:root {
  color-scheme: light;
  --bg: #eef1f3;
  --panel: #ffffff;
  --panel-soft: #f7fafa;
  --text: #14201f;
  --muted: #6b787c;
  --border: #e3e9ea;
  --border-strong: #ccd6d8;
  --teal: #0f766e;
  --teal-strong: #0b5f59;
  --teal-weak: #e2f1ef;
  --teal-weaker: #f1f8f7;
  --pos: #0f8a5f;
  --pos-weak: #e4f5ec;
  --warn: #b7791f;
  --warn-weak: #fbf1dd;
  --red: #c0392b;
  --red-weak: #fbeae8;
  --ink: #0e2122;
  --shadow: 0 1px 2px rgba(14, 33, 33, 0.05), 0 2px 6px rgba(14, 33, 33, 0.04);
  --r: 10px;
  --r-sm: 7px;
  --r-pill: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

/* 金额/数字统一等宽对齐，BI 风必备 */
td,
.metric strong,
.detail-card strong,
.bar-meta span,
.analysis-field strong {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ============ 登录 ============ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(14, 33, 34, 0.74);
  backdrop-filter: blur(3px);
}

.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

.login-card h1 {
  margin: 6px 0 0;
  font-size: 22px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  width: 100%;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

/* ============ 弹窗 ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14, 33, 34, 0.55);
  backdrop-filter: blur(2px);
}

.modal-card {
  width: min(1180px, 100%);
  max-height: min(800px, calc(100vh - 48px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-size: 17px;
}

.modal-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--panel-soft);
  color: var(--text);
}

/* ============ 分析弹窗内容 ============ */
.analysis-content {
  overflow: auto;
  padding: 18px 20px 22px;
  display: grid;
  gap: 16px;
}

.analysis-group {
  display: grid;
  gap: 10px;
}

.analysis-group h3 {
  margin: 0;
  font-size: 14px;
  color: var(--teal-strong);
  padding-left: 9px;
  border-left: 3px solid var(--teal);
}

.analysis-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.analysis-field {
  min-height: 74px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--panel-soft);
}

.analysis-field span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.analysis-field strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
  line-height: 1.35;
  word-break: break-word;
}

.analysis-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.analysis-table {
  min-width: 2800px;
}

.analysis-table th,
.analysis-table td {
  min-width: 116px;
  white-space: normal;
}

.analysis-table th:nth-child(1),
.analysis-table td:nth-child(1) {
  min-width: 72px;
}

.analysis-table th:nth-child(2),
.analysis-table td:nth-child(2) {
  min-width: 280px;
}

/* ============ 整体布局 ============ */
.app-shell {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--ink);
  color: #f4faf9;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand.compact {
  color: var(--text);
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: #f1c36d;
  color: var(--ink);
  font-weight: 800;
  font-size: 18px;
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand span,
.side-note span {
  display: block;
  margin-top: 2px;
  color: #9fb6b8;
  font-size: 11px;
  letter-spacing: 0.04em;
}

nav {
  display: grid;
  gap: 3px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
  color: #c7d6d7;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.nav-item.active {
  background: rgba(15, 118, 110, 0.32);
  color: #ffffff;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: #6fd0c4;
}

.side-note {
  margin-top: auto;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-sm);
}

.side-note strong {
  font-size: 14px;
}

.side-note .text-button {
  margin-top: 10px;
  color: #c7d6d7;
}

.main {
  padding: 20px 22px;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.search-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ============ 表单与按钮 ============ */
input,
select {
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 0 11px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

#globalSearch {
  width: 240px;
}

.button {
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: filter 0.12s, background 0.12s;
}

.button.primary {
  background: var(--teal);
  color: #fff;
}

.button.primary:hover {
  background: var(--teal-strong);
}

.button.secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--teal-strong);
}

.button.secondary:hover {
  background: var(--teal-weaker);
}

.text-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--teal);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.text-button:hover {
  text-decoration: underline;
}

.text-button.danger {
  color: var(--red);
}

/* ============ 指标卡（密集、突出） ============ */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px 15px;
  box-shadow: var(--shadow);
  position: relative;
}

.metric span {
  color: var(--muted);
  font-size: 12.5px;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* 利润率指标：随风险变色 */
.metric.rate strong.rate-pos {
  color: var(--pos);
}
.metric.rate strong.rate-mid {
  color: var(--warn);
}
.metric.rate strong.rate-neg {
  color: var(--red);
}

.metric.warn strong {
  color: var(--red);
}

.metric.warn.is-zero strong {
  color: var(--pos);
}

.metric-drill {
  cursor: pointer;
}

.metric-drill:hover,
.metric-drill:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 6px 18px rgba(15, 118, 110, 0.16);
  outline: none;
}

.metric-drill em {
  position: absolute;
  right: 14px;
  bottom: 12px;
  color: var(--teal);
  font-style: normal;
  font-size: 11px;
}

/* ============ 视图与面板 ============ */
.view {
  display: none;
}

.view.active {
  display: block;
}

.grid.two {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.9fr);
  gap: 14px;
}

.grid.two + .grid.two {
  margin-top: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 15px;
  box-shadow: var(--shadow);
}

.panel + .panel,
.detail-panel,
.grid.two + .panel {
  margin-top: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  position: relative;
  padding-left: 11px;
}

.panel-head h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 3px;
  border-radius: 3px;
  background: var(--teal);
}

.panel-head span {
  color: var(--muted);
  font-size: 12.5px;
}

/* ============ 表格（BI 核心：冻结表头、紧凑、可滚动） ============ */
.table-wrap {
  overflow: auto;
  max-height: 68vh;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 8px 11px;
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  background: #eef3f3;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
}

tbody tr {
  cursor: pointer;
}

tbody tr:nth-child(even) {
  background: #fbfcfc;
}

tbody tr:hover {
  background: var(--teal-weaker);
}

tbody tr.selected {
  background: var(--teal-weak);
  box-shadow: inset 3px 0 0 var(--teal);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  min-width: 120px;
}

/* 利润率 / 偏差 风险配色（行内徽标） */
.rate-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: 12.5px;
}
.rate-pill.rate-pos {
  color: var(--pos);
  background: var(--pos-weak);
}
.rate-pill.rate-mid {
  color: var(--warn);
  background: var(--warn-weak);
}
.rate-pill.rate-neg {
  color: var(--red);
  background: var(--red-weak);
}

.warn-pill {
  display: inline-block;
  min-width: 22px;
  text-align: center;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: 12.5px;
  color: var(--red);
  background: var(--red-weak);
}
.warn-pill.is-zero {
  color: var(--pos);
  background: var(--pos-weak);
}

/* ============ 条形图 ============ */
.bars {
  display: grid;
  gap: 11px;
}

.bar-row {
  display: grid;
  gap: 5px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12.5px;
}

.bar-meta strong {
  color: var(--text);
  font-weight: 600;
}

.bar-track {
  height: 9px;
  background: #e7eeef;
  border-radius: var(--r-pill);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--teal), #1c9e92);
}

/* 文本风险配色（柱状/汇总标签复用） */
.rate-pos {
  color: var(--pos);
  font-weight: 700;
}
.rate-mid {
  color: var(--warn);
  font-weight: 700;
}
.rate-neg {
  color: var(--red);
  font-weight: 700;
}

/* 环形饼图 */
.donut-wrap {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.donut-svg {
  width: 150px;
  height: 150px;
  flex: 0 0 auto;
}

.donut-center-num {
  font-size: 9px;
  font-weight: 700;
  fill: var(--text);
}

.donut-center-label {
  font-size: 7px;
  fill: var(--muted);
}

.donut-legend {
  display: grid;
  gap: 7px;
  flex: 1 1 200px;
  min-width: 180px;
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.donut-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.donut-label {
  flex: 1 1 auto;
  color: var(--text);
}

.donut-val {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ============ 详情卡 / 异常 ============ */
.detail-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.detail-card {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px;
  background: var(--panel-soft);
}

.detail-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.detail-card strong {
  font-size: 17px;
}

.warnings {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.warning {
  border-left: 3px solid var(--red);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 8px 11px;
  background: var(--red-weak);
  color: #8a261b;
  font-size: 13px;
}

/* ============ 筛选 / 分页 ============ */
.filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 13px;
}

.filter-grid input,
.filter-grid select {
  flex: 1 1 150px;
  min-width: 120px;
  width: auto;
}

.filter-grid input[type="search"] {
  flex: 2 1 240px;
}

.filter-grid .button {
  flex: 0 0 auto;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.pager-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager-controls select {
  width: 112px;
  height: 34px;
}

.pager-controls .button {
  height: 34px;
}

.pager-controls .button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ============ 导入 ============ */
.import-panel p {
  color: var(--muted);
  margin: 8px 0 16px;
}

.import-options {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--panel-soft);
}

.import-options span {
  color: var(--muted);
  font-size: 13px;
}

.import-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.import-options input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.drop-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r);
  padding: 36px;
  background: var(--panel-soft);
  display: grid;
  gap: 8px;
  text-align: center;
  transition: border-color 0.12s, background 0.12s;
}

.drop-zone.dragging {
  border-color: var(--teal);
  background: var(--teal-weaker);
}

.drop-zone span {
  color: var(--muted);
  font-size: 13px;
}

pre {
  min-height: 80px;
  margin: 16px 0 0;
  padding: 12px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: #e7f5f4;
  overflow: auto;
  font-size: 12.5px;
}

/* ============ 价格对比 / 异常预警 ============ */
.compare-hint {
  margin: 6px 2px 12px;
  font-size: 12.5px;
}

.compare-row {
  cursor: pointer;
}

.compare-row:hover {
  background: var(--teal-weaker);
}

.dev-high {
  color: var(--red);
  font-weight: 700;
}

.dev-low {
  color: var(--teal);
  font-weight: 700;
}

/* ============ 标签 / 标签弹窗 ============ */
.tag-line {
  display: inline-block;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--teal-strong);
  background: var(--teal-weak);
  padding: 1px 8px;
  border-radius: var(--r-pill);
}

.remark-cell {
  white-space: normal;
  min-width: 160px;
  max-width: 320px;
  word-break: break-word;
}

.meta-card {
  width: min(440px, 100%);
  max-height: none;
  display: block;
  overflow: visible;
}

.meta-fields {
  display: grid;
  gap: 14px;
  padding: 16px 20px;
}

.meta-fields label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.meta-actions {
  display: flex;
  gap: 10px;
  padding: 0 20px 6px;
}

.meta-card .form-message {
  padding: 0 20px 16px;
}

/* ============ 响应式 ============ */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  nav {
    grid-template-columns: repeat(3, 1fr);
    display: grid;
  }

  .side-note {
    display: none;
  }

  .topbar,
  .top-actions {
    flex-direction: column;
    align-items: stretch;
  }

  #globalSearch {
    width: 100%;
  }

  .grid.two,
  .detail-cards,
  .analysis-fields {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: none;
  }

  .modal {
    padding: 12px;
  }
}
