/* ============ 主题变量 ============ */
:root {
  --bg: #eef3f4;
  --bg-grad-1: #e7f2ee;
  --bg-grad-2: #e9eef7;
  --card: #ffffff;
  --card-soft: #f6f9f9;
  --text: #10231f;
  --text-2: #5c6f6b;
  --text-3: #8a9a97;
  --border: #e2eae8;
  --border-strong: #cfdcd9;
  --primary: #10a37f;
  --primary-dark: #0b7f63;
  --primary-soft: #e5f6f1;
  --good: #10a37f;
  --good-soft: #e4f5ef;
  --warn: #d98324;
  --warn-soft: #fdf1e2;
  --bad: #dc4b4b;
  --bad-soft: #fdeaea;
  --low: #3b7dd8;
  --low-soft: #e8f0fc;
  --shadow: 0 1px 2px rgba(16, 35, 31, .04), 0 8px 24px rgba(16, 35, 31, .06);
  --shadow-sm: 0 1px 2px rgba(16, 35, 31, .05);
  --radius: 18px;
  --radius-sm: 12px;
}

html[data-theme="dark"] {
  --bg: #0b1114;
  --bg-grad-1: #0c1618;
  --bg-grad-2: #0d1218;
  --card: #141d21;
  --card-soft: #1a2429;
  --text: #e8f0ee;
  --text-2: #9db0ad;
  --text-3: #74857f;
  --border: #253236;
  --border-strong: #33454a;
  --primary: #2fbf9b;
  --primary-dark: #23a382;
  --primary-soft: #17322b;
  --good: #2fbf9b;
  --good-soft: #16302a;
  --warn: #e3a45c;
  --warn-soft: #34281a;
  --bad: #f0716f;
  --bad-soft: #3a1f20;
  --low: #6aa5ee;
  --low-soft: #1b2a3c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
}

/* ============ 基础 ============ */
* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
               system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 12% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.06rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
b { font-weight: 600; }

.muted { color: var(--text-2); font-size: .86rem; }
.stat-value, .num, .table td, .ring-center strong { font-variant-numeric: tabular-nums; }

/* ============ 顶栏 ============ */
.topbar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 42px; height: 42px;
  border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 600;
  font-size: 1.15rem;
  box-shadow: 0 6px 16px rgba(16, 163, 127, .28);
}

.brand-text { display: flex; flex-direction: column; }
.brand-text p { font-size: .8rem; }

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ 按钮 / 控件 ============ */
.btn {
  font: inherit;
  font-size: .86rem;
  border-radius: 11px;
  border: 1px solid transparent;
  padding: 9px 15px;
  cursor: pointer;
  background: var(--card-soft);
  color: var(--text);
  transition: background .16s ease, border-color .16s ease, transform .12s ease, color .16s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(140deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 6px 16px rgba(16, 163, 127, .22);
}
.btn-primary:hover { border-color: transparent; filter: brightness(1.04); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}
.btn-ghost:hover { color: var(--text); background: var(--card-soft); }
.btn-ghost.danger { color: var(--bad); }
.btn-ghost.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.icon-btn { padding: 9px 11px; }

.input {
  font: inherit;
  font-size: .9rem;
  width: 100%;
  padding: 9px 12px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input::placeholder { color: var(--text-3); }

select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

input[type="date"] { min-height: 40px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: .8rem; color: var(--text-2); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.form-error { color: var(--bad); font-size: .82rem; }

.chip {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  padding: 6px 9px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
}
.chip:hover { border-color: var(--primary); }

.quick-emojis { display: flex; flex-wrap: wrap; gap: 6px; }

.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 2px var(--card);
}
.swatch[aria-checked="true"] { border-color: var(--text); }
.swatch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============ 标签页 ============ */
.tabs {
  max-width: 1080px;
  margin: 0 auto 18px;
  padding: 0 20px;
  display: flex;
  gap: 6px;
}

.tab {
  font: inherit;
  font-size: .92rem;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}
.tab:hover { background: var(--card-soft); color: var(--text); }
.tab.active {
  background: var(--card);
  color: var(--primary-dark);
  font-weight: 600;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
html[data-theme="dark"] .tab.active { color: var(--primary); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============ 布局 ============ */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

.panel { display: flex; flex-direction: column; gap: 18px; }
.panel[hidden] { display: none; }
.panel > * { min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* ============ 今日概览 ============ */
.hero {
  display: flex;
  gap: 26px;
  align-items: center;
  flex-wrap: wrap;
}

.ring-wrap { position: relative; width: 148px; height: 148px; flex: 0 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--border); stroke-width: 10; }
.ring-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset .5s cubic-bezier(.22, .61, .36, 1);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.ring-center strong { font-size: 1.7rem; font-weight: 600; }
.ring-center span { font-size: .74rem; }

.hero-info { flex: 1 1 320px; min-width: 0; }
.hero-info h2 { margin-bottom: 4px; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.stat {
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}
.stat-value { font-size: 1.3rem; font-weight: 600; line-height: 1.25; }
.stat-label { font-size: .74rem; color: var(--text-2); }

/* ============ 习惯列表 ============ */
.habit-form {
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.habit-list { display: flex; flex-direction: column; gap: 10px; }

.habit {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  transition: border-color .18s ease, background .18s ease, opacity .2s ease;
}
.habit:hover { border-color: var(--border-strong); }
.habit.is-done { background: var(--good-soft); border-color: transparent; }

.habit-emoji {
  width: 44px; height: 44px;
  border-radius: 13px;
  display: grid; place-items: center;
  font-size: 1.3rem;
  background: var(--card-soft);
  flex: 0 0 auto;
}
.habit.is-done .habit-emoji { background: var(--card); }

.habit-main { min-width: 0; }
.habit-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.habit-name .streak {
  font-size: .74rem;
  font-weight: 500;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 999px;
  padding: 1px 8px;
}
.habit-meta { font-size: .78rem; color: var(--text-2); }

.habit-week {
  display: flex;
  gap: 4px;
  margin-top: 7px;
}
.wd {
  width: 20px; height: 6px;
  border-radius: 999px;
  background: var(--border);
  transition: background .2s ease;
}
.wd.on { background: var(--hc, var(--primary)); }
.wd.part { background: var(--hc, var(--primary)); opacity: .45; }
.wd.today { box-shadow: 0 0 0 2px var(--primary-soft); }

.habit-actions { display: flex; align-items: center; gap: 8px; }

.counter {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-soft);
  border-radius: 999px;
  padding: 3px;
}
.counter button {
  font: inherit;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}
.counter button:hover { color: var(--primary-dark); }
.counter .count-value {
  min-width: 62px;
  text-align: center;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.check-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px dashed var(--border-strong);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  transition: transform .16s ease, background .18s ease, border-color .18s ease, color .18s ease;
}
.check-btn:hover { transform: scale(1.06); border-color: var(--hc, var(--primary)); }
.check-btn.done {
  border: none;
  background: var(--hc, var(--primary));
  color: #fff;
  box-shadow: 0 6px 14px rgba(16, 163, 127, .3);
}
.check-btn.done:hover { transform: scale(1.06); }

.row-actions { display: flex; flex-direction: column; gap: 4px; }
.row-actions button {
  font: inherit;
  font-size: .72rem;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 1px 2px;
  text-align: right;
}
.row-actions button:hover { color: var(--bad); }
.row-actions button.edit:hover { color: var(--primary-dark); }

.empty { text-align: center; padding: 26px 0; }

/* ============ 热力图 ============ */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 18px);
  grid-auto-columns: 18px;
  justify-content: space-between;
  gap: 4px;
  min-width: 620px;
}
.hm-cell {
  width: 18px; height: 18px;
  border-radius: 5px;
  background: var(--border);
  display: block;
}
.hm-cell.lv0 { background: var(--border); }
.hm-cell.lv1 { background: color-mix(in srgb, var(--primary) 28%, var(--border)); }
.hm-cell.lv2 { background: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.hm-cell.lv3 { background: color-mix(in srgb, var(--primary) 74%, var(--border)); }
.hm-cell.lv4 { background: var(--primary); }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 12px;
  font-size: .74rem;
}
.heatmap-legend .hm-cell { width: 13px; height: 13px; border-radius: 4px; }

/* ============ 月度统计 ============ */
.month-stats { display: flex; flex-direction: column; gap: 14px; }
.month-stat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: .88rem;
  margin-bottom: 6px;
}
.bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .5s ease; }

/* ============ 指标结果 ============ */
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.summary {
  background: var(--card-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.summary .label { font-size: .76rem; color: var(--text-2); }
.summary .value { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.summary .sub { font-size: .74rem; color: var(--text-3); }

.indicator-list { display: flex; flex-direction: column; gap: 18px; }

.indicator {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.indicator:first-child { border-top: none; padding-top: 0; }
.indicator:only-child { border-top: none; padding-top: 0; }

.indicator-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.indicator-title { font-weight: 600; font-size: .95rem; display: flex; align-items: center; gap: 8px; }
.indicator-value { font-variant-numeric: tabular-nums; }
.indicator-value strong { font-size: 1.3rem; font-weight: 600; }
.indicator-value span { color: var(--text-2); font-size: .82rem; }

.badge {
  font-size: .74rem;
  font-weight: 500;
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}
.badge.good { color: var(--good); background: var(--good-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.bad { color: var(--bad); background: var(--bad-soft); }
.badge.low { color: var(--low); background: var(--low-soft); }

.range { position: relative; }
.range-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}
.range-zone { height: 100%; }
.range-zone.good { background: var(--good); opacity: .5; }
.range-zone.warn { background: var(--warn); opacity: .42; }
.range-zone.bad { background: var(--bad); opacity: .4; }
.range-zone.low { background: var(--low); opacity: .38; }

.range-marker {
  position: absolute;
  top: -5px;
  width: 3px;
  height: 24px;
  border-radius: 999px;
  background: var(--text);
  box-shadow: 0 0 0 2px var(--card);
}

.range-ticks {
  position: relative;
  height: 18px;
  margin-top: 4px;
  font-size: .72rem;
  color: var(--text-3);
}
.range-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

.range-note { font-size: .8rem; color: var(--text-2); margin-top: 2px; }

/* ============ 建议 ============ */
.advice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.advice-group h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: .95rem;
}

.advice-list { display: flex; flex-direction: column; gap: 10px; }
.advice {
  border-radius: var(--radius-sm);
  background: var(--card-soft);
  padding: 12px 14px;
  border-left: 3px solid var(--primary);
}
.advice.p2 { border-left-color: var(--warn); }
.advice.p3 { border-left-color: var(--bad); }
.advice-title { font-weight: 600; font-size: .88rem; margin-bottom: 3px; }
.advice-text { font-size: .84rem; color: var(--text-2); }

/* ============ 图表 ============ */
.segmented {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--card-soft);
  padding: 3px;
  border-radius: 999px;
}
.segmented button {
  font: inherit;
  font-size: .8rem;
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.chart-wrap { width: 100%; overflow: hidden; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-3); font-size: 11px; }
.chart .axis-line { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 5; }
.chart .series { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--primary); opacity: .1; }
.chart .dot { fill: var(--card); stroke: var(--primary); stroke-width: 2.5; }
.chart .value-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart .band { fill: var(--primary); opacity: .08; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.table th, .table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th { color: var(--text-2); font-weight: 500; font-size: .78rem; }
.table tbody tr:hover { background: var(--card-soft); }
.table .del {
  font: inherit;
  font-size: .78rem;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 0;
}
.table .del:hover { color: var(--bad); }

.disclaimer {
  padding: 0 4px;
  font-size: .78rem;
  line-height: 1.7;
}

/* ============ 提示条 ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--card);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
  max-width: 90vw;
  text-align: center;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ 响应式 ============ */
@media (max-width: 720px) {
  body { font-size: 14.5px; }
  .topbar { padding: 16px 14px 10px; }
  .tabs { padding: 0 14px; }
  main { padding: 0 14px 56px; }
  .card { padding: 16px; border-radius: 16px; }
  .hero { gap: 18px; }
  .ring-wrap { width: 120px; height: 120px; }
  .ring-center strong { font-size: 1.4rem; }
  .habit {
    grid-template-columns: auto 1fr;
    grid-template-areas: "emoji main" ". actions";
    row-gap: 12px;
  }
  .habit-emoji { grid-area: emoji; }
  .habit-main { grid-area: main; }
  .habit-actions {
    grid-area: actions;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .row-actions { flex-direction: row; gap: 12px; }
  .check-btn { width: 40px; height: 40px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 420px) {
  .brand-text h1 { font-size: .98rem; }
  .topbar-actions .btn { padding: 8px 12px; font-size: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================
   云端账号版新增：登录页 / 管理后台 / 权限提示 / 弹窗
   ============================================================ */

.btn-block { width: 100%; justify-content: center; text-align: center; }

.save-status { font-size: .78rem; color: var(--text-3); align-self: center; }
.save-status.ok { color: var(--good); }
.save-status.busy { color: var(--text-3); }
.save-status.error { color: var(--bad); }

.notice {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: .85rem;
  margin-bottom: 16px;
}

.readonly-mark {
  color: var(--text-3);
  font-size: 1.1rem;
  justify-content: flex-end;
  min-width: 32px;
}
body.role-viewer .write-only { display: none !important; }

/* ---- 拦截页 ---- */
.blocked-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}
.blocked-card {
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.blocked-card { max-width: 480px; }
.blocked-card a { color: var(--primary-dark); }
.blocked-card code {
  font-size: .82rem;
  background: var(--card-soft);
  padding: 1px 5px;
  border-radius: 5px;
}
html[data-theme="dark"] .blocked-card a { color: var(--primary); }

/* ---- 弹窗 ---- */
.dialog {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 22px;
  width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.dialog-wide { width: min(880px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog h2 { margin-bottom: 6px; }
.dialog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 16px 0 4px;
}
.dialog-full { grid-column: 1 / -1; }
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 18px;
}
.dialog > .muted, .dialog form > .muted { margin-top: 10px; display: block; font-size: .78rem; }

.account-info { margin: 14px 0 4px; display: flex; flex-direction: column; gap: 9px; }
.account-line { display: flex; justify-content: space-between; gap: 12px; font-size: .9rem; }

.code-box {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  background: var(--card-soft);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 14px 0;
  flex-wrap: wrap;
}
.code-text {
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: .16em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--primary-dark);
}
html[data-theme="dark"] .code-text { color: var(--primary); }

/* ---- 登录 / 初始化页 ---- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrap { width: 100%; max-width: 460px; padding: 24px 18px 40px; margin: 0 auto; }
.auth-card { padding: 26px 24px; }
.auth-brand { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 20px; }
.auth-brand h1 { font-size: 1.15rem; margin-bottom: 4px; }
.auth-brand p { font-size: .82rem; }
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--card-soft);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  font: inherit;
  font-size: .88rem;
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.auth-tab.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-hint { font-size: .78rem; }
.auth-foot { text-align: center; margin-top: 18px; font-size: .78rem; }
.code-input { letter-spacing: .18em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-transform: uppercase; }
.invite-info {
  font-size: .84rem;
  background: var(--primary-soft);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  line-height: 1.7;
}
#inviteStage { display: flex; flex-direction: column; gap: 14px; }

/* ---- 管理后台 ---- */
.admin-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.admin-main > * { min-width: 0; }
.admin-stats { margin-bottom: 0; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.admin-table { min-width: 860px; }
.cell-name { font-weight: 600; }
.cell-sub { font-size: .74rem; }
.cell-actions { display: flex; flex-wrap: wrap; gap: 4px 10px; }

.link {
  font: inherit;
  font-size: .8rem;
  border: none;
  background: none;
  color: var(--primary-dark);
  cursor: pointer;
  padding: 0;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }
html[data-theme="dark"] .link { color: var(--primary); }

.badge.role.role-admin { color: var(--primary-dark); background: var(--primary-soft); }
.badge.role.role-editor { color: var(--low); background: var(--low-soft); }
.badge.role.role-viewer { color: var(--text-2); background: var(--card-soft); }
html[data-theme="dark"] .badge.role.role-admin { color: var(--primary); }

.detail-body { margin: 14px 0 4px; }
.detail-body h3 { font-size: .92rem; margin-bottom: 10px; }
.detail-list { display: flex; flex-direction: column; gap: 8px; font-size: .88rem; }
.detail-list li { display: flex; align-items: center; gap: 8px; }
.detail-list .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.detail-list .ok { color: var(--good); margin-left: auto; }
.detail-list .muted { margin-left: auto; }

@media (max-width: 720px) {
  .admin-main { padding: 0 14px 56px; }
  .auth-card { padding: 20px 16px; }
  .dialog { padding: 18px; }
  .dialog-actions { justify-content: stretch; }
  .dialog-actions .btn { flex: 1 1 auto; }
}
