:root {
  color-scheme: dark;
  --bg: #09090b;
  --panel: #09090b;
  --raised: #18181b;
  --line: #27272a;
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent: #27272a;
  --primary: #fafafa;
  --primary-text: #09090b;
  --good: #4ade80;
  --good-bg: rgba(74, 222, 128, 0.12);
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.14);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --raised: #fafafa;
  --line: #e4e4e7;
  --text: #09090b;
  --muted: #71717a;
  --accent: #f4f4f5;
  --primary: #18181b;
  --primary-text: #fafafa;
  --good: #15803d;
  --good-bg: #f0fdf4;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --warn: #a16207;
  --warn-bg: #fffbeb;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: Inter, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
.app { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.side { border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; font-weight: 600; }
.logo { width: 28px; height: 28px; border-radius: 8px; }
.nav { display: grid; gap: 2px; }
.nav button { text-align: left; border: 0; background: transparent; color: var(--text); border-radius: 8px; padding: 8px 10px; }
.nav button.active { background: var(--accent); }
.account { margin-top: auto; display: flex; gap: 10px; align-items: center; padding: 10px 8px; border-top: 1px solid var(--line); min-width: 0; }
.account > div:last-child { min-width: 0; flex: 1; }
.account strong, .account .muted { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { flex-shrink: 0; }
.avatar, .cover, .cover.empty { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); font-size: 12px; font-weight: 600; }
.maincol { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 52px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.crumb { font-weight: 500; }
.page { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
.page h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.logic { font-size: 12px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 16px; min-width: 0; }
.kpi .eyebrow { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 600; letter-spacing: -0.03em; margin: 8px 0; }
.pill { display: inline-flex; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 500; }
.up { background: var(--good-bg); color: var(--good); }
.down { background: var(--warn-bg); color: var(--warn); }
.bad { background: var(--bad-bg); color: var(--bad); }
.split { display: grid; grid-template-columns: 1.7fr 0.9fr; gap: 12px; }
.chart svg { width: 100%; height: 220px; display: block; }
.bar { height: 8px; border-radius: 99px; background: var(--accent); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--text); }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 0; }
.toolbar, .filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field, select.field { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.btn, .btn-ghost, .btn-danger, .btn-danger-ghost { border-radius: 8px; padding: 8px 12px; border: 1px solid transparent; font-weight: 500; }
.btn { background: var(--primary); color: var(--primary-text); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--bad); color: #ffffff; }
.btn-danger-ghost { background: transparent; border-color: var(--bad-bg); color: var(--bad); }
.btn-danger-ghost:hover { border-color: var(--bad); background: var(--bad-bg); }
.btn-sm { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.btn[disabled], .btn-ghost[disabled], .btn-danger[disabled], .btn-danger-ghost[disabled] { opacity: 0.45; cursor: not-allowed; }
.seg button { background: transparent; border: 1px solid var(--line); }
.seg button.on { background: var(--accent); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px; white-space: nowrap; }
td { padding: 12px 8px; border-top: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; word-break: break-word; }
td.nowrap { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
.cell-wrap { max-width: 360px; }
.cell-sub { font-size: 12px; overflow-wrap: anywhere; word-break: break-word; }
tr.clickable { cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 12px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 4px; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.tile:hover { border-color: var(--muted); }
.tile-del { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--bad); display: grid; place-items: center; font-size: 13px; line-height: 1; z-index: 2; padding: 0; opacity: 0.9; }
.tile-del:hover { background: var(--bad); color: #ffffff; border-color: var(--bad); opacity: 1; }
.cover-preview-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.cover-close-btn { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: var(--bad); color: #ffffff; display: grid; place-items: center; font-size: 12px; font-weight: 700; line-height: 1; padding: 0; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.cover-close-btn:hover { transform: scale(1.06); }
.uploaded-cover-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-size: 12px; }
.backdrop.confirm-layer { z-index: 12; }
.dialog.confirm-dialog { width: min(440px, 100%); display: grid; gap: 12px; }
.tile .cover, .tile .cover.empty { width: 100%; height: 112px; flex-shrink: 0; border-radius: 8px; margin-bottom: 4px; }
.cover.empty { background: transparent; border: 1px dashed var(--line); }
.cover-img { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; background: var(--accent); display: block; }
.cover-lg { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.tile .cover-img { width: 100%; height: 112px; flex-shrink: 0; border-radius: 8px; margin-bottom: 4px; object-fit: contain; background: var(--raised); }
.tile-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; word-break: break-word; line-height: 1.35; }
.tile-meta { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: auto; padding-top: 2px; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.chip { border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; background: var(--raised); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.banner.wait { background: var(--warn-bg); color: var(--warn); }
.cover-box-panel { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 12px; background: var(--raised); display: grid; gap: 10px; }
.cover-box-panel.missing { border-color: var(--warn); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label, .span-2 { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.span-2 { grid-column: 1 / -1; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(420px, 100%); }
.login .stack .btn, .login .stack .btn-ghost { width: 100%; }
.stack { display: grid; gap: 10px; margin-top: 16px; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 24px; z-index: 10; }
.backdrop.picker-layer { z-index: 22; background: rgba(0, 0, 0, 0.58); }
.backdrop.confirm-layer { z-index: 30; background: rgba(0, 0, 0, 0.62); }
.dialog { width: min(760px, 100%); max-height: min(86vh, 820px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.dialog.picker-dialog { width: min(640px, 100%); display: grid; gap: 12px; }
.genre-trigger { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); cursor: pointer; color: var(--text); transition: border-color 0.15s ease; }
.genre-trigger:hover { border-color: var(--muted); }
.genre-trigger.missing { border-color: var(--warn); }
.genre-trigger.locked { opacity: 0.6; cursor: not-allowed; }
.genre-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1; min-width: 0; }
.genre-tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 12px; font-weight: 500; }
.genre-tag button { border: 0; background: transparent; color: var(--muted); padding: 0 2px; font-size: 13px; line-height: 1; cursor: pointer; }
.genre-tag button:hover { color: var(--bad); }
.genre-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--raised); font-size: 11px; color: var(--text); margin: 2px 4px 2px 0; white-space: nowrap; }
.genre-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; max-height: 290px; overflow: auto; padding: 2px; }
.genre-option { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--raised); color: var(--text); text-align: left; cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease; }
.genre-option:hover { border-color: var(--muted); }
.genre-option.selected { border-color: var(--good); background: var(--good-bg); }
.genre-check { width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; margin-top: 1px; }
.genre-option.selected .genre-check { border-color: var(--good); background: var(--good); color: var(--bg); }
.code-badge { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--raised); color: var(--muted); white-space: nowrap; }
.suggestion-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.suggestion-chip { padding: 3px 9px; border-radius: 999px; border: 1px dashed var(--line); background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.suggestion-chip:hover { border-color: var(--text); color: var(--text); }
.json-box { margin: 8px 0 0; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; overflow: auto; max-height: 380px; white-space: pre; }
.secret-box { border: 1px solid var(--good); background: var(--good-bg); border-radius: 10px; padding: 14px; display: grid; gap: 8px; margin-top: 12px; }
.method-badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 700; letter-spacing: 0.03em; }
.method-get { background: var(--good-bg); color: var(--good); border: 1px solid var(--good); }
.method-post { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.notice { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); border-radius: 8px; padding: 10px 14px; z-index: 40; }
.banner { border-radius: 8px; padding: 10px 12px; margin-top: 12px; overflow-wrap: anywhere; word-break: break-word; }
.banner.ok { background: var(--good-bg); color: var(--good); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.wait { background: var(--panel-2, rgba(255, 255, 255, 0.05)); border: 1px solid var(--line); }
.progress-track { height: 6px; border-radius: 999px; background: rgba(128, 128, 128, 0.25); overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; background: var(--accent, #4f8cff); transition: width 0.15s ease; }
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; }
@media (max-width: 1100px) {
  .kpis, .split, .form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .kpis, .split, .form { grid-template-columns: 1fr; }
}
