/* ============================================================================
   LuLu妙妙屋 · 云端版
   配色直接沿用桌面端 src/ui/theme.py 的色板，保证「同一个软件」的观感：
     底  #0D0D0D / 卡片 #151515 / 浮层 #1A1A1A / 边 #262626
     字  #EDEDED / 次 #8C8C8C / 弱 #595959
     蓝 #3B82F6  绿 #72A57C  橙 #D9A45B  红 #E06C6C  紫 #9C8AC4  青 #5B9BD5
   ========================================================================== */

:root {
  --bg: #0d0d0d;
  --panel: #151515;
  --panel-2: #1a1a1a;
  --panel-3: #1f1f1f;
  --hover: #1e1e1e;
  --zebra: #181818;
  --border: #262626;
  --border-soft: #1f1f1f;
  --text: #ededed;
  --muted: #8c8c8c;
  --faint: #595959;
  --blue: #3b82f6;
  --green: #72a57c;
  --orange: #d9a45b;
  --red: #e06c6c;
  --purple: #9c8ac4;
  --teal: #4fa8a0;
  --pink: #c98aa8;
  --cyan: #5b9bd5;
  --amber: #c9a227;
  --cyan: #5b9bd5;
  --scrim: rgba(0, 0, 0, .55);
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --radius: 12px;
  --radius-sm: 8px;
  --side-w: 238px;
  --font: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC",
          -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

html[data-theme="light"] {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f2f4f7;
  --panel-3: #e9edf2;
  --hover: #eef2f7;
  --zebra: #fafbfc;
  --border: #e2e6ec;
  --border-soft: #edf0f4;
  --text: #171a20;
  --muted: #667085;
  --faint: #98a2b3;
  --blue: #2563eb;
  --green: #3f8f5c;
  --orange: #b97c20;
  --red: #cf4b4b;
  --purple: #7b63b8;
  --teal: #2f857d;
  --pink: #a85a7c;
  --cyan: #2f6fa8;
  --amber: #9a7b12;
  --cyan: #2f7fbf;
  --scrim: rgba(15, 23, 42, .35);
  --shadow: 0 10px 30px rgba(15, 23, 42, .10);
}

* { box-sizing: border-box; }
/* ⚠️ 必须有这一条：`.gate/.shell/.toast` 自己写了 display，会盖掉浏览器默认的
   `[hidden] { display: none }`，导致「隐藏了却还在屏幕上」。 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2f2f2f; border-radius: 8px; border: 2px solid var(--bg); }
html[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c8cfd9; }

/* ------------------------------------------------------------------ 编辑弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center;
  background: rgba(0, 0, 0, .55); padding: 18px;
  backdrop-filter: blur(2px);
}
.modal-card {
  width: 100%; max-width: 420px; max-height: 86dvh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 {
  flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modal-x {
  width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 18px; line-height: 1;
}
.modal-x:hover { background: var(--hover); color: var(--text); }
.modal-body { padding: 12px 16px; overflow: auto; }
.modal-hint { color: var(--faint); font-size: 11.5px; line-height: 1.6; margin-bottom: 12px; }
.fld { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 10px; margin-bottom: 9px; }
.fld > span { color: var(--muted); font-size: 12.5px; text-align: right; }
.fld input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.fld input:focus { outline: none; border-color: var(--blue); }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 10px 16px 14px; border-top: 1px solid var(--border-soft);
}
.modal-foot .btn { height: 34px; }
.modal-foot .btn.danger { color: var(--red); border-color: rgba(212, 107, 107, .4); }
.modal-foot .btn.danger:hover { background: rgba(212, 107, 107, .12); }
.modal-foot .spacer { flex: 1; }
tbody tr[data-editable] { cursor: pointer; }
.mcard[data-editable] { cursor: pointer; }

/* ------------------------------------------------------------------ 启动动画
   复刻桌面 splash.py 的构图与节奏：
     0.18s 字标淡入上浮 → 0.86s Lummy 从字的右后方升起探头 → 1.62s 眨眼
     → 1.70s 歪头 → 1.96s Lummy 缩回 → 2.18s 字标淡出 → 2.40s 圆环淡入
   角色是分层素材（body/hat/eyes），所以帽尖有惯性摆动。
   手机端只改比例（--fs），构图与时间轴不变。 */
.boot {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: grid; place-items: center;
  transition: opacity .38s ease;
  /* 环直径 = 窗口高的 5.6%（桌面 ring_d），线宽 = 直径的 24.5%（ring_w），
     所以是一个偏粗的紫环，不是细线 */
  --ring: clamp(38px, 5.6vh, 54px);
}
.boot.is-leaving { opacity: 0; }
.boot-stage {
  grid-area: 1 / 1; position: relative;
  --fs: clamp(54px, 22vw, 168px);       /* 字标字号：手机端按屏宽缩，比例不变 */
  --lu: calc(var(--fs) * .68);          /* 角色高度 = 0.68 × 字号（同桌面 lummy_h） */
  animation: stage-out .3s 2.48s forwards;
}
.boot--simple .boot-stage { display: none; }

/* 字标：底色即「挡板」，把 Lummy 的下半身遮住，只让头从字后面露出来 */
.boot-title {
  position: relative; z-index: 2; display: block;
  font-family: 'Arial Black', 'Segoe UI Black', Impact, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-weight: 900; font-size: var(--fs); line-height: .86;
  letter-spacing: .01em; color: var(--text);
  background: var(--bg); padding: 0 .04em;
}
.boot-lummy {
  position: absolute; z-index: 1;
  width: var(--lu); height: var(--lu);
  left: calc(100% - var(--lu) * .55);   /* 探头位置：从字右边缘往里收 0.55 身高 */
  /* 脚底压到字上沿之下 0.40 身高；+0.07em 是补偿行盒比字帽高出的那一截，
     补完露出的头部高度与桌面 glyph_rect 挡板一致 */
  top: calc(var(--lu) * .40 + var(--fs) * .07);
  transform: translate(-50%, -100%);
}
.bl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; }
.bl-hat { transform-origin: 50% 39%; }
.bl-shut { opacity: 0; }

.boot-ring {
  grid-area: 1 / 1; width: var(--ring); height: var(--ring);
  animation: none;
}
.ring-track { fill: none; stroke: rgba(142, 123, 192, .2); stroke-width: 12.25; }
/* 70% 圆弧（RING_GAP=0.30）＋圆头，转速 250°/s → 一圈 1.44s，方向顺时针 */
.ring-arc {
  fill: none; stroke: #a896d8; stroke-width: 12.25; stroke-linecap: round;
  stroke-dasharray: 83 35.6;
  transform-box: view-box;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  animation: ring-spin 1.44s linear infinite;
}
.boot-text {
  grid-area: 1 / 1; margin: 0;
  transform: translateY(calc(var(--ring) * .5 + 24px));
  font-size: 12px; letter-spacing: .05em; color: var(--muted);
}

/* —— 每天第一次：完整片头 —— */
.boot--intro .boot-title {
  animation: title-in .58s .18s cubic-bezier(.2, .8, .3, 1) both,
             title-out .30s 2.18s ease-in forwards;
}
.boot--intro .boot-lummy {
  animation: lummy-rise .52s .86s cubic-bezier(.2, 1.15, .3, 1) both,
             lummy-out .32s 1.96s ease-in forwards,
             lummy-tilt .34s 1.70s ease-in-out both;
}
.boot--intro .bl-open { animation: blink-open .24s 1.62s both; }
.boot--intro .bl-shut { animation: blink-shut .24s 1.62s both; }
.boot--intro .bl-hat { animation: hat-sway 1.1s .86s ease-in-out 2; }
.boot--intro .boot-ring { animation: ring-in .34s 2.40s both; }
.boot--intro .boot-text { display: none; }

/* —— 当天已经播过：只转圈，数据到就结束 —— */
.boot--simple .boot-ring { animation: boot-fade .3s both; }
.boot--simple .boot-text { animation: boot-fade .4s .08s both; }

@keyframes title-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes title-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes stage-out { to { opacity: 0; } }
@keyframes lummy-rise {
  from { opacity: 0; transform: translate(-50%, calc(-100% + var(--lu) * .70)); }
  to   { opacity: 1; transform: translate(-50%, -100%); }
}
@keyframes lummy-out {
  from { opacity: 1; transform: translate(-50%, -100%); }
  to   { opacity: 0; transform: translate(-50%, calc(-100% + var(--lu) * .18)); }
}
@keyframes lummy-tilt { 0%, 100% { rotate: 0deg; } 50% { rotate: 3deg; } }
@keyframes blink-open { 0%, 100% { opacity: 1; } 45%, 55% { opacity: 0; } }
@keyframes blink-shut { 0%, 100% { opacity: 0; } 45%, 55% { opacity: 1; } }
@keyframes ring-in { from { opacity: 0; scale: .72; } to { opacity: 1; scale: 1; } }
@keyframes hat-sway { 0%, 100% { transform: rotate(-1.8deg); } 50% { transform: rotate(1.8deg); } }
@keyframes ring-spin { to { transform: rotate(270deg); } }
@keyframes boot-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .boot-stage, .boot-title, .boot-lummy, .bl-open, .bl-shut, .bl-hat { animation: none !important; }
  .bl-shut { opacity: 0; }
}

/* ------------------------------------------------------------------ 打不开时的兜底面板 */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(59, 130, 246, .16), transparent 62%),
    var(--bg);
  padding: 22px;
}
.gate-card {
  width: 100%; max-width: 384px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.brand-mark {
  width: 56px; height: 56px; margin: 0 auto 14px;
  display: grid; place-items: center;
  color: var(--blue);
  background: rgba(59, 130, 246, .1);
  border: 1px solid rgba(59, 130, 246, .28);
  border-radius: 16px;
  overflow: hidden;
}
.brand-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-mark svg { width: 34px; height: 34px; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; border-radius: 11px; }
.brand-mark.small svg { width: 24px; height: 24px; }
.gate-card h1 { font-size: 20px; letter-spacing: .3px; font-weight: 600; }
.gate-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.gate-hint { margin-top: 13px; color: var(--muted); font-size: 12px; min-height: 18px; line-height: 1.6; }
.gate-hint.err { color: var(--red); }
.gate-foot {
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border-soft);
  color: var(--faint); font-size: 11.5px;
}
.btn {
  height: 38px; padding: 0 15px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2);
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: #333; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 500; }
.btn-primary:hover { background: #4b8df7; border-color: #4b8df7; }
.btn-block { width: 100%; justify-content: center; height: 42px; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { background: transparent; }

/* ------------------------------------------------------------------ 骨架 */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--side-w); flex: 0 0 var(--side-w);
  height: 100vh; position: sticky; top: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
  z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 18px 16px 14px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.brand-text strong { font-size: 14.5px; font-weight: 600; letter-spacing: .2px; }
.brand-text span { font-size: 11px; color: var(--faint); letter-spacing: .4px; }

.nav { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.nav-group { margin-top: 14px; }
.nav-group:first-child { margin-top: 2px; }
.nav-label {
  font-size: 11px; color: var(--faint); letter-spacing: 1.4px;
  padding: 0 8px 6px; display: flex; align-items: center; gap: 8px;
}
.nav-label::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 9px; margin-bottom: 2px;
  border-radius: 8px; color: var(--muted);
  text-decoration: none; font-size: 13.5px;
  border: 1px solid transparent;
  transition: background .14s, color .14s;
}
.nav-item .ico { width: 17px; height: 17px; opacity: .85; flex: 0 0 17px; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active {
  background: var(--panel-2); color: var(--text);
  border-color: var(--border); font-weight: 500;
}
.nav-item.active .ico { color: var(--blue); opacity: 1; }
.nav-item .badge {
  margin-left: auto; font-size: 10.5px; color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.side-foot { padding: 10px; border-top: 1px solid var(--border-soft); display: grid; gap: 4px; }
.side-btn {
  display: flex; align-items: center; gap: 9px;
  height: 34px; padding: 0 9px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 12.5px; text-align: left;
}
.side-btn:hover { background: var(--panel); color: var(--text); }
.side-btn .ico { width: 16px; height: 16px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.page-head { min-width: 0; }
.page-head h1 {
  font-size: 19px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page-head p { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px; flex: 0 0 auto;
  display: grid; place-items: center; padding: 0; line-height: 0;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn > svg, .icon-btn > .ico { display: block; }
.icon-btn:hover { color: var(--text); background: var(--hover); }
.icon-btn .ico { width: 17px; height: 17px; }
.only-mobile { display: none; }

.sync-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--muted); font-size: 12px; white-space: nowrap; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.sync-pill:hover { color: var(--text); }
.sync-pill .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px rgba(114, 165, 124, .16);
}
.sync-pill.bad .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(224, 108, 108, .16); }
.sync-pill.loading .dot { background: var(--orange); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.view { padding: 18px 24px 8px; flex: 1; min-width: 0; }
.foot {
  padding: 12px 24px 18px; color: var(--faint); font-size: 11.5px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.dot-sep { opacity: .5; }

/* ------------------------------------------------------------------ 通用块 */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 16px 14px;
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.card-head h3 { font-size: 13.5px; font-weight: 600; letter-spacing: .2px; }
.card-head .sub { font-size: 11.5px; color: var(--faint); }
.card-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpis.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.k5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.charts-3 { grid-template-columns: 5fr 3fr 4fr; }
.charts-2 { grid-template-columns: 1fr 1fr; }
.charts-3, .charts-2 { display: grid; gap: 12px; }
.charts-trend { display: grid; gap: 12px; grid-template-columns: 1.55fr 1fr; }

.kpi {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px 12px;
  position: relative; overflow: hidden;
}
.kpi .k-label { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .k-label i {
  width: 6px; height: 6px; border-radius: 2px; background: var(--blue); display: inline-block;
}
.kpi .k-value {
  font-size: 23px; font-weight: 600; letter-spacing: -.3px; margin-top: 5px;
  font-variant-numeric: tabular-nums; line-height: 1.2; word-break: break-all;
}
.kpi .k-sub { font-size: 11px; color: var(--faint); margin-top: 3px;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.good .k-value { color: var(--green); }
.kpi.bad .k-value { color: var(--red); }
.kpi.accent .k-value { color: var(--blue); }

/* 图表 */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--border-soft); stroke-width: 1; }
.chart .series-line { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { fill: url(#gradLine); }
.chart .point { fill: var(--panel); stroke: var(--blue); stroke-width: 2; }
.chart .hover-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .bar-label { fill: var(--muted); font-size: 11.5px; }
.chart .bar-value { fill: var(--text); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .empty { fill: var(--faint); font-size: 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.legend-side, .legend-v { display: grid; gap: 7px; align-content: center; }
.legend-v { padding: 0 2px; }
.legend-side .tr, .legend-v .tr {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12px; color: var(--muted);
}
.legend-side .tr span:last-child, .legend-v .tr span:last-child {
  font-variant-numeric: tabular-nums; color: var(--text);
}
.donut-row {
  display: flex; align-items: center; gap: 14px;
  max-width: 640px; margin: 0 auto; width: 100%;
}
.donut-compact { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.donut-compact svg { align-self: center; }
.toolbar-end { display: flex; align-items: center; gap: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.legend i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }

/* 提醒 */
.alerts { display: grid; gap: 8px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--border-soft);
}
.alert .mark { width: 4px; align-self: stretch; border-radius: 3px; background: var(--blue); flex: 0 0 4px; }
.alert.danger .mark { background: var(--red); }
.alert.warning .mark { background: var(--orange); }
.alert.info .mark { background: var(--cyan); }
.alert.success .mark { background: var(--green); }
.alert .t { font-size: 12.8px; font-weight: 500; }
.alert .d { font-size: 11.8px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.alert .n { margin-left: auto; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* 工具条 */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.search {
  position: relative; display: flex; align-items: center;
}
.search svg { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--faint); }
.search input {
  height: 34px; width: 240px; padding: 0 12px 0 31px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  outline: none;
}
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, .14); }
select.ctl, input.ctl {
  height: 34px; padding: 0 10px; border-radius: 9px;
  background: var(--panel); border: 1px solid var(--border);
  outline: none; color: var(--text);
}
select.ctl:focus, input.ctl:focus { border-color: var(--blue); }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font-size: 12.5px;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel-3); color: var(--text); }
.spacer { flex: 1; }
.count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

/* 表格 */
.table-wrap { overflow: auto; max-height: calc(100vh - 250px); border-radius: var(--radius); }
table.data {
  width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.8px;
  white-space: nowrap;
}
table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2); color: var(--muted);
  font-weight: 500; text-align: left;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
table.data thead th:hover { color: var(--text); }
table.data thead th .arrow { font-size: 9px; margin-left: 4px; opacity: .55; }
table.data thead th.num, table.data tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody td {
  padding: 8px 12px; border-bottom: 1px solid var(--border-soft);
  max-width: 420px; overflow: hidden; text-overflow: ellipsis;
}
table.data tbody tr { background: var(--panel); }
table.data tbody tr:nth-child(even) { background: var(--zebra); }
table.data tbody tr:hover { background: var(--hover); }
/* 列多的时候首列吸在左边（单元格背景 inherit 自 tr，斑马纹/悬停色才会跟着走） */
table.data.sticky-first th:first-child,
table.data.sticky-first td:first-child {
  position: sticky; left: 0; z-index: 3; background: inherit;
  box-shadow: 1px 0 0 var(--border-soft);
}
table.data.sticky-first thead th:first-child { background: var(--panel-2); z-index: 5; }
table.data tbody td.name { white-space: normal; min-width: 260px; line-height: 1.45; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px;
  border: 1px solid var(--border); color: var(--muted); background: var(--panel-2);
}
.tag.blue { color: var(--blue); border-color: rgba(59,130,246,.35); background: rgba(59,130,246,.1); }
.tag.purple { color: var(--purple); border-color: rgba(156,138,196,.35); background: rgba(156,138,196,.1); }
.neg { color: var(--red); }
.pos { color: var(--green); }
.dim { color: var(--faint); }

.empty {
  padding: 46px 20px; text-align: center; color: var(--faint); font-size: 12.5px;
}
.empty strong { display: block; color: var(--muted); font-size: 14px; margin-bottom: 5px; font-weight: 500; }

.section { margin-bottom: 16px; }
.section-title {
  font-size: 12px; color: var(--faint); letter-spacing: 1.1px;
  margin: 4px 0 9px;
}

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-3); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 10px; font-size: 12.5px;
  box-shadow: var(--shadow); z-index: 60;
}
.tip {
  position: fixed; z-index: 70; pointer-events: none;
  background: var(--panel-3); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px; font-size: 11.5px;
  box-shadow: var(--shadow); min-width: 108px;
}
.tip .tt { color: var(--muted); margin-bottom: 3px; font-size: 11px; }
.tip .tv { font-variant-numeric: tabular-nums; font-size: 12.5px; }
.tip .tr { display: flex; gap: 12px; justify-content: space-between; }
.tip .tr span:last-child { font-variant-numeric: tabular-nums; }

.scrim { display: none; }

/* ------------------------------------------------------------------ 手机卡片表
   ≤640px 不再横向拖表格：一行 = 一张卡，先给 4 个关键数字，点「全部字段」展开。
   卡片由 app.js 的 tableCards() 生成，字段口径仍来自同一份 columns 定义。 */
.mcards { display: grid; gap: 10px; padding: 10px; }
.mcard {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 13px 10px;
}
.mcard .mc-title {
  font-size: 13.5px; font-weight: 500; line-height: 1.45;
  margin-bottom: 9px; word-break: break-word;
}
.mcard .mc-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px;
}
.mcard .mc-grid div { min-width: 0; }
/* ⚠️ 只选中「标签」那一层（值是 <b><span class=pos>…</span></b>，
   写成 `.mc-grid span` 会把值的颜色也刷成灰色、字号压到 11px） */
.mcard .mc-grid > div > span {
  display: block; font-size: 11px; color: var(--faint); margin-bottom: 2px;
}
.mcard .mc-grid b {
  display: block; font-size: 15px; font-weight: 600;
  font-variant-numeric: tabular-nums; line-height: 1.3;
  word-break: break-all;
}
.mcard .mc-more {
  margin-top: 10px; width: 100%; height: 30px;
  border: 1px solid var(--border-soft); background: transparent;
  color: var(--muted); border-radius: 8px; font-size: 12px;
}
.mcard .mc-more:active { background: var(--hover); }
.mcard dl.mc-all {
  margin: 9px 0 0; padding-top: 9px; border-top: 1px dashed var(--border-soft);
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px 12px;
}
.mcard dl.mc-all > div { min-width: 0; }
.mcard dl.mc-all dt { font-size: 10.5px; color: var(--faint); }
.mcard dl.mc-all dd {
  margin: 1px 0 0; font-size: 12px; color: var(--text);
  font-variant-numeric: tabular-nums; word-break: break-word;
}
.mc-sortbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 0; font-size: 12px; color: var(--muted);
}
.mc-sortbar select { flex: 1; height: 32px; }
.mc-total { padding: 2px 12px 0; font-size: 11.5px; color: var(--faint); }

/* ------------------------------------------------------------------ 底部导航（手机） */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 28;
  display: none; align-items: stretch;
  height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-soft);
}
.tabbar a, .tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; border: 0; background: transparent;
  color: var(--faint); text-decoration: none; font-size: 10.5px;
  padding: 4px 2px 2px;
}
.tabbar .ico { width: 20px; height: 20px; }
.tabbar a.active, .tabbar button.active { color: var(--blue); }
.tabbar a.active .ico, .tabbar button.active .ico { stroke-width: 2; }

/* 手机上按下去的反馈：轻微缩一下，比纯变色更有"按到了"的感觉 */
button, .btn, .seg button, .tabbar a, .nav-item, .icon-btn, .sync-pill {
  transition: transform .12s ease, background-color .15s ease, color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
button:active, .btn:active, .seg button:active, .icon-btn:active,
.sync-pill:active, .tabbar a:active { transform: scale(.96); }

/* ------------------------------------------------------------------ 响应式 */

/* 平板横屏 / 小笔记本：侧栏收成 76px 图标柱（和桌面版的「收起侧栏」一个样子），
   把宽度让给表格 —— 1024px 下能多出一整列 */
@media (min-width: 901px) and (max-width: 1180px) {
  :root { --side-w: 76px; }
  .brand { justify-content: center; padding: 16px 6px 10px; }
  .brand-text { display: none; }
  .nav { padding: 2px 8px 10px; }
  .nav-label { display: none; }
  .nav-group {
    margin-top: 8px; padding-top: 8px;
    border-top: 1px solid var(--border-soft);
  }
  .nav-group:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
  .nav-item { justify-content: center; padding: 0; height: 42px; }
  .nav-item > span { display: none; }
  .nav-item .badge { display: none; }
  .nav-item .ico { width: 19px; height: 19px; flex: 0 0 19px; }
  .side-btn { justify-content: center; padding: 0; height: 38px; }
  .side-btn > span { display: none; }
  .side-foot { padding: 8px 6px; }
}

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .charts-3, .charts-trend { grid-template-columns: 1fr 1fr; }
  .charts-3 > :first-child { grid-column: 1 / -1; }
}

/* 竖屏平板 / 大手机：抽屉侧栏 */
@media (max-width: 900px) {
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100dvh;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow); z-index: 40;
  }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim {
    display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 35;
  }
  .view, .topbar, .foot { padding-left: 14px; padding-right: 14px; }
  .page-head h1 { font-size: 17px; }
  .page-head p { display: none; }
  .sync-pill { max-width: 46vw; overflow: hidden; }
  /* 竖屏平板：6 张卡走 3 列（两行），4 张卡一行放得下就一行 */
  .kpis, .kpis.k3, .kpis.k5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi .k-value { font-size: 20px; }
  .charts-3, .charts-2, .charts-trend { grid-template-columns: 1fr; }
  .search input { width: 200px; }
  .table-wrap { max-height: none; }
  /* 平板竖屏不是卡片模式：表格在容器里滚，表头才不会跟着长页面跑丢 */
  @media (min-width: 641px) {
    .table-wrap { max-height: calc(100dvh - 236px); }
  }
  .card { padding: 12px; }
  .foot { font-size: 11px; }
  table.data tbody td.name { min-width: 200px; }
}

/* 手机 */
@media (max-width: 640px) {
  .tabbar { display: flex; }
  .tabbar a, .tabbar button { flex: 1 1 0; min-width: 0; font-size: 10px; padding: 4px 0 2px; }
  .tabbar .ico { width: 19px; height: 19px; }

  /* 顶栏：标题可截断，右侧按钮与药丸固定不被挤出屏幕 */
  .topbar { gap: 8px; padding-left: 14px; padding-right: 14px; }
  .page-head { flex: 1 1 auto; min-width: 0; }
  .page-head h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { flex: 0 0 auto; }
  /* 只限宽 + 裁剪；不能改成 inline-block，否则里面的状态点会被拉成竖条 */
  .sync-pill { max-width: 38vw; overflow: hidden; }
  .sync-pill #sync-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .icon-btn { width: 38px; height: 38px; border-radius: 10px; }
  .icon-btn .ico { width: 18px; height: 18px; }
  .shell { padding-bottom: 0; }
  .view { padding-bottom: 12px; }
  .foot {
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .page-head h1 { font-size: 16px; }
  .sync-pill { max-width: none; font-size: 11.5px; }
  .top-actions { gap: 6px; }

  /* 手机：6 张卡压成 2 行（3 列），比原来 2 列 3 行省下约 100px 高度。
     字号跟着屏宽走（clamp），「¥774,952.11」在 375px 宽下也放得下。 */
  .kpis, .kpis.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis.k4, .kpis.k5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 8px 9px 7px; border-radius: 9px; }
  .kpi .k-value {
    /* 3 列时每张卡只有 ~112px，「¥774,952.11」要压得住：字号再收一点 */
    font-size: clamp(12px, 3.85vw, 16px); margin-top: 2px;
    letter-spacing: -.4px; white-space: nowrap;
    overflow: hidden; text-overflow: clip;
  }
  .kpi .k-label { font-size: 10px; gap: 4px; }
  .kpi .k-label i { width: 6px; height: 6px; }
  .kpi .k-sub { display: none; }
  .card { padding: 11px; border-radius: 10px; }
  .card-head { margin-bottom: 9px; }
  .card-head h3 { font-size: 13px; }

  /* 工具条：页签独占一行，搜索独占一行，筛选并排，右侧按钮一组 */
  .toolbar { gap: 8px; margin-bottom: 8px; }
  /* 时间范围：五个按钮平铺占满一行，比在窄屏上缩成一坨好读 */
  .toolbar > .seg { width: 100%; display: flex; }
  .toolbar > .seg button { flex: 1 1 0; min-width: 0; padding: 0 4px; font-size: 12px; }
  .toolbar .seg { flex: 1 1 100%; }
  .toolbar .seg button { flex: 1; padding: 0 6px; font-size: 12px; }
  .toolbar .search { flex: 1 1 100%; }
  .toolbar .search input { width: 100%; height: 36px; }
  .toolbar select.ctl { flex: 1 1 calc(50% - 4px); min-width: 0; height: 36px; }
  .toolbar .spacer { display: none; }
  .toolbar-end { flex: 1 1 100%; justify-content: space-between; }
  .toolbar-end .btn { height: 32px; }
  .count { font-size: 11.5px; }

  .alerts .alert { padding: 9px 10px; }
  .alert .t { font-size: 12.5px; }
  .alert .d { font-size: 11.5px; line-height: 1.55; }

  .toast { bottom: calc(70px + env(safe-area-inset-bottom)); max-width: 86vw; text-align: center; }
  .gate { padding: 16px; }
  .gate-card { padding: 26px 20px 20px; }
  .gate-card h1 { font-size: 18px; }
}

@media (max-width: 380px) {
  .kpi .k-value { font-size: 16.5px; }
  .mcard .mc-grid { gap: 8px 10px; }
}
