/* Mobile-first density layer: keep filters readable and tables useful on a phone. */
#app {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

/* 宽屏下优先给多列数据表使用可用屏宽，避免固定内容宽度形成大块留白。 */
@media (min-width: 721px) {
  main { max-width: calc(100vw - 72px); }
  #app { max-width: none; }
  .page-heading, #app { padding-left: 24px; padding-right: 24px; }
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
}
.page-heading {
  position: sticky;
  top: 72px;
  z-index: 29;
  border: 1px solid #cfd9e7;
  box-shadow: 0 2px 8px #1a315309;
}
.section-head {
  min-height: 42px;
  margin-bottom: 8px;
  padding: 10px 13px;
  background: #fff;
  border: 1px solid #cfd9e7;
  border-radius: 9px;
}

.date-nav { padding:18px 22px; gap:12px; }
.quick-ranges { gap:9px; }
.range-button { min-width:100px; height:48px; padding:0 13px; font-size:16px; }
.date-nav > .range-button { min-width:92px; }
.month-quick-picker { position:relative; flex:0 0 auto; }
.month-quick-menu { position:absolute; top:54px; left:0; z-index:90; display:none; grid-template-columns:repeat(4, minmax(48px, 1fr)); gap:6px; width:244px; padding:8px; border:1px solid #d4ddeb; border-radius:10px; background:#fff; box-shadow:0 12px 30px #25355a26; }
.month-quick-picker.open .month-quick-menu { display:grid; }
.month-quick-menu button { height:32px; padding:0 6px; border:1px solid #dce3f0; border-radius:6px; color:#36445d; background:#fff; font:12px "Microsoft YaHei","PingFang SC",Arial,sans-serif; cursor:pointer; }
.month-quick-menu button:hover { border-color:#93a3e5; color:#4057b7; background:#f5f7ff; }
.month-quick-menu button.active { border-color:var(--brand); color:#fff; background:var(--brand); }
.month-quick-menu .month-all { grid-column:1 / -1; color:#4057b7; font-weight:600; background:#f4f6fb; }
.month-quick-menu .month-all.active { color:#fff; background:var(--brand); }
.date-input { width:160px; height:48px; font-size:14px; }
.page-filter { gap:9px; padding:11px 14px; }
.channel-multi-label { position: relative; }
.channel-multi-select { position: relative; min-width: 166px; }
.channel-multi-select summary { height:32px; display:flex; align-items:center; padding:0 28px 0 10px; border:1px solid #dce3f0; border-radius:6px; color:#36445d; background:#fff; cursor:pointer; list-style:none; white-space:nowrap; }
.channel-multi-select summary::-webkit-details-marker { display:none; }
.channel-multi-select summary:after { content:'⌄'; position:absolute; right:10px; color:#69758a; font-size:16px; }
.channel-multi-options { position:absolute; top:38px; left:0; z-index:60; display:grid; grid-template-columns:repeat(2, minmax(110px, 1fr)); gap:2px 8px; width:max-content; min-width:260px; max-width:420px; padding:9px; border:1px solid #d4ddeb; border-radius:8px; background:#fff; box-shadow:0 10px 24px #25355a24; }
.channel-multi-options label { display:flex; align-items:center; gap:6px; min-height:28px; padding:3px 5px; color:#36445d; cursor:pointer; white-space:nowrap; }
.channel-multi-options input { width:14px; height:14px; accent-color:var(--brand); }
.channel-multi-all { grid-column:1 / -1; height:28px; border:0; border-bottom:1px solid var(--line); background:#fff; color:#4057b7; text-align:left; font:inherit; cursor:pointer; }
.channel-chip-picker { display:flex; align-items:flex-start; gap:10px; flex:1 0 100%; min-width:0; padding-top:2px; }
.channel-chip-picker > span { flex:0 0 auto; height:30px; display:flex; align-items:center; color:var(--muted); font-size:12px; }
.channel-chip-list { display:flex; flex-wrap:wrap; gap:6px; min-width:0; }
.channel-chip { height:30px; padding:0 10px; border:1px solid #dce3f0; border-radius:15px; color:#53617a; background:#fff; font:12px "Microsoft YaHei","PingFang SC",Arial,sans-serif; cursor:pointer; transition:.15s; white-space:nowrap; }
.channel-chip:hover { border-color:#93a3e5; color:#4057b7; background:#f5f7ff; }
.channel-chip.active { border-color:#5c72cf; color:#fff; background:#5c72cf; box-shadow:0 2px 5px #5c72cf28; }
.channel-dropdown-field { display:flex; align-items:center; gap:7px; color:var(--muted); font-size:12px; }
.channel-dropdown { position:relative; min-width:180px; }
.channel-dropdown-trigger { width:100%; height:32px; display:flex; align-items:center; justify-content:space-between; gap:8px; padding:0 10px; border:1px solid #dce3f0; border-radius:6px; color:#36445d; background:#fff; font:12px "Microsoft YaHei","PingFang SC",Arial,sans-serif; cursor:pointer; }
.channel-dropdown-trigger:hover,.channel-dropdown.open .channel-dropdown-trigger { border-color:#8294df; box-shadow:0 0 0 2px #5c72cf15; }
.channel-dropdown-trigger span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.channel-dropdown-trigger i { color:#69758a; font-style:normal; font-size:16px; }
.channel-dropdown-menu { display:none; position:absolute; top:38px; left:0; z-index:80; width:230px; max-height:360px; overflow:auto; padding:7px; border:1px solid #d4ddeb; border-radius:10px; background:#fff; box-shadow:0 12px 30px #25355a26; }
.channel-dropdown.open .channel-dropdown-menu { display:block; }
.channel-dropdown-option { display:flex; align-items:center; gap:11px; min-height:38px; padding:7px 9px; border-radius:7px; color:#243758; font-size:14px; cursor:pointer; }
.channel-dropdown-option:hover { background:#f4f6fb; }
.channel-dropdown-option.all { margin-bottom:3px; color:#c84c22; font-weight:700; background:#f4f6fb; }
.channel-dropdown-option input { width:18px; height:18px; margin:0; accent-color:#c84c22; }
/* 保持本系统现有的紫蓝色、字号和紧凑控件节奏，仅采用下拉多选交互。 */
button.channel-dropdown-option { width:100%; justify-content:flex-start; border:0; margin:2px 0; min-height:32px; padding:6px 10px; background:#f7f9fd; color:#36445d; text-align:left; font:12px "Microsoft YaHei","PingFang SC",Arial,sans-serif; }
button.channel-dropdown-option:hover { background:#edf1ff; color:#4057b7; }
button.channel-dropdown-option.all { margin-bottom:5px; border:0; color:#4057b7; background:#edf1ff; }
button.channel-dropdown-option.selected { color:#fff; background:var(--brand); }
button.channel-dropdown-option.selected:hover { background:var(--brand-dark); color:#fff; }

.table-wrap .org-table { table-layout:fixed; }
/* 桌面端各模块都固定表头；内容列不固定，避免表头与数据行交叠。 */
@media (min-width: 721px) {
  /* 表格自身承担双向滚动。横向滚动容器若跟随页面纵向滚动，浏览器会将
     sticky 表头错误限制在数据行中；限定表格视区后，表头只固定在表格顶端。 */
  .table-wrap,
  .data-source-status {
    max-height: calc(100vh - 210px);
    overflow: auto !important;
    overscroll-behavior: contain;
    max-width: 100%;
  }
  .table-wrap .org-table .serial-cell,
  .table-wrap .org-table .org-cell {
    position: static !important;
    top: auto !important;
    left: auto !important;
  }
  .table-wrap thead th,
  .data-source-status thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 12 !important;
    background: #f8faff !important;
  }
  .table-wrap .org-table .serial-header,
  .table-wrap .org-table .org-header {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    z-index: 14 !important;
    background: #f8faff !important;
  }
  /* 渠道小类同样使用该规则，横向滚动不影响纵向固定。 */
  .channel-small-wrap { overflow: auto !important; }
  .channel-small-wrap thead th,
  .channel-small-wrap .serial-header,
  .channel-small-wrap .org-header {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    z-index: 14 !important;
    background: #f8faff !important;
  }
  .channel-small-wrap .serial-cell,
  .channel-small-wrap .org-cell,
  .channel-small-wrap td {
    position: static !important;
    top: auto !important;
    left: auto !important;
  }
}
.table-wrap,
.data-source-status {
  border: 1px solid #cfd9e7;
  box-shadow: inset 0 0 0 1px #e8edf5, 0 3px 12px #1a31530a;
}

/* Keep the column labels visible while reading long, grouped tables. */
.table-wrap thead th,
.data-source-status thead th {
  position: sticky;
  top: 173px;
  z-index: 12;
  background: #f8faff;
  border-top: 1px solid #cfd9e7;
  border-bottom: 1px solid #cfd9e7;
}
.table-wrap thead th:first-child,
.data-source-status thead th:first-child { border-left: 1px solid #cfd9e7; }
.table-wrap thead th:last-child,
.data-source-status thead th:last-child { border-right: 1px solid #cfd9e7; }

.table-wrap .org-table .serial-header,
.table-wrap .org-table .serial-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 48px;
  min-width: 48px;
  text-align: center;
  color: #64748b;
  background: inherit;
  box-shadow: 1px 0 0 var(--line);
}
.table-wrap .org-table .org-header,
.table-wrap .org-table .org-cell {
  position: sticky;
  left: 48px;
  z-index: 3;
  width: 116px;
  min-width: 116px;
  background: inherit;
  box-shadow: 1px 0 0 var(--line);
}
.table-wrap .org-table .year-header,
.table-wrap .org-table .year-cell {
  width: 86px;
  min-width: 86px;
}
.table-wrap .org-table .serial-header,
.table-wrap .org-table .org-header {
  top: 173px;
  z-index: 14;
  background: #f8faff;
}
.table-wrap .org-table .serial-header,
.table-wrap .org-table .org-header,
.table-wrap .org-table .serial-cell,
.table-wrap .org-table .org-cell { border: 1px solid #dfe6f0; }
.table-wrap .org-table td:first-child:not(.serial-cell):not(.org-cell) {
  position: static;
  min-width: 0;
  box-shadow: none;
  background: inherit;
}

@media (max-width: 720px) {
  body { font-size: 13px; }

  .app-header {
    position: sticky;
    top: 0;
    min-height: 58px;
    height: auto;
    padding: 7px 12px 0;
    gap: 4px;
  }

  .brand { gap: 8px; font-size: 16px; }
  .brand-mark { width: 27px; height: 27px; border-radius:7px; }
  .header-actions { margin-left: auto; gap: 0; }
  .workspace-state { display: none; }
  .user-avatar { width: 29px; height: 29px; font-size: 12px; }

  .top-nav {
    order: 3;
    width: calc(100% + 24px);
    margin-left: -12px;
    padding: 0 10px;
    height: 39px;
    gap: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .top-nav::-webkit-scrollbar { display: none; }
  .top-nav-item, .nav-menu { height: 39px; flex: 0 0 auto; }
  .top-nav-item { padding: 0 10px; font-size: 13px; }
  .top-nav-item.active:after { left: 10px; right: 10px; height: 2px; }
  /* 下拉菜单不能留在横向滚动容器内，否则会被 overflow 裁掉。 */
  .nav-menu.open .nav-dropdown {
    position: fixed;
    top: 97px;
    left: 10px;
    z-index: 80;
    min-width: 132px;
  }

  main { min-height: calc(100vh - 97px); }
  /* 手机端不固定页面标题：手机浏览器地址栏伸缩时，固定标题会压住筛选和表格。 */
  .page-heading {
    position: static;
    top: auto;
    min-height: 76px;
    padding: 13px 14px;
    align-items: center;
    top: 97px;
  }
  .page-heading p { margin-bottom: 4px; font-size: 11px; }
  .page-heading h1 { font-size: 20px; letter-spacing: -.2px; }
  .header-button { display: none; }
  #app { padding: 12px 10px 26px; }

  .date-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px;
    border-radius: 10px;
  }
  .quick-ranges {
    order: 0;
    display: flex;
    width: 100%;
    gap: 7px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .quick-ranges::-webkit-scrollbar { display: none; }
  /* 基础样式把按钮设为整行宽度，会将其余快捷日期挤出视区。 */
  .quick-ranges .range-button {
    width: auto;
    flex: 0 0 auto;
  }
  .range-button {
    height: 38px;
    min-width: 76px;
    padding: 0 10px;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    flex: 0 0 auto;
  }
  .date-nav > .range-button { width:auto; min-width:62px; flex:0 0 auto; }
  .custom-date-label { display: none; }
  .date-input {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    height: 38px;
    padding: 0 7px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
  }
  .month-quick-picker { order:1; flex:0 0 auto; }
  .month-quick-menu { top:44px; width:min(260px, calc(100vw - 32px)); }
  .date-nav > [data-start-date], .date-nav > .to-label, .date-nav > [data-end-date] { order: 2; }
  .to-label { margin: 0; font-size: 12px; }

  .page-filter {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px 10px;
    padding: 10px;
    margin-top: 10px;
    border-radius: 10px;
  }
  .page-filter label {
    display: grid;
    grid-template-columns: 43px minmax(0, 1fr);
    gap: 4px;
    min-width: 0;
    align-items: center;
    font-size: 11px;
  }
  .page-filter select {
    width: 100%;
    min-width: 0;
    height: 34px;
    padding: 0 5px;
    font-size: 12px;
  }
  .channel-multi-select { min-width: 0; width:100%; }
  .channel-multi-select summary { width:100%; }
  .channel-multi-options { grid-template-columns:1fr; min-width:190px; max-width:calc(100vw - 36px); }
  .channel-chip-picker { grid-column:1 / -1; gap:7px; align-items:flex-start; }
  .channel-chip-picker > span { height:28px; font-size:11px; }
  .channel-chip-list { gap:5px; }
  .channel-chip { height:28px; padding:0 9px; font-size:11px; }
  .channel-dropdown-field { grid-column:1 / -1; font-size:11px; }
  .channel-dropdown { flex:1; min-width:0; }
  .channel-dropdown-menu { width:100%; max-height:300px; }
  button.channel-dropdown-option { min-height:32px; font-size:12px; }
  .page-filter .secondary {
    grid-column: 1 / -1;
    justify-self: end;
    height: 30px;
    padding: 0 13px;
  }

  .section-head { min-height: 34px; margin: 9px 0 6px; padding: 7px 9px; align-items: center; gap: 8px; }
  .section-head h2 { font-size: 15px; white-space: nowrap; }
  .section-head span { font-size: 10px; line-height: 1.4; text-align: right; }

  .panel { border-radius: 10px; }
  .table-wrap {
    /* Android 对仅 overflow-x 的容器计算 sticky 偏移有问题；
       让表格容器同时承担双向滚动，表头始终固定在该容器顶部。 */
    max-height: min(68svh, 620px);
    overflow: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 2px 9px #1a315308;
  }
  /* 在页面导航下固定表头；固定范围只属于表格本身，不会再与页面标题交叠。 */
  .table-wrap thead th,
  .data-source-status thead th {
    position: sticky;
    top: 0;
    z-index: 16;
    background: #f8faff;
  }
  .table-wrap .org-table .serial-header,
  .table-wrap .org-table .org-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f8faff;
  }
  /* 序号、机构随横向滑动时固定在左侧，读取长表时始终可识别当前行。 */
  .table-wrap .org-table .serial-cell,
  .table-wrap .org-table .org-cell {
    position: sticky;
    top: auto;
    z-index: 8;
    background: #fff;
    box-shadow: 1px 0 0 var(--line);
  }
  /* 不再使用 fixed 布局平均撑满整张表；每一列只占标题或数据需要的宽度。 */
  .table-wrap .org-table,
  .table-wrap table,
  .panel > table {
    table-layout: auto;
    width: max-content;
    min-width: 0;
    margin: 0;
  }
  .table-wrap th, .table-wrap td, .panel > table th, .panel > table td {
    width: auto;
    min-width: 0;
    padding: 8px 5px;
    font-size: 12px;
    line-height: 1.25;
    white-space: nowrap;
  }
  .table-wrap th { font-size: 11px; }
  .table-wrap .org-table .serial-header, .table-wrap .org-table .serial-cell { width:42px; min-width:42px; left:0; }
  .table-wrap .org-table .org-header, .table-wrap .org-table .org-cell { width:82px; min-width:82px; max-width:82px; left:42px; }
  .table-wrap .org-table .year-header, .table-wrap .org-table .year-cell { width:62px; min-width:62px; }
  .table-wrap th:first-child, .table-wrap td:first-child { min-width:0; max-width:none; }
  .table-wrap td:first-child { font-size:12px; }
  .table-wrap td:nth-child(2) { min-width: 0; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
  .metric { padding: 13px; }
  .metric strong { font-size: 20px; }
  .grid-two, .file-grid { grid-template-columns: 1fr; gap: 10px; }
  .panel:not(.table-wrap) { padding: 13px; }
  .toast { right: 12px; bottom: 12px; max-width: calc(100vw - 24px); }
}

@media (max-width: 390px) {
  .page-filter { grid-template-columns: 1fr; }
  .page-filter label { grid-template-columns: 48px minmax(0, 1fr); }
  .date-nav > .range-button { min-width: 54px; padding: 0 7px; }
  .table-wrap .org-table, .table-wrap table, .panel > table { min-width: 0; }
  .table-wrap th, .table-wrap td, .panel > table th, .panel > table td { min-width: 0; padding: 8px 4px; }
}

/* Data Center upload cards are shared by desktop and mobile. */
.data-upload-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 3px 12px #1a31530a;
}
.data-upload-title { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:16px; }
.data-upload-title h2 { margin:0; font-size:16px; }
.data-upload-title p, .data-upload-help { margin:6px 0 0; color:var(--muted); font-size:12px; line-height:1.6; }
.data-upload-title > span { color:#61708a; font-size:12px; white-space:nowrap; }
.source-upload-grid { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:12px; }
.source-upload-card { border:1px solid var(--line); border-radius:9px; padding:15px; }
.source-upload-head { display:flex; justify-content:space-between; gap:9px; align-items:flex-start; }
.source-upload-head h3 { margin:0; font-size:14px; font-weight:600; }
.source-upload-head p, .source-current, .source-selected { margin:5px 0 0; font-size:12px; color:var(--muted); line-height:1.45; }
.source-current { padding-top:8px; border-top:1px dashed #e6ebf2; margin-top:10px; min-height:43px; }
.source-picker { display:inline-flex; align-items:center; justify-content:center; height:34px; padding:0 11px; margin-top:12px; border:1px solid #d4ddef; border-radius:7px; color:#4c62bc; background:#f9faff; font-size:12px; cursor:pointer; }
.source-picker input { position:absolute; width:1px; height:1px; overflow:hidden; opacity:0; }
.source-selected { min-height:34px; overflow-wrap:anywhere; }
.source-import { height:34px; margin-top:9px; padding:0 12px; font-size:12px; }
.source-import:disabled { cursor:wait; opacity:.7; }
.data-upload-help { margin-top:14px; padding-top:12px; border-top:1px solid var(--line); }
.data-source-status { margin-top:0; }

.account-head { display:flex; align-items:flex-start; justify-content:space-between; gap:14px; margin-bottom:13px; }
.account-head h3 { margin:0; font-size:16px; }
.account-head p, .account-security-note { margin:6px 0 0; color:var(--muted); font-size:12px; line-height:1.55; }
.account-editor { padding:18px; margin-bottom:13px; }
.account-editor .split-title h3 { font-size:15px; }
.account-form { display:grid; grid-template-columns:repeat(3, minmax(0, 1fr)); gap:12px; margin-top:16px; }
.account-form label { display:grid; gap:6px; color:var(--muted); font-size:12px; }
.account-form input, .account-form select { width:100%; height:35px; border:1px solid #dce3f0; border-radius:6px; padding:0 10px; color:#36445d; background:#fff; font:inherit; }
.account-form-action { grid-column:1 / -1; display:flex; align-items:center; justify-content:flex-start; gap:10px; padding-top:14px; margin-top:2px; border-top:1px solid var(--line); }
.account-form-action .cta { min-width:128px; height:38px; }
.account-security-note { padding-top:12px; border-top:1px solid var(--line); }
.account-table .account-empty { height:84px; color:var(--muted); text-align:center; }

@media (max-width:720px) {
  .data-upload-panel { padding:13px; border-radius:10px; }
  .data-upload-title { gap:9px; margin-bottom:11px; }
  .data-upload-title h2 { font-size:15px; }
  .data-upload-title p, .data-upload-help { font-size:11px; }
  .data-upload-title > span { font-size:11px; }
  .source-upload-grid { grid-template-columns:1fr; gap:9px; }
  .source-upload-card { padding:12px; }
  .source-current { min-height:0; }
  .source-selected { min-height:0; }
  .source-import { width:100%; }
  .account-head { margin-bottom:10px; }
  .account-head h3 { font-size:15px; }
  .account-head p, .account-security-note { font-size:11px; }
  .account-editor { padding:13px; }
  .account-form { grid-template-columns:1fr; gap:9px; margin-top:12px; }
  .account-form input, .account-form select { height:34px; }
.account-form-action .cta { width:100%; }
}

/* 全屏双列下，渠道小类必须服从面板宽度；覆盖旧框架的 1390px 最小宽度和通用横向滚动。 */
@media (min-width:1201px) {
  #data-fullscreen-overlay .data-fullscreen-split .data-fullscreen-table {
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
  #data-fullscreen-overlay .data-fullscreen-split .channel-small-table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
  }
  #data-fullscreen-overlay .data-fullscreen-split .channel-small-table .channel-serial-col { width:36px !important; }
  #data-fullscreen-overlay .data-fullscreen-split .channel-small-table .channel-org-col { width:92px !important; }
  #data-fullscreen-overlay .data-fullscreen-split .channel-small-table .channel-year-col { width:54px !important; }
  #data-fullscreen-overlay .data-fullscreen-split .channel-small-table .channel-data-col { width:42px !important; }
}
