:root {
  color-scheme: light;
  --bg: #f5f7fb; --surface: #fff; --surface-2: #f1f4f9; --nav-bg: #fff;
  --border: #e4e9f0; --border-strong: #d3dbe6;
  --text: #0f172a; --text-muted: #56657a; --text-subtle: #6b778a;
  --primary: #2563eb; --primary-hover: #1d4ed8; --primary-ink: #fff; --primary-soft: #eaf1ff; --primary-text: #1d4ed8;
  --ring: rgba(37,99,235,.32);
  --ok: #067647; --ok-soft: #e6f6ed; --warn: #a15c07; --warn-soft: #fdf1d6;
  --bad: #b42318; --bad-soft: #fde8e6; --info: #3538cd; --info-soft: #eef0ff;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow-md: 0 1px 3px rgba(15,23,42,.06), 0 6px 16px rgba(15,23,42,.05);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.14);
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 999px;
  --ease: cubic-bezier(.2,.8,.2,1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --nav-w: 248px; --top-h: 60px;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0e15; --surface: #111723; --surface-2: #161e2c; --nav-bg: #0d131d;
  --border: #212b3b; --border-strong: #2d394d;
  --text: #e6ebf3; --text-muted: #9aa9bd; --text-subtle: #738198;
  --primary: #5b8cff; --primary-hover: #7aa1ff; --primary-ink: #06101f; --primary-soft: #162341; --primary-text: #8fb0ff;
  --ring: rgba(91,140,255,.42);
  --ok: #6fd3a0; --ok-soft: #0f2a1f; --warn: #f0c26a; --warn-soft: #2c2210;
  --bad: #f5a399; --bad-soft: #2e1714; --info: #a5b0ff; --info-soft: #1b1f3d;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 1px 3px rgba(0,0,0,.4), 0 8px 20px rgba(0,0,0,.3);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.55);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--primary-text); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--primary); }
code, .mono { font-family: var(--mono); font-size: .86em; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { flex: none; display: inline-block; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.cell-sub { color: var(--text-subtle); font-size: .82em; }
.mono.cell-sub { font-size: .78rem; }

.skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; background: var(--primary); color: var(--primary-ink); padding: 8px 14px; border-radius: var(--r-sm); font-weight: 600; transition: top .15s var(--ease); }
.skip-link:focus { top: 12px; color: var(--primary-ink); }

/* layout shell */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav { position: sticky; top: 0; align-self: start; height: 100vh; display: flex; flex-direction: column; gap: 2px; padding: 18px 14px; background: var(--nav-bg); border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-md); background: var(--primary-soft); color: var(--primary-text); }
.brand-name { display: block; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { display: block; font-size: .76rem; color: var(--text-subtle); }
.nav-label { margin: 14px 10px 4px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-subtle); }
.nav-link { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px; border: 0; background: none; border-radius: var(--r-sm); color: var(--text-muted); font-weight: 500; cursor: pointer; text-align: left; transition: background .15s var(--ease), color .15s var(--ease); }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-text); }
.nav-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.nav-footer form { margin: 0; }

.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; height: var(--top-h); padding: 0 20px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-title { display: flex; align-items: center; gap: 6px; color: var(--text); font-weight: 500; min-width: 0; overflow: hidden; }
.topbar-title a { color: var(--text-muted); }
.topbar-title .sep { color: var(--text-subtle); }
.topbar-title .icon { color: var(--text-subtle); }
.topbar-spacer { flex: 1; }
.menu-btn { display: none; }
main { padding: 22px 20px 48px; width: 100%; max-width: 1120px; }

.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); border-radius: var(--r-sm); cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.danger:hover { color: var(--bad); border-color: var(--bad); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.theme-icon-dark { display: none; }
html[data-theme="dark"] .theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-dark { display: inline-block; }

.scrim { display: none; }

/* page + cards */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { color: var(--text-muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-actions form { margin: 0; }
.section { margin-top: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card-head p { color: var(--text-muted); font-size: .86rem; margin-top: 2px; }
.card-head form { margin: 0; }
.card-body { padding: 18px; }
.card-link { display: inline-flex; align-items: center; gap: 4px; font-size: .86rem; font-weight: 600; }
.count-chip { display: inline-block; padding: 1px 8px; border-radius: var(--r-full); background: var(--surface-2); color: var(--text-muted); font-size: .8rem; font-weight: 600; vertical-align: middle; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { color: var(--text-muted); font-size: .84rem; font-weight: 500; }
.stat-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text-muted); }
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-icon.neutral { background: var(--surface-2); color: var(--text-muted); }
.stat-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.stat-foot { color: var(--text-subtle); font-size: .82rem; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; padding: 10px 18px; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-subtle); border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted-num { color: var(--text-subtle); }
.num.pos { color: var(--ok); }
.num.neg { color: var(--bad); }
.stamp { color: var(--text-subtle); font-size: .84rem; white-space: nowrap; }
.row-end { text-align: right; white-space: nowrap; }
.row-end form { display: inline-block; margin: 0 0 0 4px; }
.order { white-space: nowrap; }
.order form { display: inline-block; margin: 0 2px 0 0; }
.who { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; }
.who:hover { color: var(--primary); }
.who-name { display: inline-flex; align-items: baseline; gap: 6px; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-full); background: var(--primary-soft); color: var(--primary-text); font-weight: 700; font-size: .8rem; text-transform: uppercase; flex: none; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.2rem; }
.node-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text-muted); flex: none; }
.unit-text { display: inline-block; max-width: 44ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: var(--r-full); font-size: .74rem; font-weight: 600; letter-spacing: .01em; background: var(--surface-2); color: var(--text-muted); text-transform: capitalize; }
.badge.onsale, .badge.paid, .badge.credited { background: var(--ok-soft); color: var(--ok); }
.badge.soldout, .badge.pending, .badge.detected { background: var(--warn-soft); color: var(--warn); }
.badge.hidden, .badge.expired, .badge.cancelled, .badge.dropped { background: var(--bad-soft); color: var(--bad); }
.badge.section { background: var(--info-soft); color: var(--info); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border: 1px solid transparent; border-radius: var(--r-sm); background: var(--primary); color: var(--primary-ink); font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, opacity .15s; }
.btn:hover { background: var(--primary-hover); color: var(--primary-ink); }
.btn.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn.secondary:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 85%, #000); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: .84rem; }
.btn.block { width: 100%; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-icon { display: inline-flex; }
.btn .spinner { display: none; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-icon { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* forms */
.form-col { display: flex; flex-direction: column; gap: 14px; }
.form-stack { display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field-hint { font-size: .8rem; color: var(--text-subtle); }
input[type="text"], input[type="password"], input:not([type]), input[type="number"], textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; font-family: var(--mono); font-size: .86rem; line-height: 1.5; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input[aria-invalid="true"] { border-color: var(--bad); }
.input-group { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.input-group:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input-group .prefix { display: grid; place-items: center; padding: 0 10px; background: var(--surface-2); color: var(--text-subtle); border-right: 1px solid var(--border); }
.input-group input { border: 0; box-shadow: none; }
.input-group input:focus { box-shadow: none; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.order-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.order-inline form { margin: 0; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--r-sm); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { display: inline-flex; align-items: center; gap: 5px; padding: 7px 13px; border-radius: 6px; font-size: .86rem; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: background .15s, color .15s; }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + label { box-shadow: 0 0 0 3px var(--ring); }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar .btn { margin: 0; }
.search-field { flex: 1; min-width: 200px; }
.pw-field { position: relative; }
.pw-field input { padding-right: 42px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: none; color: var(--text-subtle); cursor: pointer; border-radius: 6px; }
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }

.quick-links { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.quick-links .btn { width: 100%; justify-content: flex-start; }

/* key-value lists */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px 24px; margin: 0; }
.kv > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kv-wide { grid-column: 1 / -1; }
.kv dt { color: var(--text-subtle); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.kv dd { margin: 0; font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }

.profile { display: flex; align-items: center; gap: 16px; padding: 18px; }
.profile-name { font-size: 1.3rem; }
.profile-meta { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; color: var(--text-muted); font-size: .86rem; }
.profile-meta span { display: inline-flex; align-items: center; gap: 5px; }
.card > .kv { padding: 0 18px 18px; }
.card > .profile + .kv { border-top: 1px solid var(--border); padding-top: 16px; }

.copy-cell { display: inline-flex; align-items: center; gap: 6px; }
.copy-btn { display: grid; place-items: center; width: 26px; height: 26px; border: 0; background: none; color: var(--text-subtle); cursor: pointer; border-radius: 6px; }
.copy-btn:hover { color: var(--text); background: var(--surface-2); }
.copy-btn.copied { color: var(--ok); }

.inline-error, .inline-note { display: flex; align-items: flex-start; gap: 8px; padding: 11px 13px; border-radius: var(--r-sm); font-size: .88rem; margin-top: 14px; }
.inline-error { background: var(--bad-soft); color: var(--bad); }
.inline-note { background: var(--info-soft); color: var(--info); }
.inline-error .icon, .inline-note .icon { margin-top: 1px; flex: none; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 34px 18px; text-align: center; color: var(--text-muted); }
.empty-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: var(--r-full); background: var(--surface-2); color: var(--text-subtle); }
.empty p { font-size: .86rem; color: var(--text-subtle); max-width: 36ch; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: .86rem; flex-wrap: wrap; }
.pager-nav { display: flex; gap: 8px; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-tools { position: fixed; top: 16px; right: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 20px; box-shadow: var(--shadow-lg); }
.login-card .brand { padding: 0; }
.login-card h1 { font-size: 1.35rem; }
.lede { color: var(--text-muted); margin-top: 4px; }

/* toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 10px; max-width: min(92vw, 380px); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toast-in .25s var(--ease); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast p { margin: 0; font-size: .9rem; }
.toast-icon { flex: none; margin-top: 1px; }
.toast.ok .toast-icon { color: var(--ok); }
.toast.bad .toast-icon { color: var(--bad); }
.toast-close { margin-left: auto; border: 0; background: none; color: var(--text-subtle); cursor: pointer; padding: 2px; border-radius: 4px; }
.toast-close:hover { color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; z-index: 40; left: 0; top: 0; width: var(--nav-w); transform: translateX(-100%); transition: transform .2s var(--ease); box-shadow: var(--shadow-lg); }
  html[data-nav="open"] .nav { transform: none; }
  html[data-nav="open"] .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.4); }
  .menu-btn { display: inline-grid; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr; }
  main { padding: 16px 16px 40px; }
  .topbar { padding: 0 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
