/* ---------- tokens ---------- */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --fg: #0a0a0a;
  --fg-2: #2e2e2e;
  --muted: #6e6e6e;
  --faint: #a1a1a1;
  --line: #ececec;
  --line-strong: #d6d6d6;
  --soft: #f7f7f7;
  --hover: #f2f2f2;
  --inv: #0a0a0a;
  --on-inv: #ffffff;
  --radius: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0a0a; --surface: #0d0d0d; --fg: #f4f4f4; --fg-2: #d9d9d9; --muted: #8c8c8c; --faint: #595959;
    --line: #1e1e1e; --line-strong: #2f2f2f; --soft: #131313; --hover: #171717; --inv: #f4f4f4; --on-inv: #0a0a0a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0a0a; --surface: #0d0d0d; --fg: #f4f4f4; --fg-2: #d9d9d9; --muted: #8c8c8c; --faint: #595959;
  --line: #1e1e1e; --line-strong: #2f2f2f; --soft: #131313; --hover: #171717; --inv: #f4f4f4; --on-inv: #0a0a0a;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.mono { word-break: break-all; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.i { flex: none; display: block; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 18px 12px; border-right: 1px solid var(--line); background: var(--bg);
}
.brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px;
  text-decoration: none; font-weight: 700; font-size: 13px; letter-spacing: .16em; text-transform: uppercase;
}
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--fg); flex: none; position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px 6px 6px 11px; background: var(--bg); border-radius: 1.5px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  padding: 14px 10px 6px; font-size: 10.5px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--faint);
}
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font: 500 13.5px var(--font);
  background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
  transition: background .12s, color .12s;
}
.nav a:hover, .nav-btn:hover { color: var(--fg); background: var(--hover); }
.nav a.active { color: var(--on-inv); background: var(--inv); }
.nav .count {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
  background: var(--inv); color: var(--on-inv);
}
.nav a.active .count { background: var(--on-inv); color: var(--inv); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.side-foot form { margin: 0; }

.main { padding: 36px 44px 80px; width: 100%; max-width: 1240px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; line-height: 1.15; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 6px; }
.eyebrow { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.eyebrow a { text-decoration: none; }
.eyebrow a:hover { color: var(--fg); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.cols-2 { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.cols-even { grid-template-columns: 1fr 1fr; }
.stack { display: grid; gap: 16px; align-content: start; }

/* ---------- cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line); min-height: 52px;
}
.card-head h2 { font-size: 13.5px; font-weight: 600; letter-spacing: 0; }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-bottom: 16px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.stat { background: var(--surface); padding: 18px 20px 20px; }
.stat .k { font-size: 11px; font-weight: 500; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-size: 28px; font-weight: 650; letter-spacing: -.025em; margin-top: 8px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .s { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.notice {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; margin-bottom: 16px;
  border: 1px solid var(--fg); border-radius: var(--radius); text-decoration: none; font-weight: 500;
}
.notice .i:last-child { margin-left: auto; }
.notice:hover { background: var(--inv); color: var(--on-inv); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--soft); }
.table .actions { justify-content: flex-end; flex-wrap: nowrap; gap: 4px; }
.table form { margin: 0; }
.cell-main { font-weight: 550; text-decoration: none; }
a.cell-main:hover { text-decoration: underline; text-underline-offset: 3px; }
.cell-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.tree-indent { display: inline-block; color: var(--faint); font-family: var(--mono); }
.with-thumb { display: flex; align-items: center; gap: 12px; }

.thumb {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex: none;
  border: 1px solid var(--line); background: var(--soft); display: grid; place-items: center; color: var(--faint);
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 7px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap; letter-spacing: 0;
  border: 1px solid var(--line-strong); color: var(--fg-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.solid { background: var(--inv); border-color: var(--inv); color: var(--on-inv); }
.badge.warn { border-color: var(--fg); color: var(--fg); font-weight: 600; }
.badge.warn::before { animation: pulse 1.6s ease-in-out infinite; }
.badge.muted { color: var(--faint); border-style: dashed; }
.badge.muted::before { background: transparent; border: 1px solid currentColor; }
.badge.plain::before { display: none; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--inv); background: var(--inv); color: var(--on-inv);
  font: 500 13px/1 var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: opacity .12s, background .12s, color .12s, border-color .12s;
}
.btn:hover { opacity: .85; }
.btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--hover); opacity: 1; }
.btn.danger { background: transparent; color: var(--fg); border-color: var(--line-strong); }
.btn.danger:hover { background: var(--inv); color: var(--on-inv); border-color: var(--inv); opacity: 1; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { width: 30px; padding: 0; }
.btn.block { width: 100%; height: 42px; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--fg); background: var(--hover); opacity: 1; }

/* ---------- forms ---------- */
.form { display: grid; gap: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.span-2 { grid-column: 1 / -1; }
.field { display: grid; gap: 7px; align-content: start; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 550; color: var(--fg-2); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.hint code { font-size: 11.5px; padding: 1px 5px; border-radius: 4px; background: var(--soft); border: 1px solid var(--line); }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: 14px var(--font); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 112px; padding: 10px 12px; line-height: 1.55; resize: vertical; }
textarea.mono { font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { border-color: var(--fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 9%, transparent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
select { appearance: none; padding-right: 34px; cursor: pointer; }
.select { position: relative; }
.select::after {
  content: ""; position: absolute; right: 14px; top: 50%; width: 6px; height: 6px; pointer-events: none;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: translateY(-75%) rotate(45deg);
}
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-prefix input { padding-left: 26px; font-variant-numeric: tabular-nums; }

.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; user-select: none; }
.switch input {
  appearance: none; margin: 1px 0 0; width: 36px; height: 20px; border-radius: 999px; flex: none; cursor: pointer;
  background: var(--line-strong); position: relative; transition: background .18s;
}
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--bg); transition: transform .18s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked { background: var(--inv); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.switch b { display: block; font-weight: 550; font-size: 13.5px; }
.switch small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice {
  position: relative; display: block; padding: 14px 14px 14px 40px; border: 1px solid var(--line-strong);
  border-radius: 10px; cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.choice:hover { border-color: var(--muted); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice::before {
  content: ""; position: absolute; left: 14px; top: 16px; width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); transition: border .12s;
}
.choice:has(input:checked) { border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); }
.choice:has(input:checked)::before { border: 4.5px solid var(--fg); }
.choice:has(input:focus-visible) { outline: 2px solid var(--fg); outline-offset: 2px; }
.choice b { display: block; font-size: 13.5px; font-weight: 600; }
.choice span { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }

input[type=file] { font: 13px var(--font); color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button {
  font: 500 12.5px var(--font); height: 32px; padding: 0 12px; margin-right: 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg);
}
input[type=file]::file-selector-button:hover { background: var(--hover); }

.media { display: grid; gap: 12px; }
.preview {
  width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; border: 1px dashed var(--line-strong);
  background: var(--soft); display: grid; place-items: center; overflow: hidden; color: var(--faint);
}
.preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--soft); font-size: 13px;
}

.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 16px;
  border: 1px solid var(--fg); border-radius: 10px; font-weight: 500;
}
.alert .i { margin-top: 1px; }
.info {
  padding: 12px 14px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line);
  color: var(--fg-2); font-size: 13px; line-height: 1.5;
}

.savebar {
  position: sticky; bottom: 0; z-index: 5; margin-top: 16px; padding: 14px 0;
  display: flex; gap: 8px; align-items: center; background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ---------- settings sections ---------- */
.section { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 32px; padding: 28px 0; border-top: 1px solid var(--line); }
.section:first-of-type { border-top: 0; padding-top: 4px; }
.section h2 { font-size: 15px; }
.section p { color: var(--muted); font-size: 13px; margin-top: 6px; line-height: 1.5; }

/* ---------- toolbar / tabs / pager ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar form { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; margin: 0; }
.toolbar .search { flex: 1 1 240px; max-width: 360px; }
.toolbar .select { flex: 0 1 260px; }
.tabs { display: flex; gap: 2px; box-shadow: inset 0 -1px 0 var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: flex; align-items: center; gap: 7px; padding: 10px 12px; white-space: nowrap;
  color: var(--muted); text-decoration: none; border-bottom: 1.5px solid transparent; font-weight: 500;
}
.tabs a:hover { color: var(--fg); }
.tabs a.active { color: var(--fg); border-color: var(--fg); }
.tabs .n { font-size: 11px; font-weight: 600; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; display: grid; place-items: center; background: var(--inv); color: var(--on-inv); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }

.empty { padding: 56px 24px; text-align: center; }
.empty .i { margin: 0 auto 14px; color: var(--faint); }
.empty h3 { font-size: 15px; }
.empty p { color: var(--muted); margin: 6px auto 18px; max-width: 360px; }

/* ---------- key-value ---------- */
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 11px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; min-width: 0; }
.pre {
  margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--soft); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-all;
  max-height: 320px; overflow: auto;
}
.list { display: grid; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg); flex: none; }
.dot.off { background: transparent; border: 1.5px solid var(--faint); }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.mini-stats > div { background: var(--surface); padding: 14px 18px; }
.mini-stats b { display: block; font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stock-item { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-all; }

/* ---------- chart ---------- */
.chart { position: relative; padding: 16px 18px 10px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart text { fill: var(--muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--fg); transition: opacity .12s; }
.chart .hit { fill: transparent; cursor: default; }
.chart svg:hover .bar { opacity: .3; }
.chart svg .col:hover .bar { opacity: 1; }
.tip {
  position: absolute; z-index: 3; pointer-events: none; transform: translate(-50%, calc(-100% - 10px));
  padding: 7px 10px; border-radius: 8px; background: var(--inv); color: var(--on-inv);
  font-size: 12px; line-height: 1.35; white-space: nowrap; box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.tip b { display: block; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- flash ---------- */
.flash {
  position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(420px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 10px;
  background: var(--inv); color: var(--on-inv); font-weight: 500; box-shadow: 0 10px 40px rgba(0,0,0,.22);
  animation: flash-in .22s ease-out;
}
.flash.out { opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
@keyframes flash-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding: 0 0 28px; font-size: 14px; }
.login-card h1 { font-size: 22px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); margin: 6px 0 24px; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .cols-2, .cols-even { grid-template-columns: minmax(0, 1fr); }
  .section { grid-template-columns: minmax(0, 1fr); gap: 16px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 8px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 8px 0 0; }
  .brand span:last-child { display: none; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-label { display: none; }
  .nav a { width: auto; flex: none; height: 34px; }
  .nav a span, .side-foot .nav-btn span { display: none; }
  .nav a.active span { display: inline; }
  .side-foot { margin: 0; padding: 0; border: 0; flex-direction: row; }
  .side-foot .nav-btn { width: 34px; justify-content: center; padding: 0; }
  .main { padding: 24px 16px 64px; }
  .page-head h1 { font-size: 24px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .choices, .choices.two { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .table th, .table td { padding: 10px 12px; }
  .hide-sm { display: none; }
  .flash { right: 16px; left: 16px; bottom: 16px; }
}
