:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --surface-hover: #eceff6;
  --border: #e2e5ee;
  --border-strong: #cfd4e1;
  --text: #0f1729;
  --text-2: #3b4559;
  --muted: #6b7489;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-contrast: #ffffff;
  --primary-soft: #eef0ff;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf3e2;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow-sm: 0 1px 2px rgba(15, 23, 41, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 41, 0.06), 0 8px 24px rgba(15, 23, 41, 0.06);
  --shadow-lg: 0 24px 64px rgba(15, 23, 41, 0.18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0a0c12;
  --surface: #11141c;
  --surface-2: #171b26;
  --surface-hover: #1d2230;
  --border: #232838;
  --border-strong: #303749;
  --text: #e7e9f0;
  --text-2: #b9bfcd;
  --muted: #858da1;
  --primary: #8b8cf8;
  --primary-hover: #a5a6fb;
  --primary-contrast: #0a0c12;
  --primary-soft: rgba(139, 140, 248, 0.14);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
svg.icon { width: 16px; height: 16px; flex: none; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); text-decoration: none; }
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); background: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 550; font-size: 13px; color: var(--text-2); }
.field small { color: var(--muted); font-size: 12px; }
.input {
  width: 100%; height: 36px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.input { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
select.input { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, var(--primary-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow-lg); }
.login-card .brand { margin-bottom: 24px; }
.login-card h1 { margin-bottom: 4px; }
.login-theme { position: fixed; top: 16px; right: 16px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 272px 1fr; height: 100vh; }
.sidebar { display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; box-shadow: var(--shadow-sm); }
.brand-logo svg { width: 18px; height: 18px; }
.sidebar-head { padding: 18px 16px 12px; display: flex; align-items: center; justify-content: space-between; }
.nav { padding: 4px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; cursor: pointer; border: 0; background: none; font: inherit; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-section { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 6px; font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.search { margin: 4px 12px 8px; position: relative; }
.search .input { height: 32px; padding-left: 32px; font-size: 13px; }
.search svg { position: absolute; left: 10px; top: 8px; color: var(--muted); }
.app-list { flex: 1; overflow-y: auto; padding: 0 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.app-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-2); cursor: pointer; }
.app-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.app-item.active { background: var(--primary-soft); color: var(--text); }
.app-item .avatar { width: 28px; height: 28px; font-size: 12px; }
.app-item .meta { min-width: 0; flex: 1; }
.app-item .name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-item .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { flex: none; display: grid; place-items: center; border-radius: 8px; font-weight: 700; color: #fff; text-transform: uppercase; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; display: flex; align-items: center; gap: 8px; }
.user-chip { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-chip .avatar { width: 28px; height: 28px; font-size: 12px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.user-chip span { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { overflow-y: auto; min-width: 0; }
.topbar { display: none; }
.content { max-width: 1180px; margin: 0 auto; padding: 28px 32px 64px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head .title { flex: 1; min-width: 240px; display: flex; gap: 14px; align-items: center; }
.page-head .avatar { width: 48px; height: 48px; font-size: 18px; border-radius: 12px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.slug-pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 12px; color: var(--text-2); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head p { margin: 0; color: var(--muted); font-size: 13px; }
.card-body { padding: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .label svg { color: var(--primary); }
.stat .value { font-size: 26px; font-weight: 680; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-hover) 50%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
.v-num { font-weight: 650; font-family: var(--mono); font-size: 13.5px; }
.v-notes { color: var(--muted); font-size: 12.5px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-cell { display: flex; flex-direction: column; min-width: 0; max-width: 240px; }
.file-cell .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.hash { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 12px; color: var(--text-2); cursor: pointer; border-radius: 6px; padding: 1px 4px; margin-left: -4px; border: 0; background: none; }
.hash:hover { background: var(--surface-hover); color: var(--text); }
.hash b { font-weight: 600; color: var(--muted); font-family: var(--font); font-size: 11px; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--border-strong); margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- endpoint explorer ---------- */
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 550; font-size: 13px; padding: 4px 12px; border-radius: 6px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.url-bar { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.url-bar .method { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--success); background: var(--success-soft); padding: 2px 6px; border-radius: 5px; }
.url-bar code { flex: 1; overflow-x: auto; white-space: nowrap; color: var(--text); }
pre.code { margin: 0; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: auto; max-height: 340px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: var(--text-2); }
.explorer { display: flex; flex-direction: column; gap: 12px; }
.explorer-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- recent list ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); color: var(--text); }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-hover); text-decoration: none; }
.list-item .avatar { width: 32px; height: 32px; font-size: 13px; }
.list-item .meta { flex: 1; min-width: 0; }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.endpoint-doc { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.endpoint-doc code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 10, 18, 0.5); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade 0.15s ease-out; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 40px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop 0.18s ease-out; }
.modal-sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 26px; text-align: center; cursor: pointer; transition: border-color 0.15s, background 0.15s; background: var(--surface-2); }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone svg { width: 28px; height: 28px; color: var(--primary); margin-bottom: 6px; }
.dropzone .file-picked { font-weight: 600; color: var(--text); word-break: break-all; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #7c3aed); transition: width 0.15s; }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 380px; padding: 11px 14px; border-radius: 10px; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); animation: pop 0.18s ease-out; font-weight: 500; }
.toast.success svg { color: var(--success); }
.toast.error svg { color: var(--danger); }

.theme-switch { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.theme-switch button { width: 26px; height: 24px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 6px; cursor: pointer; }
.theme-switch button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.theme-switch svg { width: 14px; height: 14px; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--primary); animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 64px; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
  .content { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 22px; }
}
