/* 布局：左侧深色导航 + 右侧工作区；卡片只用于分隔独立操作区。手机宽度时导航变为顶部横向滚动。 */
:root {
  --bg: #f2f4f4;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #16201f;
  --muted: #5b6a67;
  --line: #dbe2e0;
  --accent: #12695d;
  --accent-ink: #ffffff;
  --accent-soft: #dff0ec;
  --side-bg: #13201e;
  --side-text: #b7c7c3;
  --side-strong: #f2f7f6;
  --side-hover: #1d2e2b;
  --ok: #2b7a4b;
  --warn: #9a5b00;
  --err: #b42318;
  --focus: #12695d;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1413;
    --surface: #161f1e;
    --surface-2: #1c2826;
    --text: #e4ecea;
    --muted: #93a39f;
    --line: #2a3735;
    --accent: #4db3a2;
    --accent-ink: #062019;
    --accent-soft: #173431;
    --side-bg: #0a0f0e;
    --side-text: #9fb0ac;
    --side-strong: #eef5f3;
    --side-hover: #152120;
    --ok: #6cc28f;
    --warn: #e0ac4f;
    --err: #f08679;
    --focus: #4db3a2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1413;
  --surface: #161f1e;
  --surface-2: #1c2826;
  --text: #e4ecea;
  --muted: #93a39f;
  --line: #2a3735;
  --accent: #4db3a2;
  --accent-ink: #062019;
  --accent-soft: #173431;
  --side-bg: #0a0f0e;
  --side-text: #9fb0ac;
  --side-strong: #eef5f3;
  --side-hover: #152120;
  --ok: #6cc28f;
  --warn: #e0ac4f;
  --err: #f08679;
  --focus: #4db3a2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.6 var(--font); }
h1, h2, h3 { text-wrap: balance; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- 框架 ---- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100%; }
.sidebar {
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; gap: 20px;
  padding: 20px 12px; position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #ffffff 0 18%, #d9e7e4 32%, #8fb3ab 70%, #4d7d73 100%);
}
.brand-name { color: var(--side-strong); font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11px; letter-spacing: .08em; padding: 12px 10px 4px; opacity: .75; }
.tab {
  text-align: left; border: 0; background: none; color: var(--side-text); cursor: pointer;
  padding: 8px 10px; border-radius: 8px; font: inherit;
}
.tab:hover { background: var(--side-hover); color: var(--side-strong); }
.tab.active { background: var(--side-hover); color: var(--side-strong); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side-usage { margin-top: auto; }
#usage { display: flex; flex-direction: column; gap: 10px; padding: 0 10px; }
.meter-label { display: flex; justify-content: space-between; font-size: 12px; font-variant-numeric: tabular-nums; }
.meter { height: 4px; border-radius: 2px; background: var(--side-hover); overflow: hidden; margin-top: 4px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.full > span { background: var(--warn); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding-block: 16px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar h1 { font-size: 18px; margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--ok); }
.chip.bad { color: var(--warn); }
.content {
  padding-block: 20px 48px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
  max-width: 1240px; width: 100%;
}
.panel { display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }

/* ---- 卡片与表单 ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card > h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
label { display: block; color: var(--muted); font-size: 13px; margin: 12px 0 4px; }
label.check, label.switch { color: var(--text); }
input, textarea, select {
  display: block; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input[type=file] { padding: 6px; background: var(--surface-2); }
textarea { resize: vertical; }
input[type=checkbox] { display: inline-block; width: auto; margin: 0 6px 0 0; vertical-align: -2px; accent-color: var(--accent); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.row-inline { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-inline input { flex: 1; min-width: 200px; width: auto; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.settings-actions .actions { margin-top: 0; }
button {
  cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 7px 14px; font: inherit;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.small { font-size: 12px; padding: 2px 10px; font-weight: 400; }
button.danger { color: var(--err); border-color: var(--err); }
button:disabled { opacity: .55; cursor: progress; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.hint.block { display: block; }
.error { color: var(--err); font-size: 12px; }

/* ---- 表格与状态 ---- */
.table-wrap { overflow-x: auto; }
.table-wrap table { min-width: 520px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; }
th, td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.status { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.status.succeeded { color: var(--ok); }
.status.running, .status.pending, .status.queued { color: var(--warn); }
.status.failed { color: var(--err); }

/* ---- 结果展示 ---- */
.variant { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 12px; white-space: pre-wrap; }
.variant h3 { margin: 0 0 6px; font-size: 15px; }
.tags { color: var(--accent); font-size: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 12px; }
.gallery figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.gallery img, .gallery video { width: 100%; display: block; aspect-ratio: 3 / 4; object-fit: cover; }
.gallery figcaption { padding: 8px; font-size: 12px; }
pre.json {
  background: var(--surface-2); border-radius: 8px; padding: 10px; overflow: auto; max-height: 320px;
  font-size: 12px; white-space: pre-wrap; margin: 8px 0 0;
}
.shot-edit { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.shot-edit label { margin-top: 6px; }
video.final { max-width: 320px; width: 100%; margin-top: 12px; border-radius: 8px; }
.templates { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.templates select, .templates input { width: auto; padding: 3px 8px; font-size: 12px; }

/* ---- 产物库 ---- */
.asset { border-top: 1px solid var(--line); padding: 14px 0; display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 14px; }
.asset:first-child { border-top: 0; }
.asset .preview img, .asset .preview video { width: 100%; max-height: 240px; object-fit: contain; border-radius: 6px; background: var(--surface-2); display: block; }
.asset .text { white-space: pre-wrap; margin-top: 6px; }
.asset .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.asset .actions input { width: auto; flex: 1; min-width: 140px; }
#as-list { margin-top: 8px; }

/* ---- 后台设置 ---- */
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  flex: none; width: 40px; height: 22px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.limit { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 4px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.limit:first-child { border-top: 0; }
.limit label { margin: 0; color: var(--text); font-size: 14px; }
.limit .unit-input span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.limit .sub { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.limit .bar { flex: 1; min-width: 80px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.limit .bar > span { display: block; height: 100%; background: var(--accent); }
.limit .bar.full > span { background: var(--warn); }
.badge { font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }

/* ---- 登录与账号 ---- */
body.is-staff .admin-only { display: none !important; }
.login-view {
  min-height: 100%; display: grid; place-items: center; background: var(--side-bg);
  padding-block: 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: 12px; padding: 28px; }
.login-card .brand { padding: 0; margin-bottom: 8px; }
.login-card .brand-name { color: var(--text); }
.login-card .brand-sub { color: var(--muted); }
.login-card .actions button { width: 100%; }
.user-box { border-top: 1px solid var(--side-hover); padding: 12px 10px 0; display: flex; flex-direction: column; gap: 6px; }
.me-name { color: var(--side-strong); font-weight: 600; }
.user-actions { display: flex; gap: 14px; }
button.link { background: none; border: 0; padding: 0; color: var(--side-text); text-decoration: underline; font-size: 12px; }
button.link:hover { color: var(--side-strong); }
dialog { width: min(380px, calc(100% - 32px)); padding: 20px; }
dialog h2 { font-size: 15px; margin: 0 0 4px; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
.unit-input { display: flex; align-items: center; gap: 6px; }
.unit-input input { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.quota-chips { display: flex; flex-wrap: wrap; gap: 4px; max-width: 380px; }
.limit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
#us-editor h3 { font-size: 13px; margin: 18px 0 0; }

/* ---- 操作记录 ---- */
.activity-list { display: flex; flex-direction: column; gap: 12px; }
.activity-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.chip.feature { background: var(--accent-soft); color: var(--accent); }
.activity-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px 24px; }
.activity-body section { min-width: 0; }
.activity-body h3 { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .04em; margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 4px 10px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.thumbs img { width: 72px; height: 96px; object-fit: cover; border-radius: 6px; background: var(--surface-2); display: block; }
.thumbs.large img { width: 120px; height: 160px; }
.thumbs figure { margin: 0; width: 96px; font-size: 11px; color: var(--muted); }
.thumbs figure img { width: 96px; height: 120px; }
.activity video { max-width: 220px; width: 100%; border-radius: 8px; margin-top: 6px; }
ul.plain, ol.plain { margin: 4px 0 0; padding-left: 18px; }
.variant-mini { border-top: 1px solid var(--line); padding: 6px 0; }
.variant-mini:first-child { border-top: 0; }
.variant-mini summary { cursor: pointer; font-weight: 500; }
.variant-mini .text { white-space: pre-wrap; margin-top: 4px; color: var(--muted); }

/* ---- 提示 ---- */
.toasts {
  position: fixed; z-index: 20; display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100% - 32px);
}
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 16px rgb(0 0 0 / .18); }
.toast.error { background: var(--err); color: #fff; }
.demo-banner { background: var(--accent-soft); color: var(--accent); font-size: 12px; padding: 6px 12px; border-radius: 8px; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .switch-track, .switch-track::after { transition: none; }
}

/* ---- 手机 ---- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: column; gap: 10px;
    padding-block: 14px 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .brand { padding: 0; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-group { display: none; }
  .tab { white-space: nowrap; }
  .tab.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .side-usage { display: none; }
  .topbar, .content { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .grid { grid-template-columns: 1fr; }
  .asset { grid-template-columns: 1fr; }
  .limit { grid-template-columns: minmax(0, 1fr) 110px; }
}
