/*
 * 全站统一的设计系统：颜色取自 logo（深棕 #441E11、金色星星），
 * 登录页、工作台、案例、后台共用这一份。界面只做浅色，诊室里更清楚。
 */
:root {
  color-scheme: light;
  --brand: #441E11;
  --brand-hover: #5A2A19;
  --brand-ink: #FFFFFF;
  --brand-soft: #F4ECE7;
  --gold: #8A6100;
  --gold-bright: #F2C230;
  --gold-soft: #FBF2D4;
  --bg: #F7F4F1;
  --surface: #FFFFFF;
  --ink: #24160F;
  --muted: #74635A;
  --line: #E5DCD5;
  --ok: #1F7A4D;
  --ok-soft: #E2F2E8;
  --warn: #8A5A00;
  --warn-soft: #FFF1D2;
  --danger: #B3261E;
  --danger-soft: #FBE6E3;
  --marker: #D4402C;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(36, 22, 15, .06), 0 4px 14px rgba(36, 22, 15, .05);
  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.6; }
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 4px; text-wrap: balance; }
h2 { font-size: 17px; line-height: 1.35; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 6px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; padding: 8px 12px; background: var(--surface); border-radius: 8px; }
.skip:focus { left: 8px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 22px;
  min-height: 60px; padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand img { width: 40px; height: 40px; flex: none; }
.brand-text { display: grid; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 16px; }
.brand-text small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.mainnav { display: flex; gap: 2px; flex: 1; }
.mainnav a { position: relative; padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.mainnav a:hover { color: var(--ink); background: var(--bg); }
.mainnav a[aria-current="page"] { color: var(--brand); }
.mainnav a[aria-current="page"]::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 0; height: 3px; border-radius: 3px; background: var(--gold-bright); }
.topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.topbar-slot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.langs { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--bg); border: 1px solid var(--line); }
.langs a { padding: 3px 9px; border-radius: 6px; font-size: 12.5px; font-weight: 700; color: var(--muted); text-decoration: none; }
.langs a[aria-current="true"] { background: var(--surface); color: var(--brand); box-shadow: 0 1px 2px rgba(36, 22, 15, .14); }

.menu { position: relative; }
.menu summary { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer; list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { border-color: var(--brand); }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 13px; }
.menu-name { font-size: 14px; font-weight: 600; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 230px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 34px rgba(36, 22, 15, .18);
  display: grid; gap: 2px;
}
.menu-who { display: grid; padding: 6px 10px 10px; margin: 0 0 4px; border-bottom: 1px solid var(--line); }
.menu-who span { font-size: 12.5px; color: var(--muted); }
.menu-body a, .menu-body button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; border: 0; background: transparent;
  color: var(--ink); text-decoration: none; cursor: pointer;
}
.menu-body a:hover, .menu-body button:hover { background: var(--bg); }
.menu-body form { margin: 0; }

.subnav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.subnav a { padding: 5px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.subnav a:hover { color: var(--ink); background: var(--bg); }
.subnav a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }

main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 56px; }
body.wide main { max-width: 1560px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.page-head p { color: var(--muted); margin: 0; max-width: 60em; }

/* ---------- 基础组件 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; min-width: 0; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.hint { font-size: 13px; line-height: 1.6; color: var(--muted); }
.fine { font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions.end { justify-content: flex-end; margin-top: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 7px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--brand); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.gold { background: var(--gold-bright); border-color: var(--gold-bright); color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); }
.btn.small { min-height: 32px; padding: 3px 11px; font-size: 13.5px; border-radius: 8px; }
.btn.block { width: 100%; min-height: 46px; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.seg button { min-height: 36px; padding: 5px 14px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(36, 22, 15, .18); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.seg.small button { min-height: 30px; padding: 3px 11px; font-size: 13.5px; }

.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.off { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--brand-soft); color: var(--brand); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }

.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 16px; font-weight: 600; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: #5F3E00; }
.flash a, .notice a { color: inherit; margin-left: 6px; }
.errors { padding: 10px 14px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); margin-bottom: 14px; }
.errors ul { margin: 0; padding-left: 1.2em; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: #5F3E00; margin: 0 0 16px; font-size: 14px; }

/* ---------- 表单 ---------- */
form.stack { display: grid; gap: 14px; max-width: 640px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field > label, .field > .label { font-size: 13.5px; font-weight: 600; }
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field input[type="date"], .field input[type="search"], .field select, .field textarea {
  min-height: 40px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
.field textarea { min-height: 80px; resize: vertical; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.inline input[type="number"] { width: 140px; }
.inline select { width: auto; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checks label, label.check { display: inline-flex; align-items: flex-start; gap: 8px; font-weight: 500; cursor: pointer; }
.checks input, label.check input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--brand); flex: none; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.filters .field { min-width: 140px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 12px 14px; display: grid; gap: 12px; min-width: 0; }
legend { padding: 0 6px; font-weight: 700; font-size: 14px; }
input[type="range"] { width: 100%; accent-color: var(--brand); }

/* ---------- 表格和统计 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--ink); }
td.num, th.num { text-align: right; }
td .sub, .sub { display: block; font-size: 12.5px; color: var(--muted); }
tr.muted td { color: var(--muted); }
.empty { color: var(--muted); padding: 18px 0; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat > span { font-size: 13px; color: var(--muted); }
.stat.sm b { font-size: 17px; line-height: 1.5; padding: 4px 0 3px; }

.bar { position: relative; height: 6px; border-radius: 3px; background: var(--bg); margin-top: 4px; min-width: 90px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--brand); }
.bar.warn i { background: #D68A00; }
.bar.off i { background: var(--danger); }

dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; font-size: 14.5px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 600; }

.chart { display: block; width: 100%; height: auto; color: var(--muted); }
.chart .bar-ok { fill: var(--brand); }
.chart .bar-fail { fill: #D9A441; }
.chart text { font-size: 11px; fill: currentColor; font-family: var(--font); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; font-size: 14px; color: var(--muted); }

/* ---------- 案例列表 ---------- */
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.case-card { display: grid; grid-template-rows: auto 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.case-thumb { position: relative; display: block; aspect-ratio: 4 / 3; background: #E9E2DC; overflow: hidden; }
.case-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.case-thumb .chip { position: absolute; left: 8px; top: 8px; }
.case-body { padding: 12px 14px 14px; display: grid; gap: 4px; align-content: start; }
.case-body strong { font-size: 15px; overflow-wrap: anywhere; }
.case-body .meta { font-size: 12.5px; color: var(--muted); }
.case-actions { display: flex; gap: 8px; margin-top: 8px; }
.case-actions form { margin: 0; }

/* ---------- 弹窗和提示 ---------- */
dialog { width: min(560px, calc(100vw - 32px)); border: 0; border-radius: 16px; padding: 22px; color: var(--ink); box-shadow: 0 20px 60px rgba(36, 22, 15, .32); }
dialog::backdrop { background: rgba(36, 22, 15, .5); }
dialog h2 { margin-bottom: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80;
  max-width: min(580px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: #FFFFFF; box-shadow: 0 8px 30px rgba(36, 22, 15, .32);
}

/* ---------- 登录等单卡片页面 ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; background: linear-gradient(180deg, #F4ECE7 0%, var(--bg) 46%); }
.auth-wrap { width: min(420px, 100%); }
.auth-wrap.wide { width: min(580px, 100%); }
.auth-brand { display: grid; justify-items: center; gap: 4px; text-align: center; margin-bottom: 18px; }
.auth-brand img { width: 84px; height: 84px; }
.auth-brand strong { font-size: 22px; margin-top: 6px; }
.auth-brand span { font-size: 13px; color: var(--muted); }
.auth-card { position: relative; padding: 26px; margin: 0; }
.auth-card h1 { font-size: 18px; margin-bottom: 14px; }
.auth-card form.stack { max-width: none; }
.auth-lang { position: absolute; right: 16px; top: 16px; }
.auth-foot { text-align: center; font-size: 12px; color: var(--muted); margin: 16px 0 0; }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .brand-text small { display: none; }
  .mainnav { order: 3; flex-basis: 100%; }
  .topbar-right { margin-left: auto; }
}
@media (max-width: 560px) {
  main { padding: 16px 12px 40px; }
  /* 手机上顶栏会折成几行，不再固定在顶部，免得占掉半屏 */
  .topbar { position: static; padding: 8px 12px; gap: 8px 10px; }
  /* 第一行：标志 + 语言 + 头像；第二行：页面自己的工具；第三行：导航 */
  .topbar-right { display: contents; }
  .brand { flex: 1; }
  .langs { order: 1; }
  .menu { order: 2; }
  .topbar-slot { order: 3; flex-basis: 100%; gap: 8px; }
  .mainnav { order: 4; }
  .menu-name { display: none; }
  .menu summary { padding: 3px; }
}
