/* 拾光更新后台 — 浅色专业风，克制的暖色强调 */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #1b1f26;
  --text-2: #5a6472;
  --text-3: #8b95a5;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --green: #127a45;
  --green-soft: #e8f6ee;
  --red: #c02626;
  --red-soft: #fdeceb;
  --blue: #1a56b0;
  --blue-soft: #eaf1fd;
  --amber: #96650a;
  --amber-soft: #fdf5e3;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
}

* { box-sizing: border-box; }

/* The class rules below set `display`, which outranks the UA's `[hidden]` rule, so
   hiding must be enforced explicitly or hidden panes still occupy layout space. */
[hidden] { display: none !important; }

/* A grid/flex child defaults to min-width:auto, which lets wide tables push the whole
   page sideways instead of scrolling inside their own box.
   `clip` (not `hidden`) matters: `overflow-x: hidden` turns <body> into the scrolling
   container, so window.scrollY stays 0, scroll restoration breaks, and the mobile URL
   bar never collapses. `clip` still trims the overflow without creating a scroller. */
html, body { max-width: 100%; overflow-x: hidden; }
@supports (overflow-x: clip) {
  html, body { overflow-x: clip; }
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-2); }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ------------------------------------------------------------------ login */

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #fff2ea 0%, transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 28px 26px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-brand { text-align: center; margin-bottom: 6px; }
.login-brand h2 { margin: 12px 0 2px; font-size: 19px; letter-spacing: .2px; }
.login-brand p { margin: 0; font-size: 13px; }

/* ---------------------------------------------------------------- shell */

.app-shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }
.brand-mark { display: grid; place-items: center; border-radius: 9px; overflow: hidden; }
.brand-mark svg { display: block; border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .3px; }
.brand-text span { font-size: 11.5px; color: var(--text-3); letter-spacing: .6px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: #b8450a; font-weight: 600; }
.nav-ico { font-size: 13px; opacity: .8; width: 16px; text-align: center; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
}

.link-btn {
  border: 0; background: none; color: var(--text-2);
  font-family: inherit; font-size: 12.5px; cursor: pointer; padding: 2px 4px;
  border-radius: 4px;
}
.link-btn:hover { color: var(--red); background: var(--red-soft); }

.main { min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.view { padding: 22px 26px 60px; max-width: 1180px; width: 100%; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #d24e08; border-color: #d24e08; }

.btn-danger { color: var(--red); border-color: #f0c4c0; background: #fff; }
.btn-danger:hover { background: var(--red-soft); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 10px; }

/* ----------------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--text-2); font-weight: 550; }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 89, 12, .12);
}
textarea { resize: vertical; min-height: 74px; line-height: 1.6; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.form-error { margin: 0; min-height: 18px; font-size: 12.5px; color: var(--red); }

.checkbox-row { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; }
.checkbox-row input { margin-top: 2px; width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.checkbox-row .hint { color: var(--text-3); font-size: 12px; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.card-body { padding: 18px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.stat-value { font-size: 25px; font-weight: 660; letter-spacing: -.4px; line-height: 1.15; }
.stat-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ----------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; }
th {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.7;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-live { background: var(--green-soft); color: var(--green); border-color: #bfe3cf; }
.badge-draft { background: var(--surface-2); color: var(--text-2); border-color: var(--border-strong); }
.badge-archived { background: var(--blue-soft); color: var(--blue); border-color: #c6d8f5; }
.badge-rolled { background: var(--red-soft); color: var(--red); border-color: #f2c9c5; }
.badge-force { background: var(--amber-soft); color: var(--amber); border-color: #ecd9ab; }

/* ----------------------------------------------------------------- chart */

.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.chart-bar {
  width: 100%; max-width: 34px; border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #ff8a4c, #e8590c);
  min-height: 2px; transition: height .3s ease;
  position: relative;
}
.chart-bar.is-zero { background: var(--border); }
.chart-x { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }
.chart-bar:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: #1b1f26; color: #fff; font-size: 11px; padding: 3px 7px;
  border-radius: 5px; white-space: nowrap; margin-bottom: 4px; z-index: 5;
}

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ----------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .42);
  display: grid; place-items: center; padding: 20px; z-index: 100;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: var(--surface); border-radius: 13px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .14s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99) } to { opacity: 1; transform: none } }

.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-2); }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ----------------------------------------------------------------- misc */

.empty { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 13px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1b1f26; color: #fff; padding: 9px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow-lg); z-index: 200;
  animation: pop .16s ease;
}
.toast.is-error { background: #a11d1d; }

.progress {
  height: 6px; background: var(--border); border-radius: 3px; overflow: hidden;
}
.progress-bar { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.code-block {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; overflow-x: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px;
  line-height: 1.65; white-space: pre; color: var(--text);
  position: relative;
}
.copy-btn { position: absolute; top: 7px; right: 7px; font-size: 11.5px; padding: 2px 8px; }

.kv { display: grid; grid-template-columns: 118px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); font-size: 12.5px; }
.kv dd { margin: 0; word-break: break-all; }

.hstack { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ================================================================ mobile */

/* Phones: the sidebar becomes a fixed bottom tab bar, the standard mobile pattern.
   A bottom bar keeps every destination one tap away and never collides with content. */
@media (max-width: 820px) {
  /* Desktop caps the shell at 100vh and scrolls .main internally. On phones that
     traps scrolling inside <body> (window.scrollY stays 0, the URL bar never
     collapses). Let the document itself scroll instead. */
  html, body { height: auto; min-height: 100%; }

  .app-shell {
    grid-template-columns: 1fr;
    display: block;
    min-height: 100dvh;
  }

  /* The brand mark moves into the topbar action area on phones. */
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    /* Must reset the desktop height:100vh, otherwise the bar covers the whole page. */
    height: auto;
    top: auto;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding: 0 0 env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    border-right: 0;
    background: rgba(255, 255, 255, .97);
    backdrop-filter: blur(10px);
  }

  .brand, .sidebar-foot { display: none; }

  .nav {
    flex: 1;
    flex-direction: row;
    gap: 0;
    overflow: visible;
    padding: 0;
  }

  .nav-item {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 8px 2px 7px;
    font-size: 11px;
    line-height: 1.25;
    border-radius: 0;
    text-align: center;
    /* A fixed height keeps all four tabs on one baseline even if a label wraps. */
    height: 53px;
    min-height: 53px;
    white-space: nowrap;
    overflow: hidden;
  }
  .nav-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .nav-item.is-active { background: transparent; color: var(--accent); }
  .nav-ico { font-size: 16px; width: auto; }
  /* A short bar under the active tab reads as "selected" without a heavy fill. */
  .nav-item.is-active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 26px;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--accent);
  }
  .nav-item { position: relative; }

  .main {
    height: auto;
    overflow-y: visible;
    /* Clear the fixed tab bar so the last card is never hidden behind it. */
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
    background: rgba(255, 255, 255, .95);
    backdrop-filter: blur(8px);
  }
  .topbar h1 { font-size: 16.5px; }
  .topbar-actions { flex: 1; justify-content: flex-end; gap: 6px; }
  .topbar-actions .btn, .topbar-actions select { min-height: 34px; }

  .view { padding: 14px 14px 20px; max-width: 100%; }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }
  .stat { padding: 12px 13px; }
  .stat-value { font-size: 21px; }
  .stat-label { font-size: 12px; margin-bottom: 4px; }

  .card + .card { margin-top: 12px; }
  .card-head { padding: 12px 14px; flex-wrap: wrap; }
  .card-head h2 { font-size: 13.5px; }
  .card-body { padding: 14px; }

  .grid-2 { grid-template-columns: 1fr; gap: 10px; }

  /* ---- Tables reflow into stacked cards instead of overflowing.
     Each cell carries its column name in data-label set by app.js. */
  .table-wrap { overflow-x: visible; }

  table, thead, tbody, tr, th, td { display: block; }

  thead { display: none; }

  tbody tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }
  tbody tr:last-child { border-bottom: 0; }
  /* Hover highlighting is meaningless without a pointer. */
  tbody tr:hover { background: transparent; }

  td {
    border: 0;
    padding: 0;
    text-align: left !important;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /* Label above value, so a wide cell never squeezes its neighbour. */
  td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--text-3);
    margin-bottom: 1px;
    font-weight: 500;
  }

  /* The action cell spans the full row and holds the buttons in a wrap. */
  td[data-label="操作"] { grid-column: 1 / -1; }
  td[data-label="操作"]::before { margin-bottom: 6px; }
  td[data-label="操作"] > div { flex-wrap: wrap; gap: 6px; }

  td[data-label="操作"] .btn { flex: 1 1 auto; min-height: 34px; }

  .btn { min-height: 34px; }
  .btn-sm { padding: 6px 11px; font-size: 12.5px; }

  /* Charts need fewer, sparser labels on a phone. */
  .chart { height: 120px; }
  .chart-x { font-size: 9.5px; }
  /* Show every other date only, since 14 labels cannot fit. */
  .chart-col:nth-child(even) .chart-x { visibility: hidden; }

  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; font-weight: 600; color: var(--text); }
  .kv dd { margin-bottom: 2px; }

  /* A long endpoint URL scrolls horizontally on desktop, but on a phone that hides
     most of it behind a scroll gesture nobody performs. Wrap it instead. */
  .code-block {
    font-size: 11.5px; padding: 10px;
    white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: visible;
  }
  .copy-btn { position: static; display: block; margin: 0 0 8px auto; }

  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
    animation: slideUp .18s ease;
  }
  @keyframes slideUp { from { transform: translateY(18px); opacity: .6 } to { transform: none; opacity: 1 } }

  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    flex-direction: column-reverse;
  }
  .modal-foot .btn { width: 100%; min-height: 42px; }

  .login-card { padding: 26px 20px 22px; }
  .toast { left: 12px; right: 12px; transform: none; text-align: center; bottom: 16px; }
}

/* Narrow phones: one stat per row keeps the numbers legible. */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  tbody tr { grid-template-columns: 1fr; }
  .nav-item { padding: 7px 9px; font-size: 12.5px; }
}

/* Touch devices: relaxed tap targets, no sticky hover states. */
@media (hover: none) {
  .nav-item:hover, .btn:hover, tbody tr:hover { background: transparent; }
  .nav-item.is-active:hover { background: var(--accent-soft); }
  input[type=text], input[type=password], input[type=number], textarea, select {
    /* 16px avoids the iOS Safari auto-zoom on focus. */
    font-size: 16px;
    padding: 10px 11px;
  }
}
