/* 企业中台统一页头与面包屑（UI-10 / UI-11 / UI-41 / UI-42）。所有后台页面在页面 CSS 之后加载。 */

/* ---- 页头：品牌 / 侧栏开关 / 一级菜单 / 搜索 / 账号区，固定 56px、不换行 ---- */
.has-app-shell .app-header {
  flex-wrap: nowrap;
  height: 56px;
  gap: 10px;
}
.has-app-shell .app-header .app-nav {
  flex: 0 1 auto;
  overflow: visible;
}
.has-app-shell .app-header .enterprise-global-search {
  position: relative;
  flex: 1 1 240px;
  max-width: 380px;
  min-width: 160px;
  margin-left: auto;
  order: 0;
}
.has-app-shell .app-header .enterprise-search-row { display: flex; min-width: 0; }
.has-app-shell .app-header .enterprise-search-row input {
  width: 100%;
  height: 36px;
  margin: 0;
  padding: 0 28px 0 11px;
  border: 1px solid var(--line, #dbe3ea);
  border-radius: 9px;
  background: var(--panel, #fff);
  color: var(--ink, #0f172a);
  box-shadow: none;
  font-size: 13px;
}
.has-app-shell .app-header .enterprise-search-kbd {
  position: absolute;
  right: 9px;
  top: 8px;
  color: var(--muted, #64748b);
  font: 11px/20px ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
}
.has-app-shell .app-header .enterprise-search-results {
  position: absolute;
  z-index: 80;
  left: 0;
  right: 0;
  min-width: 320px;
  top: calc(100% + 7px);
  max-height: min(64vh, 520px);
  overflow: auto;
  border: 1px solid var(--line, #dbe3ea);
  border-radius: 12px;
  background: var(--panel, #fff);
  box-shadow: 0 18px 45px rgba(15, 23, 42, .18);
  padding: 6px;
}
.has-app-shell .app-header .enterprise-search-results.hidden { display: none; }
.has-app-shell .enterprise-search-status { padding: 9px 10px; color: var(--muted, #64748b); font-size: 12px; }
.has-app-shell .enterprise-search-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}
.has-app-shell .enterprise-search-item:hover,
.has-app-shell .enterprise-search-item[aria-selected="true"] { background: var(--brand-soft, rgba(15, 118, 110, .09)); }
.has-app-shell .enterprise-search-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.has-app-shell .enterprise-search-meta { color: var(--muted, #64748b); font-size: 12px; }
.has-app-shell .enterprise-search-type { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.has-app-shell .enterprise-sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.has-app-shell .app-header .userchip { flex: 0 0 auto; margin-left: 0; }
.has-app-shell .app-header .enterprise-global-search + .userchip { margin-left: 0; }
.has-app-shell .app-header .app-nav + .userchip { margin-left: auto; }

/* ---- 面包屑：内容区第一行，任何宽度都显示 ---- */
.has-app-shell .main > .crumb.app-crumb {
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex: none;
  min-width: 0;
  min-height: 0;
  margin: 0 0 8px;
  padding: 0;
  border-left: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  white-space: normal;
  overflow: visible;
}
.has-app-shell .main > .crumb.app-crumb:empty { display: none !important; }
.has-app-shell .main > .crumb.app-crumb .crumb-current { color: var(--ink-2, var(--ink)); }

/* ---- 1366 以下：收起账号名文字，只留按钮 ---- */
@media (max-width: 1366px) {
  .has-app-shell .app-header .userchip > #who { display: none; }
}

/* ---- 1280 以下：一级菜单收紧间距；搜索框缩成图标，聚焦时展开 ---- */
@media (max-width: 1280px) {
  .has-app-shell .app-header .app-nav-item { padding: 7px 9px; }
  .has-app-shell .app-header .enterprise-global-search {
    flex: 0 0 38px;
    min-width: 38px;
    max-width: 38px;
  }
  .has-app-shell .app-header .enterprise-search-row input {
    padding: 0 0 0 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 10px center;
    cursor: pointer;
  }
  .has-app-shell .app-header .enterprise-search-row input::placeholder { color: transparent; }
  .has-app-shell .app-header .enterprise-search-kbd { display: none; }
  .has-app-shell .app-header .enterprise-global-search:focus-within {
    position: absolute;
    right: 16px;
    top: 10px;
    z-index: 60;
    max-width: none;
    width: min(420px, calc(100vw - 32px));
  }
  .has-app-shell .app-header .enterprise-global-search:focus-within .enterprise-search-row input { cursor: text; }
  .has-app-shell .app-header .enterprise-global-search:focus-within .enterprise-search-row input::placeholder { color: var(--muted, #64748b); }
}

/* ---- 1100 以下：品牌只留图标 ---- */
@media (max-width: 1100px) {
  .has-app-shell .app-header .brand > div { display: none; }
}

/* ---- UI-21 筛选条：控件按内容定宽、同一行排开（全局 input/select 默认 100% 宽，在筛选条里会一个占一行） ---- */
.has-app-shell :is(.desk-filter-bar, .sales-toolbar, .toolbar, .an-filter, .crm-filter, .log-filter, .request-filter, .filter-row, .ov-filter)
  > :is(select, input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"])) {
  width: auto;
  flex: 0 1 auto;
  min-width: 140px;
  max-width: 220px;
}
.has-app-shell :is(.desk-filter-bar, .sales-toolbar, .toolbar, .an-filter, .crm-filter, .log-filter, .request-filter, .filter-row, .ov-filter)
  > :is(input[type="search"], input.search, input:not([type])) {
  flex: 1 1 220px;
  max-width: 320px;
}
.has-app-shell :is(.desk-filter-bar, .sales-toolbar, .toolbar, .an-filter, .crm-filter, .log-filter, .request-filter, .filter-row, .ov-filter)
  > :is(input[type="date"], input[type="month"], input[type="datetime-local"]) {
  flex: 0 0 auto;
  min-width: 150px;
}
/* 服务申请的筛选原来是 3 列网格，统一成一行内联 */
.has-app-shell .request-filter {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.has-app-shell .request-filter > .btn { width: auto; flex: 0 0 auto; }

/* ---- UI-20 卡片头与页标题同名时不重复显示（由 app-shell.js 标记） ---- */
.has-app-shell [data-app-dup-title] { display: none !important; }

/* ---- UI-23 行内「更多」菜单：操作列最多两个文字按钮，其余收进这里 ---- */
.has-app-shell .row-more { position: relative; display: inline-block; }
.has-app-shell .row-more > summary { list-style: none; cursor: pointer; }
.has-app-shell .row-more > summary::-webkit-details-marker { display: none; }
.has-app-shell .row-more > summary::after { content: ' ▾'; font-size: 10px; opacity: .7; }
.has-app-shell .row-more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  display: grid;
  min-width: 132px;
  padding: 4px;
  border: 1px solid var(--line, #dbe3ea);
  border-radius: 10px;
  background: var(--panel, #fff);
  box-shadow: 0 12px 30px rgba(15, 23, 42, .16);
}
.has-app-shell .row-more-menu > button,
.has-app-shell .row-more-menu > a {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink, #0f172a);
  font: inherit;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}
.has-app-shell .row-more-menu > :is(button, a):hover { background: var(--hover, rgba(15, 23, 42, .05)); }
.has-app-shell .row-more-menu > .is-danger { color: var(--danger, #b91c1c); }
.has-app-shell .row-ops { display: inline-flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.has-app-shell .btn.sm { padding: 4px 10px; font-size: 12px; line-height: 1.5; }

/* ---- UI-29 看板：所有阶段排成一行，超出横向滚动，不再折到第二行 ---- */
.has-app-shell .pipe-board {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(210px, 1fr);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 12px;
}
.has-app-shell .pipe-board > .pipe-col { scroll-snap-align: start; }

/* ---- UI-28 主从布局：列表统一 300px，详情撑满剩余宽高 ---- */
.has-app-shell #view-requests .request-grid,
.has-app-shell #view-callback .callback-desk,
.has-app-shell #view-tickets .crm-desk {
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: calc(100vh - 230px);
}
.has-app-shell #view-requests .request-grid > * { min-height: 0; }
@media (max-width: 1024px) {
  .has-app-shell #view-requests .request-grid,
  .has-app-shell #view-callback .callback-desk,
  .has-app-shell #view-tickets .crm-desk { grid-template-columns: 1fr; min-height: 0; }
}

/* ---- UI-26 空状态：统一居中、灰字、高度随内容；空表格（只有表头）给出提示 ---- */
.has-app-shell .main .empty { text-align: center; color: var(--muted); }
.has-app-shell .content > .empty,
.has-app-shell .main .panel > .empty { min-height: 160px; }
.has-app-shell td.app-empty-cell {
  padding: 28px 14px !important;
  color: var(--muted);
  text-align: center !important;
  font-size: 13px;
}
.has-app-shell .main .table-wrap:has(> table > tbody:empty)::after {
  content: '暂无数据';
  display: block;
  padding: 24px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}
.has-app-shell .main :is(.panel, .card) > p:only-child:not([class]) { padding: 18px 16px; margin: 0; color: var(--muted); text-align: center; }

/* ---- UI-27 页内 Tab：统一为标题下方的下划线式，一行占满 ---- */
.has-app-shell .page-head > .page-tabs {
  flex: 1 0 100%;
  order: 5;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-top: 4px;
}
.has-app-shell .page-tab {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  margin-bottom: -1px;
  padding: 8px 12px 10px;
  color: var(--muted);
  font-size: 13px;
}
.has-app-shell .page-tab:hover { color: var(--ink); border-color: transparent; }
.has-app-shell .page-tab.is-on,
.has-app-shell .page-tab[aria-current="page"] {
  background: transparent;
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: var(--fw-sb, 600);
}

/* ---- UI-30 表单控件：文件选择按钮与普通按钮同款；设置类表单限制最大宽度 ---- */
.has-app-shell input[type="file"] {
  width: auto;
  max-width: 100%;
  padding: 4px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}
.has-app-shell input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.has-app-shell input[type="file"]::file-selector-button:hover { border-color: var(--brand); color: var(--brand); }
.has-app-shell :is(#view-settings-phrases, #view-settings-pool, #view-settings-fields) :is(.panel, .card) { max-width: 880px; }

/* ---- UI-42 1024 档：侧栏收窄到 200px，内容区不少于 ~800px ---- */
@media (min-width: 861px) and (max-width: 1180px) {
  .has-app-shell .app:not(.side-collapsed):not(.is-overview) { grid-template-columns: 200px minmax(0, 1fr); }
  .has-app-shell .app:has(.enterprise-app-nav):not(.side-collapsed) { grid-template-columns: 200px minmax(0, 1fr); }
}

/* ---- UI-43 手机档：页头两行（品牌+账号 / 一级菜单横向滑动），总高约 100px ---- */
@media (max-width: 860px) {
  .has-app-shell .app { grid-template-rows: auto minmax(0, 1fr); }
  .has-app-shell .app-header {
    flex-wrap: wrap;
    height: auto;
    min-height: 0;
    padding: 8px 12px 0;
    row-gap: 4px;
    column-gap: 8px;
  }
  .has-app-shell .app-header .brand > div { display: none; }
  .has-app-shell .app-header .enterprise-global-search { margin-left: auto; }
  .has-app-shell .app-header .userchip { gap: 6px; }
  .has-app-shell .app-header .userchip > :is(#who, .site-picker > span, .sync-light b) { display: none; }
  .has-app-shell .app-header .app-nav {
    order: 10;
    flex: 1 0 100%;
    display: flex;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    margin: 0 -12px;
    padding: 2px 12px 6px;
    width: auto !important;
  }
  .has-app-shell .app-header .app-nav::-webkit-scrollbar { display: none; }
  /* W-45：隐藏滚动条后，用渐隐边缘提示还有菜单可横向滚动 */
  .has-app-shell .app-header .app-nav[data-scroll-more="end"] {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
  }
  .has-app-shell .app-header .app-nav[data-scroll-more="start"] {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent);
  }
  .has-app-shell .app-header .app-nav[data-scroll-more="both"] {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent);
  }
  .has-app-shell .app-header .app-nav-item { flex: 0 0 auto; padding: 6px 10px; }
  .has-app-shell .app-header .enterprise-global-search:focus-within { top: 8px; right: 12px; width: calc(100vw - 24px); }
  .has-app-shell .main > .crumb.app-crumb { display: none !important; }
}

/* AL-P0-3：套餐未开通的菜单项与二级条目打锁（可点进查看，写入由服务端 402 拦截）。 */
.has-app-shell .app-nav-item[data-plan-lock],
.nav-btn[data-plan-lock] { opacity: .62; }
.has-app-shell .app-nav-item[data-plan-lock]::after,
.nav-btn[data-plan-lock]::after {
  content: "\1F512";
  font-size: 11px;
  margin-left: 6px;
  opacity: .8;
}
.is-plan-readonly { opacity: .75; }

/* UI-NAV-1：侧栏分组间距不再依赖「相邻兄弟」——被隐藏的页面自带分组排在前面时，第一个可见分组会多出 14px，
   不同页面侧栏起点不一致。改成每组底部留白，隐藏分组不再影响可见分组的位置。 */
.side > .nav-group + .nav-group { margin-top: 0; }
.side > .nav-group { margin-bottom: 14px; }
.side > .nav-group.nav-dock { margin-top: auto; }
/* 条目全部无权或隐藏的分组，连标题一起隐藏（app-nav.js 标记）。 */
.side > .nav-group[data-app-empty] { display: none !important; }

/* ---- M-01 / M-04：页面自带但菜单清单里没有的侧栏条目隐藏；三级 Tab（标题下方一行，地址 #视图） ---- */
.side .nav-btn[data-app-extra="1"] { display: none !important; }
.has-app-shell .page-head > .app-subtabs { display: flex; flex-wrap: wrap; }
.has-app-shell .main > .app-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin: 0 0 14px;
}
.has-app-shell .app-subtabs .page-tab { text-decoration: none; }
/* M-20：平台控制台内嵌企业页面（套餐与计费各页、支付配置）时去掉企业壳 */
html[data-embed] .app-header,
html[data-embed] #sideNav,
html[data-embed] .side,
html[data-embed] .main > .crumb,
html[data-embed] .app-crumb,
html[data-embed] #crumb,
html[data-embed] .main > .page-head .page-head-text,
html[data-embed] #planBanner,
html[data-embed] .onboard-bar { display: none !important; }
html[data-embed] .app { display: block !important; grid-template-columns: 1fr !important; }
html[data-embed] .main { margin: 0 !important; max-width: none !important; }
/* 外层 iframe 按内容撑高：去掉 100vh 下限，否则框只增不减；弹窗按外层可见区域居中（--embed-view-* 由 system/app_core.js fitBillingEmbed 写入） */
html[data-embed] body,
html[data-embed] .app { min-height: 0 !important; }
html[data-embed] .main { padding-top: 6px !important; }
html[data-embed] .main > .page-head { margin-bottom: 0; }
html[data-embed] .aics-modal-root { bottom: auto; top: var(--embed-view-top, 0px); height: var(--embed-view-h, 100%); }
.embed-panel { padding: 0 !important; overflow: hidden; }
.embed-frame { display: block; width: 100%; min-height: calc(100vh - 190px); border: 0; background: var(--panel, transparent); }
.embed-panel .embed-fallback { margin: 0; padding: 8px 14px; border-top: 1px solid var(--line); }
.embed-panel.embed-blocked .embed-frame { display: none; }
.embed-panel.embed-blocked .embed-fallback { padding: 48px 16px; border-top: 0; text-align: center; font-size: 14px; }
