:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-soft: #0b1120;
  --panel: #0e1626;
  --panel-2: #111c2f;
  --input: #0a1220;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --faint: #5d6f88;
  --border: #1d2a40;
  --border-strong: #2b3d57;
  --accent: #5eead4;
  --accent-strong: #2dd4bf;
  --accent-soft: rgba(94, 234, 212, 0.12);
  --blue: #7dd3fc;
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.12);
  --warn: #fbbf24;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f5f9;
  --bg-soft: #eaf0f7;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --input: #f8fafc;
  --text: #0f1e31;
  --muted: #5b6b80;
  --faint: #7b8ba1;
  --border: #d8e1ec;
  --border-strong: #c3d0df;
  --accent: #0f766e;
  --accent-strong: #0d9488;
  --accent-soft: rgba(15, 118, 110, 0.09);
  --blue: #0369a1;
  --danger: #be123c;
  --danger-soft: rgba(190, 18, 60, 0.08);
  --warn: #a16207;
  --shadow: 0 24px 70px rgba(15, 35, 55, 0.14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1100px 700px at 8% -10%, rgba(94, 234, 212, 0.06), transparent 60%),
    radial-gradient(900px 600px at 95% 0%, rgba(125, 211, 252, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

::selection { background: var(--accent-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Login ---------- */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  position: relative;
  overflow: hidden;
}

.login-glow {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(600px 420px at 22% 18%, rgba(94, 234, 212, 0.14), transparent 65%),
    radial-gradient(520px 380px at 82% 78%, rgba(125, 211, 252, 0.12), transparent 65%);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: min(440px, 100%);
  padding: 34px 32px 26px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #04111a;
  font-weight: 800;
  letter-spacing: -0.04em;
  box-shadow: 0 8px 24px rgba(94, 234, 212, 0.18);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; letter-spacing: -0.02em; }
.brand-text span { color: var(--muted); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1 { margin: 18px 0 4px; font-size: clamp(26px, 4vw, 34px); letter-spacing: -0.04em; }
h2 { margin: 0; font-size: 17px; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.login-sub { margin: 0 0 24px; font-size: 13px; }

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}
.seg {
  flex: 1;
  border: 0;
  border-radius: 9px;
  padding: 9px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: 160ms ease;
}
.seg.active { background: var(--panel-2); color: var(--text); box-shadow: 0 2px 10px rgba(0,0,0,0.18); }

#login-form { margin-top: 20px; }
label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input);
  color: var(--text);
  padding: 11px 13px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
input:focus, textarea:focus {
  outline: 0;
  border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-hint { margin: 7px 0 16px; color: var(--faint); font-size: 11.5px; }
.login-error {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}
.login-foot { margin: 18px 0 0; color: var(--faint); font-size: 11.5px; line-height: 1.6; }
.theme-link {
  margin-top: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.dashboard { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
}
.brand-lockup.compact .brand-mark { width: 32px; height: 32px; border-radius: 9px; font-size: 12px; }
.brand-lockup.compact .brand-text strong { font-size: 14px; }
.brand-lockup.compact .brand-text span { font-size: 9px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.role-pill {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.role-pill.owner { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); color: var(--accent); background: var(--accent-soft); }
.token-id { color: var(--faint); font-family: var(--mono); font-size: 10px; }

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}
.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-soft) 65%, transparent);
}
.nav { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  transition: 150ms ease;
}
.nav-item small { color: var(--faint); font-family: var(--mono); font-size: 9px; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active {
  border-color: var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar-note { display: flex; align-items: flex-start; gap: 7px; padding: 0 8px; color: var(--faint); font-size: 10.5px; line-height: 1.5; }
.dot { flex: 0 0 auto; width: 6px; height: 6px; margin-top: 5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.main { min-width: 0; padding: 30px clamp(18px, 3.4vw, 44px) 60px; }
.view { max-width: 1180px; margin: 0 auto; animation: rise 220ms ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.page-head h1 { margin: 4px 0 2px; font-size: clamp(24px, 3vw, 32px); }
.page-head .muted { margin: 0; font-size: 12.5px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  transition: 150ms ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--panel-2); }
.btn.primary { border-color: color-mix(in srgb, var(--accent) 65%, var(--border)); background: var(--accent); color: #04111a; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); color: var(--danger); }
.btn.small { min-height: 30px; padding: 5px 10px; font-size: 11px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--muted);
  font-size: 16px;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- Overview ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.stat span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.stat strong { display: block; margin-top: 8px; font-size: 30px; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.stat small { display: block; margin-top: 9px; color: var(--faint); font-size: 10.5px; }
.stat.accent { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); background: linear-gradient(180deg, var(--accent-soft), var(--panel)); }
.stat.accent strong { color: var(--accent); }
.stat.wide-stat { grid-column: span 2; }
.stat.wide-stat strong { font-size: 22px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.85fr); gap: 16px; align-items: start; }
.panel {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-head .eyebrow { margin-bottom: 3px; }

.album-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.album-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
}
.album-card .album-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  color: var(--faint);
  font-size: 11px;
  overflow: hidden;
}
.album-card .album-cover.placeholder { border: 1px dashed var(--border); }
.album-card strong { display: block; margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.album-card small { color: var(--faint); font-size: 10px; }

.mini-history { display: grid; gap: 8px; }
.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-2);
  font-size: 11px;
}
.mini-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.mini-row time { color: var(--faint); white-space: nowrap; }
.mini-pending { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); color: var(--muted); font-size: 11.5px; }

/* ---------- Data ---------- */

.data-panel { padding: 0; overflow: hidden; }
.data-panel .panel-head { margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.data-panel .panel-head .muted { font-size: 11px; }
.segmented.compact-seg { width: auto; padding: 3px; }
.compact-seg .seg { flex: 0 0 auto; padding: 6px 10px; font-size: 11px; }

#data-preview { padding: 18px; }
.data-raw {
  margin: 0;
  max-height: 68vh;
  overflow: auto;
  padding: 18px;
  background: var(--input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.data-editor-wrap { padding: 14px; background: var(--bg-soft); }
#data-editor {
  min-height: 52vh;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  tab-size: 2;
}
.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}
.editor-bar .muted { font-size: 11px; }
.editor-bar > div { display: flex; flex-wrap: wrap; gap: 6px; }

.data-section { margin-bottom: 22px; }
.data-section:last-child { margin-bottom: 0; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.section-head h3 { margin: 0; font-size: 13px; letter-spacing: -0.01em; }
.section-head span { color: var(--faint); font-family: var(--mono); font-size: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 11px;
}
.chip code { color: var(--faint); font-family: var(--mono); font-size: 9px; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; background: var(--panel-2); position: sticky; top: 0; }
.table tr:last-child td { border-bottom: 0; }
.table td { color: var(--text); }
.table td.mono, .mono { font-family: var(--mono); font-size: 10.5px; }
.table td.muted-cell { color: var(--muted); }
.table .cell-title { min-width: 150px; }
.table .cell-nowrap { white-space: nowrap; }

/* ---------- Pending ---------- */

.stack { display: grid; gap: 12px; }
.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.review-head .mono { color: var(--faint); }
.review-head time { color: var(--muted); font-size: 11px; }
.review-pre {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  padding: 14px 16px;
  background: var(--input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}

.empty {
  padding: 34px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  background: var(--bg-soft);
}

/* ---------- History ---------- */

.table-panel { padding: 0; overflow: auto; }
.table-panel .table { min-width: 680px; }
.table-panel .empty { margin: 0; border: 0; border-top: 1px solid var(--border); border-radius: 0; background: transparent; }
.notice {
  margin: -8px 0 14px;
  padding: 9px 12px;
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------- Tokens / settings ---------- */

.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form label { margin: 0; }
.inline-form input { flex: 1 1 240px; }
.form-stack { display: grid; gap: 7px; }
.form-stack label { margin: 4px 0 0; }
.form-stack .btn { justify-self: start; margin-top: 6px; }
.field-error { margin: 2px 0 0; color: var(--danger); font-size: 11.5px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 11px; word-break: break-all; }

.token-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}
.token-row strong { display: block; font-size: 12.5px; }
.token-row small { display: block; margin-top: 3px; color: var(--faint); font-family: var(--mono); font-size: 9.5px; }

/* ---------- Modal / toast ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 14, 0.72);
  backdrop-filter: blur(5px);
}
.modal {
  width: min(680px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--panel-2); }
.modal-body pre {
  margin: 0;
  max-height: 50vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-text { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.token-box { display: flex; gap: 8px; margin: 12px 0 4px; }
.token-box input { font-family: var(--mono); font-size: 12px; }
.danger-text { color: var(--danger); }

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}
.toast {
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 12px;
  animation: toast-in 180ms ease both;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat.wide-stat { grid-column: span 1; }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar { height: 60px; padding: 0 14px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 60px;
    z-index: 9;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(14px);
  }
  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    gap: 2px;
    scrollbar-width: thin;
  }
  .nav-item { width: auto; padding: 8px 10px; white-space: nowrap; }
  .nav-item small { display: none; }
  .sidebar-note { display: none; }
  .main { padding: 20px 14px 48px; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 10px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .album-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-bar { align-items: flex-start; flex-direction: column; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form input { flex-basis: auto; }
  .token-row { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 430px) {
  .stat-grid { grid-template-columns: 1fr; }
  .stat { min-height: 88px; }
  .stat strong { font-size: 24px; }
  .login-card { padding: 26px 20px 22px; }
  .top-actions .token-id { display: none; }
}
