:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --sidebar: #0b1220;
  --sidebar-ink: #cbd5e1;
  --sidebar-muted: #7f8ea8;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.wrap { overflow-wrap: anywhere; word-break: break-word; }
.right { text-align: right; }
.inline { display: inline; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 238px;
  flex: 0 0 238px;
  background: linear-gradient(180deg, #0b1220, #111c31);
  color: var(--sidebar-ink);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; color: #fff; padding: 4px 8px 20px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .4px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; letter-spacing: .5px; }
.brand-text small { color: var(--sidebar-muted); font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  color: var(--sidebar-ink);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { background: rgba(56, 189, 248, .14); color: #e0f2fe; box-shadow: inset 2px 0 0 #38bdf8; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.08); }
.lock-pill { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--sidebar-muted); }
.lock-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(245,158,11,.12); }
.lock-pill.unlocked .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.12); }
.side-link { color: var(--sidebar-muted); font-size: 12px; }
.side-link:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
.topbar {
  height: 62px; background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px; position: sticky; top: 0; z-index: 10;
}
.page-title { display: flex; align-items: center; gap: 10px; }
.page-title .crumb { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.user-chip { font-size: 12px; color: var(--muted); padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px; background: #fff; }
.content { padding: 26px; max-width: 1440px; margin: 0 auto; }

/* auth */
.auth-shell {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 16px;
  background: radial-gradient(1200px 600px at 10% 0%, #dff3ff 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 100%, #e6e9ff 0%, transparent 55%),
              var(--bg);
}
.auth-card {
  width: min(560px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 30px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand div { display: flex; flex-direction: column; line-height: 1.2; }
.auth-brand small { color: var(--muted); font-size: 11px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card > p { margin-bottom: 18px; }
.auth-foot { margin-top: 14px; color: var(--muted); font-size: 12px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 18px; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.grid-main + .card { margin-top: 0; }
.card + .grid-main, .grid-main + .grid-main { margin-top: 0; }

/* hero */
.hero {
  background: linear-gradient(135deg, #0b1220, #12304f);
  color: #e2e8f0; border-radius: 16px; padding: 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  margin-bottom: 20px;
}
.hero h1 { color: #fff; margin: 6px 0 8px; }
.hero p { color: #a9b7cc; max-width: 620px; }
.hero code { color: #7dd3fc; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #7dd3fc; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 12px; }
.stat strong { display: block; font-size: 28px; margin: 4px 0 0; letter-spacing: -.02em; }
.stat small { color: var(--muted); font-size: 11px; }
.stat.warn strong { color: var(--amber); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; line-height: 1.2; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: #94a3b8; background: #f8fafc; }
.btn.primary { background: linear-gradient(180deg, #0ea5e9, #0284c7); border-color: #0284c7; color: #fff; }
.btn.primary:hover { background: linear-gradient(180deg, #38bdf8, #0284c7); }
.btn.ghost { background: transparent; }
.btn.danger { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.btn.danger:hover { background: #fee2e2; border-color: #fca5a5; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* forms */
.stack { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:first-child { font-size: 12.5px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 9px 11px; font: inherit; background: #fff; color: var(--ink);
}
.field textarea { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 12.5px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.field input[type="file"] { padding: 7px; background: var(--panel-soft); font-size: 12px; }
.field.hint p { color: var(--muted); font-size: 12px; margin: 0; }
.help { color: var(--muted); font-size: 12px; margin: 0; }
.section-title { margin: 6px 0 -4px; font-size: 13px; color: #334155; text-transform: uppercase; letter-spacing: .06em; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #334155; }
.check input { width: auto; }
.check-row { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-soft); }
.segmented { display: flex; gap: 6px; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; padding: 5px; background: var(--panel-soft); }
.segmented label { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 6px; font-size: 12.5px; cursor: pointer; }
.segmented label:has(input:checked) { background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.08); color: var(--accent-dark); font-weight: 600; }
.segmented input { width: auto; }

/* alerts */
.alert { border-radius: 9px; padding: 11px 14px; font-size: 13px; border: 1px solid #cbd5e1; background: #f8fafc; color: #334155; }
.alert.warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--panel-soft); color: var(--muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fbff; }
td.right, th.right { text-align: right; }

/* badges */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; white-space: nowrap; }
.pill.blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.pill.green { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.pill.warn { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.pill.red { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.inline-title { display: inline-block; }

/* key-value */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; margin: 0; }
.kv.wide { grid-template-columns: 1fr; gap: 10px; }
.kv > div { min-width: 0; }
.kv dt { color: var(--muted); font-size: 11.5px; margin-bottom: 2px; }
.kv dd { margin: 0; font-size: 13px; }
.ca-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.ca-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.ca-card h3 a { color: var(--ink); }
.ca-card .kv { margin: 12px 0 14px; }

/* page actions / filters */
.page-actions { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-actions > p { max-width: 720px; }
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; font: inherit; background: #fff; }
.filter-bar input { min-width: 240px; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-actions.wrap { flex-wrap: wrap; }
.row-actions.tight { gap: 5px; justify-content: flex-end; }

/* downloads */
.download-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.download-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
.download-item {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel-soft);
  color: var(--ink); min-width: 0;
}
.download-item:hover { border-color: var(--accent); background: #f0f9ff; text-decoration: none; }
.download-item strong { font-size: 12.5px; }
.download-item span { color: var(--muted); font-size: 11px; }
.download-item.locked { border-style: dashed; }
.download-item.disabled { opacity: .55; }
.url-box { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-soft); display: flex; flex-direction: column; gap: 3px; }
.url-box > span { color: var(--muted); font-size: 11px; }
.url-box code, .url-box a { overflow-wrap: anywhere; font-size: 12px; }

/* chain */
.chain { display: flex; flex-direction: column; gap: 2px; }
.chain-node { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-soft); }
.chain-node > div { min-width: 0; }
.chain-arrow { text-align: center; color: var(--line-strong); font-size: 14px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.timeline li { display: flex; align-items: baseline; gap: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.timeline li:last-child { border-bottom: 0; padding-bottom: 0; }

/* code */
.code { background: #0b1220; color: #dbeafe; border-radius: 9px; padding: 14px; font-family: var(--mono); font-size: 12px; line-height: 1.6; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.code.scroll { max-height: 320px; overflow-y: auto; }
.advanced { border: 1px dashed var(--line-strong); border-radius: 9px; padding: 10px 12px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
.advanced .code { margin-top: 10px; }

/* pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding-top: 14px; }

/* misc */
.empty { color: var(--muted); padding: 18px 4px; }
.empty-state { text-align: center; padding: 50px 20px; background: var(--panel); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty-state h2 { margin-bottom: 6px; }
.empty-state p { color: var(--muted); margin-bottom: 18px; }
.error-box { text-align: center; padding: 70px 20px; }
.error-code { font-size: 64px; font-weight: 800; color: var(--line-strong); letter-spacing: -.04em; }
.error-box h2 { margin: 6px 0 20px; }
.error-box .row-actions { justify-content: center; }
.hidden { display: none !important; }

@media (max-width: 1050px) {
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { flex-direction: row; align-items: center; justify-content: space-between; margin-top: 12px; }
  .content { padding: 18px; }
  .topbar { padding: 0 18px; }
  .form-grid.two, .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .download-grid, .download-grid.compact { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; }
}
