/* ============================================================
   投放工作台 · 设计系统
   方向：Financial Dashboard → Dark Mode(OLED) + Data-Dense
   配色：深色底 + 红(坏/亏损) 绿(好/在线) + 信任蓝(主操作)
   ============================================================ */

/* ── 设计令牌 ────────────────────────────────────────── */
:root {
  /* 层次（越靠上越"近"） */
  --bg:          #080c14;
  --surface:     #101827;
  --surface-2:   #16203344;
  --surface-3:   #1c2740;
  --border:      #26314a;
  --border-soft: #1e2739;

  /* 文字 */
  --text:        #e6edf7;
  --text-2:      #b6c2d4;
  --text-dim:    #7d8ba3;
  --text-faint:  #5c6b85;

  /* 语义色 */
  --primary:     #3b82f6;   /* 信任蓝：主操作 */
  --primary-dim: #1d4ed8;
  --success:     #22c55e;   /* 好：在线/盈利/加热中 */
  --danger:      #ef4444;   /* 坏：亏损/掉线/告警 */
  --warning:     #f59e0b;   /* 注意：待支付/临近 */
  --neutral:     #64748b;   /* 终态：已结束/已取消 */

  /* 间距刻度 */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px;

  /* 字号 */
  --t-xs: 11px; --t-sm: 12px; --t-base: 13px;
  --t-md: 14px; --t-lg: 16px; --t-xl: 20px; --t-2xl: 26px; --t-3xl: 34px;

  /* 圆角 / 阴影 */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.55);

  --sidebar-w: 216px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: var(--t-base)/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC",
        "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* 数字统一等宽，表格对齐不乱 */
.num, td.num, th.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ── 焦点可见（无障碍）──────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline-offset: 1px; }

/* ── 布局 ────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 40;
}
.brand {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s2);
  padding: 0 var(--s4); border-bottom: 1px solid var(--border-soft);
  font-size: var(--t-md); font-weight: 700; letter-spacing: .3px;
}
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }

.nav { flex: 1; overflow-y: auto; padding: var(--s3) 0; }
.nav-group { padding: var(--s3) var(--s4) var(--s1); }
.nav-group-label {
  font-size: var(--t-xs); color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .8px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s4);
  color: var(--text-dim); cursor: pointer;
  font-size: var(--t-md); border-left: 2px solid transparent;
  transition: background .12s, color .12s;
  user-select: none;
}
.nav-item:hover { background: #ffffff08; color: var(--text); }
.nav-item.active {
  color: var(--text); background: #3b82f61a;
  border-left-color: var(--primary); font-weight: 600;
}
.nav-item .ico { width: 16px; text-align: center; opacity: .85; flex: none; }
.nav-item .badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: var(--t-xs); padding: 1px 6px; border-radius: 9px; font-weight: 700;
}

.main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-width: 0;
}

/* ── 顶栏 ────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s5);
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.status-group { display: flex; align-items: center; gap: var(--s4); }
.status {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--t-sm); color: var(--text-dim); white-space: nowrap;
}
.status .led { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.led.on   { background: var(--success); box-shadow: 0 0 0 3px #22c55e33; }
.led.off  { background: var(--danger);  box-shadow: 0 0 0 3px #ef444433; }
.status b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.freshness { font-size: var(--t-sm); color: var(--text-faint); white-space: nowrap; }
.spacer { flex: 1; }

.content { padding: var(--s5); flex: 1; overflow-x: hidden; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; } }

.page-head { margin-bottom: var(--s5); }
.page-head h2 { font-size: var(--t-xl); font-weight: 700; }
.page-head p { color: var(--text-dim); font-size: var(--t-sm); margin-top: 2px; }

/* ── 卡片 / 网格 ─────────────────────────────────────── */
.grid { display: grid; gap: var(--s4); }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s4);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--s3); gap: var(--s3);
}
.card-head h3 { font-size: var(--t-md); font-weight: 600; }

/* KPI 卡：大数字 + 单位 + 同比说明 */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s4);
}
.kpi .label { font-size: var(--t-sm); color: var(--text-dim); }
.kpi .value {
  font-size: var(--t-2xl); font-weight: 700; margin-top: var(--s2);
  font-variant-numeric: tabular-nums; line-height: 1.15;
}
.kpi .unit { font-size: var(--t-sm); color: var(--text-dim); font-weight: 500; margin-left: 3px; }
.kpi .sub { font-size: var(--t-xs); color: var(--text-faint); margin-top: var(--s1); }
.kpi.good .value { color: var(--success); }
.kpi.bad  .value { color: var(--danger); }
.kpi.warn .value { color: var(--warning); }

/* ── 表格（Data-Dense）────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--s4)); padding: 0 var(--s4); }
table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
thead th {
  position: sticky; top: 0;
  background: var(--surface);
  color: var(--text-dim); font-weight: 600; font-size: var(--t-xs);
  text-align: left; padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; text-transform: uppercase; letter-spacing: .4px;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th .arrow { opacity: .4; margin-left: 3px; }
thead th.sorted .arrow { opacity: 1; color: var(--primary); }
tbody td {
  padding: var(--s3); border-bottom: 1px solid var(--border-soft);
  white-space: nowrap; color: var(--text-2);
}
tbody tr:hover td { background: #ffffff06; }
tbody td.num { text-align: right; }
thead th.num { text-align: right; }
td.name { color: var(--text); font-weight: 500; }
td .mono { font-size: var(--t-xs); color: var(--text-faint); display: block; }

/* 状态标签 */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px;
  font-size: var(--t-xs); font-weight: 600; white-space: nowrap;
}
.tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.tag-run    { color: var(--success); background: #22c55e1a; }
.tag-wait   { color: var(--warning); background: #f59e0b1a; }
.tag-review { color: var(--primary); background: #3b82f61a; }
.tag-pause  { color: var(--danger);  background: #ef44441a; }
.tag-end    { color: var(--neutral); background: #64748b1a; }
.tag-live   { color: var(--success); background: #22c55e1a; }
.tag-down   { color: var(--danger);  background: #ef44441a; }
.tag-warn   { color: var(--warning); background: #f59e0b1a; }

/* ROI 色阶：亏=红，平=黄，赚=绿 */
.roi-bad  { color: var(--danger);  font-weight: 700; }
.roi-flat { color: var(--warning); font-weight: 700; }
.roi-good { color: var(--success); font-weight: 700; }

/* ── 按钮 ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface-3);
  color: var(--text); font-size: var(--t-sm); font-weight: 500; cursor: pointer;
  transition: filter .12s, background .12s;
}
.btn:hover { filter: brightness(1.18); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; }
.btn-sm      { padding: 4px 10px; font-size: var(--t-xs); }
.btn-money   { background: var(--danger); border-color: var(--danger); color: #fff; } /* 花钱=危险级 */

/* ── 表单 ─────────────────────────────────────────────── */
.field { margin-bottom: var(--s4); }
.field label {
  display: block; font-size: var(--t-sm); color: var(--text-dim);
  margin-bottom: var(--s2); font-weight: 500;
}
.input, select.input, textarea.input {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 9px 11px; font-size: var(--t-md); font-family: inherit;
}
.input:focus { border-color: var(--primary); outline: none; }
.input::placeholder { color: var(--text-faint); }
select.input { cursor: pointer; }
.hint { font-size: var(--t-xs); color: var(--text-faint); margin-top: 5px; }

/* 计划选择卡（显示关键参数，不盲选） */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px,1fr)); gap: var(--s2); }
.plan {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s3); cursor: pointer; background: var(--bg);
  transition: border-color .12s, background .12s;
}
.plan:hover { border-color: var(--primary-dim); }
.plan.sel { border-color: var(--primary); background: #3b82f614; }
.plan .id { font-weight: 700; font-size: var(--t-md); }
.plan .goal { font-size: var(--t-xs); color: var(--text-dim); margin-top: 2px; }
.plan .meta { font-size: var(--t-xs); color: var(--text-faint); margin-top: var(--s2); line-height: 1.6; }

/* ── 空 / 加载 / 错误态 ───────────────────────────────── */
.state { padding: var(--s7) var(--s4); text-align: center; color: var(--text-dim); }
.state .icon { font-size: 26px; opacity: .5; margin-bottom: var(--s2); }
.state .title { font-size: var(--t-md); color: var(--text-2); margin-bottom: 4px; }
.state .desc  { font-size: var(--t-sm); color: var(--text-faint); }
.state.error .title { color: var(--danger); }

.skeleton {
  background: linear-gradient(90deg, #1a2338 25%, #222e4a 50%, #1a2338 75%);
  background-size: 200% 100%; animation: sk 1.2s infinite;
  border-radius: var(--r-sm); height: 12px; margin: var(--s2) 0;
}
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── 弹层 ─────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: #000000b8;
  display: none; align-items: center; justify-content: center; z-index: 100;
  padding: var(--s4);
}
.modal.open { display: flex; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s5);
  width: 100%; max-width: 400px; box-shadow: var(--shadow-lg);
}
.modal-box h3 { font-size: var(--t-lg); margin-bottom: var(--s2); }
.modal-box .desc { color: var(--text-dim); font-size: var(--t-sm); margin-bottom: var(--s4); }
.modal-actions { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s4); }

/* 危险确认：红边 + 强调金额 */
.modal-box.danger { border-color: var(--danger); }
.amount-callout {
  background: #ef444414; border: 1px solid #ef444455; border-radius: var(--r-md);
  padding: var(--s3); margin: var(--s3) 0; text-align: center;
}
.amount-callout .amt { font-size: var(--t-xl); font-weight: 700; color: var(--danger); }
.amount-callout .cap { font-size: var(--t-xs); color: var(--text-dim); }

.toast {
  position: fixed; right: var(--s5); bottom: var(--s5);
  background: var(--surface-3); border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--r-md); padding: var(--s3) var(--s4);
  box-shadow: var(--shadow); max-width: 340px; z-index: 200;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok   { border-left-color: var(--success); }
.toast.err  { border-left-color: var(--danger); }

/* ── 预警条目 ─────────────────────────────────────────── */
.alert-item {
  display: flex; gap: var(--s3); padding: var(--s3);
  border-radius: var(--r-md); background: var(--bg);
  border-left: 3px solid var(--neutral); margin-bottom: var(--s2);
}
.alert-item .body { flex: 1; min-width: 0; }
.alert-item .msg { font-size: var(--t-sm); color: var(--text-2); }
.alert-item .when { font-size: var(--t-xs); color: var(--text-faint); margin-top: 2px; }
.alert-item.lv-danger { border-left-color: var(--danger); }
.alert-item.lv-warn   { border-left-color: var(--warning); }

/* ── 响应式 ──────────────────────────────────────────── */
@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: fixed; width: 240px; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .topbar { padding: 0 var(--s3); gap: var(--s2); }
  .status-group .status:not(.essential) { display: none; }
  .content { padding: var(--s3); }
  .grid.kpi { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .grid.kpi { grid-template-columns: 1fr; }
  .kpi .value { font-size: var(--t-xl); }
}

/* 汉堡按钮（小屏） */
.menu-btn { display: none; background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer; padding: var(--s1) var(--s2); }
@media (max-width: 860px) { .menu-btn { display: block; } }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
