/* Fage OS 样式:电脑(侧栏)/ 平板(图标栏)/ 手机(底部导航)三端自适应,浅色 + 深色。 */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f7f8fa; --border: #e4e7ec;
  --text: #1c2026; --muted: #68707d; --primary: #1668dc; --primary-soft: #e8f1fe; --on-primary: #ffffff;
  --ok: #18794e; --ok-soft: #e3f5ec; --warn: #a15c00; --warn-soft: #fdf1dc; --bad: #c62a2f; --bad-soft: #fde8e8;
  --info: #1668dc; --info-soft: #e8f1fe; --track: #e9ecf1; --ref: #8b93a1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05); --radius: 12px;
  --nav-w: 208px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111317; --surface: #1a1d23; --surface-2: #20242b; --border: #2c313a;
  --text: #e8eaee; --muted: #9aa2af; --primary: #4c94f5; --primary-soft: #1b2b45; --on-primary: #0b1220;
  --ok: #4cc38a; --ok-soft: #16301f; --warn: #f0b34a; --warn-soft: #382a10; --bad: #f2777a; --bad-soft: #3a1b1d;
  --info: #4c94f5; --info-soft: #1b2b45; --track: #2a2f38; --ref: #7d8695;
  --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --surface: #1a1d23; --surface-2: #20242b; --border: #2c313a;
    --text: #e8eaee; --muted: #9aa2af; --primary: #4c94f5; --primary-soft: #1b2b45; --on-primary: #0b1220;
    --ok: #4cc38a; --ok-soft: #16301f; --warn: #f0b34a; --warn-soft: #382a10; --bad: #f2777a; --bad-soft: #3a1b1d;
    --info: #4c94f5; --info-soft: #1b2b45; --track: #2a2f38; --ref: #7d8695;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
h1 { font-size: 20px; line-height: 1.3; }
h2 { font-size: 15px; }
h3 { font-size: 16px; }
a { color: var(--primary); text-decoration: none; }
b { font-weight: 600; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 12.5px; }
.tone-ok { color: var(--ok); } .tone-bad { color: var(--bad); } .tone-warn { color: var(--warn); } .tone-primary { color: var(--primary); }
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); font-weight: 700; letter-spacing: .04em; }

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.nav { display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 800; font-size: 17px; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--on-primary); font-weight: 800; flex: none; }
.nav-links { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: var(--muted); border: 0; background: none; cursor: pointer; font-weight: 500; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-more { display: none; }
.nav-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 10px 4px 0 12px; border-top: 1px solid var(--border); }
.nav-user { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.nav-logout { padding: 8px 10px; font-size: 13px; gap: 6px; }
.main { overflow-y: auto; min-width: 0; -webkit-overflow-scrolling: touch; }
.page { max-width: 1180px; margin: 0 auto; padding: 22px 24px 40px; display: flex; flex-direction: column; gap: 14px; }
.page-narrow { max-width: 760px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back { color: var(--muted); }

/* ---------- 卡片与列表 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; padding: 13px 16px 0; }
.card-extra { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.card-head + .card-body { padding-top: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.grid-2-wide { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.35; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-sub { color: var(--muted); font-size: 12px; }
.stat .bar { margin-top: 6px; }
.mini-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini-stats .stat { border: 0; box-shadow: none; background: var(--surface-2); padding: 10px 12px; }
.mini-stats .stat-value { font-size: 19px; }
.rows > .row { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; padding: 11px 0; border-top: 1px solid var(--border); }
.rows > .row:first-child { border-top: 0; padding-top: 2px; }
.rows > .row:last-child { padding-bottom: 2px; }
.row-col { flex-direction: column; align-items: stretch !important; flex-wrap: nowrap !important; }
.row-main { min-width: 0; flex: 1 1 240px; }
.row-title { overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-dim { opacity: .55; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 22px 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.alert { border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: baseline; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 1.6; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; font-weight: 500; }
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag-info, .tag-proj { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; font-size: 11px; }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--primary); min-width: 0; transition: width .25s ease; }
.details > summary { padding: 13px 16px; cursor: pointer; font-weight: 600; }
.details > .rows { padding: 0 16px 12px; }
.list-links { overflow: hidden; }
.list-link { display: flex; align-items: center; gap: 12px; padding: 15px 16px; color: var(--text); border-top: 1px solid var(--border); }
.list-link:first-child { border-top: 0; }
.list-link span { flex: 1; }
.proj-name { color: var(--text); font-weight: 600; font-size: 16px; }

/* ---------- 按钮与表单 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.btn-primary:hover { color: var(--on-primary); filter: brightness(1.08); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { color: #fff; filter: brightness(1.08); }
.btn-text { border-color: transparent; background: none; color: var(--muted); }
.btn-sm { min-height: 32px; padding: 0 11px; font-size: 13.5px; border-radius: 8px; }
.btn-lg { min-height: 44px; padding: 0 20px; font-size: 16px; }
.btn-block { width: 100%; min-height: 44px; }
.icon-btn { border: 0; background: none; cursor: pointer; width: 36px; height: 36px; border-radius: 8px; color: var(--muted); font-size: 15px; }
.icon-btn:hover { background: var(--surface-2); }
.input { width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-size: 16px; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.input-sm { width: auto; min-height: 34px; padding: 4px 10px; font-size: 14px; }
.input-num { width: 116px; font-variant-numeric: tabular-nums; }
.input-color { width: 64px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13.5px; font-weight: 500; }
.field-inline { flex-direction: row; align-items: center; justify-content: space-between; }
.field-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.req { color: var(--bad); }
.form-error { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 8px 12px; font-size: 13.5px; }
.switch, .check { width: 22px; height: 22px; accent-color: var(--primary); flex: none; margin: 0; }
.check-label { display: flex; align-items: center; gap: 10px; flex: 1 1 200px; cursor: pointer; min-height: 32px; }
.range { flex: 1 1 160px; min-width: 120px; accent-color: var(--primary); height: 28px; }
.target-edit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; padding: 3px; background: var(--surface-2); align-self: flex-start; }
.seg-item { border: 0; background: none; padding: 7px 16px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg-item.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.day-toggles { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; max-width: 560px; }
.day-toggle { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 12.5px; }
.day-toggle b { font-size: 15px; }
.day-toggle.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.save-bar { position: sticky; bottom: 12px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--primary); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .14); z-index: 5; }
.save-bar > span { margin-right: auto; font-weight: 600; }

/* ---------- 表格(手机上每行变卡片) ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: 4px; }

/* ---------- 弹窗 ---------- */
.modal { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); overflow: hidden; }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(10, 14, 20, .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 20px; }
.modal-body { padding: 8px 20px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.modal > .modal-foot { padding: 0 20px 18px; }
.confirm-text { padding: 4px 0 6px; }
.toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: #20242b; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); transition: opacity .25s; text-align: center; }
.toast-err { background: #b3261e; }
.toast.out { opacity: 0; }

/* ---------- 登录 ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px 24px; box-shadow: 0 10px 40px rgba(16, 24, 40, .08); display: flex; flex-direction: column; gap: 14px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin-top: -8px; }

/* ---------- 图表 ---------- */
.chart-wrap { display: flex; flex-direction: column; gap: 6px; }
.chart-holder { position: relative; }
.chart { width: 100%; touch-action: pan-y; }
.chart svg { display: block; }
.c-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.c-axis { stroke: var(--border); stroke-width: 1; }
.c-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-line-main { stroke: var(--primary); }
.c-line-ref { stroke: var(--ref); stroke-width: 1.5; stroke-dasharray: 5 5; }
.c-area { fill: var(--primary); opacity: .1; }
.c-dot, .c-dot-main { fill: var(--primary); stroke: var(--surface); stroke-width: 2; }
.c-dot-ref { fill: var(--ref); }
.c-cross { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart-tip { position: absolute; top: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; font-size: 12.5px; box-shadow: 0 6px 18px rgba(0, 0, 0, .14); pointer-events: none; white-space: nowrap; z-index: 2; }
.chart-tip-title { color: var(--muted); margin-bottom: 2px; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; }
.chart-tip-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--primary); }
.legend-ref { border-top: 2px dashed var(--ref); }
.legend-main-fill { height: 10px; width: 10px; border: 0; border-radius: 2px; background: var(--primary); }
.legend-ref-fill { height: 10px; width: 10px; border: 0; border-radius: 2px; background: var(--track); outline: 1px solid var(--ref); }
.cols { display: flex; align-items: stretch; gap: 8px; height: 190px; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); border-radius: 8px; padding: 4px 2px; }
.col:hover, .col.on { background: var(--surface-2); }
.col-value { font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-bars { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; }
.col-bar { width: min(18px, 38%); border-radius: 4px 4px 0 0; }
.col-target { background: var(--track); outline: 1px solid var(--ref); outline-offset: -1px; }
.col-actual { background: var(--primary); }
.col-label { font-size: 11.5px; color: var(--muted); }

/* ---------- 平板:图标导航栏 ---------- */
@media (max-width: 1023px) {
  :root { --nav-w: 76px; }
  .nav { padding: 12px 6px; align-items: stretch; }
  .brand { justify-content: center; padding: 2px 0 12px; }
  .brand-name, .nav-user { display: none; }
  .nav-link { flex-direction: column; gap: 3px; padding: 9px 2px; font-size: 11.5px; justify-content: center; }
  .nav-foot { justify-content: center; padding: 8px 0 0; }
  .page { padding: 18px 18px 32px; }
  .grid-2, .grid-2-wide { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 手机:底部导航 ---------- */
@media (max-width: 639px) {
  .shell { display: block; height: auto; }
  .main { overflow: visible; padding-bottom: calc(62px + var(--safe-b)); }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex-direction: row; padding: 4px 4px calc(4px + var(--safe-b)); border-right: 0; border-top: 1px solid var(--border); }
  .brand, .nav-foot, .nav-secondary { display: none; }
  .nav-links { flex-direction: row; overflow: visible; }
  .nav-link { flex: 1; padding: 6px 0 4px; font-size: 11px; border-radius: 10px; }
  .nav-link.active { background: none; }
  .nav-more { display: flex; }
  .page { padding: 14px 12px 20px; gap: 12px; }
  h1 { font-size: 19px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-value { font-size: 19px; }
  .card-head { padding: 12px 14px 0; }
  .card-body { padding: 10px 14px 12px; }
  .btn-sm { min-height: 36px; }
  .page-actions .btn-lg { flex: 1; }
  .save-bar { bottom: calc(70px + var(--safe-b)); }
  .modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; max-height: 92dvh; }
  .modal-body { padding-bottom: calc(18px + var(--safe-b)); }
  .modal-foot .btn { flex: 1; min-height: 44px; }
  .toasts { top: auto; bottom: calc(76px + var(--safe-b)); }
  /* 表格 → 卡片 */
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 0; border-top: 1px solid var(--border); }
  .table tr:first-child { border-top: 0; padding-top: 0; }
  .table td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; flex: none; text-align: left; }
  .table td.td-primary { font-size: 15.5px; text-align: left; justify-content: flex-start; align-items: center; gap: 0; flex-wrap: wrap; padding-bottom: 4px; }
  .table td.td-primary::before, .table td.actions::before { content: none; }
  .table td.actions { justify-content: flex-end; padding-top: 6px; }
  .table td:empty { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
