:root {
  --bg: #0b1220;
  --panel: #121c2e;
  --panel2: #17233a;
  --border: #26334d;
  --text: #e8eefc;
  --muted: #8fa2c4;
  --primary: #3b82f6;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 20% 0%, #16233d, var(--bg));
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 14px; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; flex-wrap: wrap; }
.inline { display: inline; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px;
  background: rgba(12, 20, 35, .92);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.logo { color: var(--primary); font-size: 20px; }
.main-nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
/* 导航分两段（.nav-bar / .nav-sheet）：桌面下两段各为一行 flex 片段，
   拼起来与改造前的 10 项完全同序；手机断点里再分别变成底部栏与上拉面板。 */
.nav-bar { display: flex; gap: 4px; }
.nav-sheet { display: flex; gap: 4px; }
.nav-sheet-title { display: none; }
.nav-more { display: none; }
.brand-text { display: inline; }
.brand-short { display: none; }
.tab-btn {
  background: transparent; color: var(--muted); border: 0;
  padding: 8px 12px; border-radius: 8px; white-space: nowrap;
}
.tab-btn:hover { background: var(--panel2); color: var(--text); }
.tab-btn.active { background: var(--primary); color: #fff; }
.user-box { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.clock-beijing { color: var(--text); font-size: 13px; font-variant-numeric: tabular-nums; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.container { max-width: 1360px; margin: 0 auto; padding: 18px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 20px; }
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.card-title { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.metric { font-size: 34px; font-weight: 700; letter-spacing: .5px; }
.sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bar { height: 8px; background: #0d1526; border-radius: 99px; margin-top: 12px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #22d3ee); width: 0; transition: width .4s; }
.kv-list { display: grid; gap: 8px; }
.kv-list > div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed #26334d; padding-bottom: 6px; }
.btn {
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  border-radius: 9px; padding: 9px 14px;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea {
  width: 100%; background: #0d1526; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px;
}
input[type="checkbox"] { width: auto; }
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
.checkline { display: flex; align-items: center; gap: 8px; }
input, select, textarea { margin-bottom: 2px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 500; }
.badge { background: #1e3a5f; color: #93c5fd; border-radius: 99px; padding: 3px 10px; font-size: 12px; }
.placeholder-box { text-align: center; padding: 50px 20px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.camera-view { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; min-height: 260px; display:flex; align-items:center; justify-content:center; }
.camera-view img { width: 100%; height: auto; display:block; }
.camera-osd { position:absolute; left:10px; top:10px; color:#fff; background:rgba(0,0,0,.45); padding:3px 7px; border-radius:5px; font-size:13px; pointer-events:none; white-space:pre-line; }
.camera-osd.bottom-left { top:auto; bottom:10px; }
.camera-osd.top-right { left:auto; right:10px; }
.camera-osd.bottom-right { left:auto; right:10px; top:auto; bottom:10px; }
.placeholder-box div:first-child { color: var(--text); font-size: 18px; margin-bottom: 8px; }

/* intercom */
.intercom-status { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #475569; display: inline-block; }
.dot.recording { background: var(--red); box-shadow: 0 0 0 5px rgba(239,68,68,.15); }
.meter { height: 10px; background: #0d1526; border-radius: 99px; margin-top: 14px; overflow: hidden; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, #22c55e, #eab308, #ef4444); width: 0; transition: width .08s; }

/* chat */
.chat-layout { display: grid; grid-template-columns: 1fr; }
.chat-card { display: flex; flex-direction: column; min-height: 62vh; }
.chat-history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px 2px; }
.msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; line-height: 1.5; }
.msg.user { align-self: flex-end; background: #1d4ed8; color: #fff; }
.msg.assistant { align-self: flex-start; background: #0d1526; border: 1px solid var(--border); }
.msg.system { align-self: center; color: var(--muted); font-size: 12px; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.chat-input textarea { resize: vertical; min-height: 54px; }
.tts-bar { margin-top: 10px; }
.tts-bar select, .tts-bar input { width: auto; min-width: 130px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 390px; background: linear-gradient(180deg, #17233a, #101a2b); border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: 0 25px 70px rgba(0,0,0,.4); }
.login-logo { font-size: 42px; color: var(--primary); text-align: center; }
.login-card h1 { font-size: 21px; text-align: center; margin: 8px 0 4px; }
.login-card > .muted { text-align: center; margin: 0 0 18px; }
.login-hint { color: var(--muted); font-size: 12px; margin-top: 14px; text-align: center; }
.flash { padding: 10px; border-radius: 8px; margin: 8px 0; font-size: 13px; }
.flash.error { background: rgba(239,68,68,.15); color: #fca5a5; }
.flash.success { background: rgba(34,197,94,.15); color: #86efac; }
.toast {
  position: fixed; right: 18px; bottom: 18px; max-width: 340px;
  background: #111c30; border: 1px solid var(--border); border-left: 4px solid var(--primary);
  padding: 12px 14px; border-radius: 10px; color: var(--text); font-size: 13px;
  opacity: 0; pointer-events: none; transform: translateY(10px); transition: all .25s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
.cal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* 每卡片保存按钮旁的「有未保存的修改」提示 */
.muted.small.dirty { color: #f5a623; opacity: 1; }

/* ---------- 设置页分类收纳（原生 details） ---------- */
details.acc {
  margin: 0 0 14px; border: 1px solid var(--border); border-radius: 10px;
  background: rgba(255, 255, 255, .02); overflow: hidden;
}
details.acc > summary {
  cursor: pointer; padding: 11px 14px; display: flex; flex-wrap: wrap;
  align-items: baseline; gap: 10px; user-select: none;
  background: rgba(255, 255, 255, .03);
  border-left: 3px solid var(--primary);
}
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: '▾ 收起'; margin-left: auto; font-size: 12px; opacity: .55; }
details.acc:not([open]) > summary::after { content: '▸ 展开'; }
details.acc > summary:hover { background: rgba(255, 255, 255, .07); }
details.acc > summary b { font-size: 14px; }
details.acc .acc-sub { font-size: 12px; opacity: .6; }
details.acc > *:not(summary) { padding-left: 14px; padding-right: 14px; }
details.acc > *:not(summary):last-child { padding-bottom: 14px; }

@media (max-width: 980px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .main-nav { order: 3; width: 100%; }
  .metric { font-size: 28px; }
}

/* ==========================================================================
   直板手机适配（≤720px）—— 导航改成底部固定栏 + 「更多」上拉面板
   桌面完全不受影响：以下规则全部在媒体查询内，且用 body:not(.page-sub)
   把「顶栏收一行 + 底部栏」限定在仪表盘（子页面沿用原顶栏导航）。
   ========================================================================== */
@media (max-width: 720px) {
  /* ---------- 顶栏收成一行：品牌 / 时钟 / 退出 ---------- */
  body:not(.page-sub) .topbar {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    /* 关键：backdrop-filter 会让元素成为 position:fixed 后代的包含块，
       底栏/上拉面板的 bottom:0 就会相对顶栏而不是视口解析（实测底栏会跑到顶部）。
       手机端关掉模糊，背景本就是 .92 不透明度，观感无差别。 */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .brand { font-size: 14px; min-width: 0; }
  .brand-full { display: none; }
  .brand-short { display: inline; }
  body:not(.page-sub) .brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body:not(.page-sub) .user-box { gap: 6px; }
  body:not(.page-sub) #current-user {
    max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px;
  }
  body:not(.page-sub) .clock-beijing { font-size: 12px; padding: 4px 7px; }
  /* 手机上只留「时:分:秒」；日期段由 app.js 单独放进 .clock-date（桌面仍显示完整日期） */
  body:not(.page-sub) .clock-date { display: none; }
  body:not(.page-sub) .user-box .btn { padding: 6px 10px; }

  /* ---------- 导航 → 底部固定栏 ---------- */
  body:not(.page-sub) .main-nav {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    order: 0; width: auto; flex: none;
    display: block; padding: 0;
    background: rgba(12, 20, 35, .97);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 40;
  }
  body:not(.page-sub) .nav-bar { display: flex; min-height: 56px; }
  body:not(.page-sub) .nav-bar > .tab-btn,
  body:not(.page-sub) .nav-bar > .nav-more {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 2px 6px;
    background: transparent; border: 0; border-radius: 0;
    color: var(--muted); font-size: 11px; line-height: 1.1;
    -webkit-tap-highlight-color: rgba(59, 130, 246, .25);
  }
  body:not(.page-sub) .nav-bar > .tab-btn::before,
  body:not(.page-sub) .nav-bar > .nav-more::before {
    content: attr(data-icon); font-size: 19px; line-height: 1;
  }
  /* 底栏用短标签（data-short），完整标签留给桌面与上拉面板 */
  body:not(.page-sub) .nav-bar > .tab-btn .tl,
  body:not(.page-sub) .nav-bar > .nav-more .tl { display: none; }
  body:not(.page-sub) .nav-bar > .tab-btn::after,
  body:not(.page-sub) .nav-bar > .nav-more::after {
    content: attr(data-short); font-size: 11px;
  }
  body:not(.page-sub) .nav-bar > .tab-btn.active,
  body:not(.page-sub) .nav-bar > .nav-more.active,
  body:not(.page-sub) .nav-bar > .nav-more.open { color: var(--primary); }
  body:not(.page-sub) .nav-bar > .tab-btn.active { background: transparent; }

  /* ---------- 「更多」上拉面板 ---------- */
  body:not(.page-sub) .nav-sheet {
    position: fixed; left: 0; right: 0;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    display: none; flex-direction: column; gap: 2px;
    max-height: 62vh; overflow-y: auto;
    padding: 4px 8px 10px;
    background: #101a2b;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -14px 34px rgba(0, 0, 0, .5);
    z-index: 39;
  }
  body:not(.page-sub) .nav-sheet.open { display: flex; }
  body:not(.page-sub) .nav-sheet-title {
    display: block; padding: 9px 10px 8px; margin-bottom: 2px;
    font-size: 12px; color: var(--muted);
    border-bottom: 1px solid var(--border);
  }
  body:not(.page-sub) .nav-sheet > .tab-btn {
    display: flex; align-items: center; gap: 12px;
    width: 100%; padding: 13px 12px; border-radius: 10px;
    font-size: 15px; text-align: left;
    background: transparent; color: var(--text);
  }
  body:not(.page-sub) .nav-sheet > .tab-btn::before {
    content: attr(data-icon); font-size: 18px; width: 22px; text-align: center;
  }
  body:not(.page-sub) .nav-sheet > .tab-btn.active { background: var(--primary); color: #fff; }

  /* ---------- 内容让出底栏高度 ---------- */
  body:not(.page-sub) .container {
    padding: 12px 12px calc(72px + env(safe-area-inset-bottom, 0px));
  }
  /* Toast 原本 fixed 在 bottom:18px，会被底栏盖住 */
  body:not(.page-sub) .toast {
    left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
  .chat-card { min-height: 52vh; }
  .panel-head h2 { font-size: 18px; }
  .cal-row { grid-template-columns: 1fr; }
}
