/* ===== Tokens ===== */
:root {
  --bg: #f7f8f9; --panel: #ffffff; --panel-2: #f1f3f5; --border: #e3e6ea; --border-strong: #cfd4da;
  --text: #11181c; --muted: #687076; --faint: #889096;
  --brand: #3ecf8e; --brand-strong: #249361; --brand-soft: rgba(62,207,142,.12);
  --danger: #e5484d; --danger-soft: rgba(229,72,77,.1); --warn: #f5a524; --warn-soft: rgba(245,165,36,.12);
  --info: #3e63dd; --info-soft: rgba(62,99,221,.1);
  --code-bg: #f1f3f5; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 8px; --radius-sm: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #121212; --panel: #1a1a1a; --panel-2: #222; --border: #2e2e2e; --border-strong: #3d3d3d;
  --text: #ededed; --muted: #a0a0a0; --faint: #707070;
  --brand-strong: #3ecf8e; --code-bg: #161616; --shadow: 0 4px 20px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--brand-strong); }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; } h3 { font-size: 15px; } h4 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hidden { display: none !important; }

/* ===== Layout ===== */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.brand-logo { width: 26px; height: 26px; border-radius: 6px; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 800; }
.nav { padding: 8px; overflow-y: auto; flex: 1; }
.nav-section { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--text); font-weight: 500; }
.nav .ico { width: 18px; text-align: center; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--faint); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.view { flex: 1; overflow: auto; padding: 24px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head p { margin: 4px 0 0; color: var(--muted); }
.menu-btn { display: none; }

/* ===== Components ===== */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.split { display: grid; grid-template-columns: 240px 1fr; gap: 16px; min-height: 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.loading { pointer-events: none; opacity: .7; }
.btn.loading::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.field .hint { font-weight: 400; color: var(--faint); font-size: 12px; }
input, select, textarea { font: inherit; font-size: 13px; color: var(--text); background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; width: 100%; min-width: 0; }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type="checkbox"] { width: auto; }
.inline-check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.yellow { background: var(--warn-soft); color: #b07400; border-color: transparent; }
.badge.blue { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.on { background: var(--brand); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--muted); font: inherit; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); }

.list { display: flex; flex-direction: column; gap: 2px; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item:hover { background: var(--panel-2); color: var(--text); }
.list-item.active { background: var(--brand-soft); color: var(--text); }

.callout { padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-2); font-size: 13px; }
.callout.warn { background: var(--warn-soft); border-color: transparent; }
.callout.error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.callout.info { background: var(--info-soft); border-color: transparent; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 32px; margin-bottom: 8px; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--panel-2); }

/* ===== Data table ===== */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); max-height: 62vh; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); text-align: left; vertical-align: top; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--panel-2); font-weight: 600; z-index: 1; cursor: default; }
table.data th .type { font-weight: 400; color: var(--faint); font-size: 11px; margin-left: 4px; }
table.data th.sortable { cursor: pointer; }
table.data tr:hover td { background: var(--panel-2); }
table.data td.null { color: var(--faint); font-style: italic; }
table.data td.num { font-family: var(--mono); text-align: right; }
table.data td.json { font-family: var(--mono); color: var(--info); }
table.data td.act, table.data th.act { width: 1%; position: sticky; left: 0; background: var(--panel); z-index: 2; }
table.data th.act { z-index: 3; background: var(--panel-2); }

/* ===== JSON / response ===== */
.response { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 16px; background: var(--panel); }
.response-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; font-size: 12.5px; }
.response-head .spacer { flex: 1; }
.response-body { padding: 12px; max-height: 60vh; overflow: auto; }
pre.code { background: var(--code-bg); padding: 12px; border-radius: var(--radius-sm); overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-word; }
.json { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.json details { margin-left: 14px; } .json > details { margin-left: 0; }
.json summary { cursor: pointer; list-style: none; } .json summary::-webkit-details-marker { display: none; }
.json summary::before { content: "▸ "; color: var(--faint); } .json details[open] > summary::before { content: "▾ "; }
.json .kv { margin-left: 14px; }
.json .k { color: #9b4dca; } .json .s { color: #2b8a3e; } .json .n { color: #d9480f; } .json .b { color: var(--info); } .json .z { color: var(--faint); } .json .p { color: var(--faint); }
:root[data-theme="dark"] .json .k { color: #c792ea; } :root[data-theme="dark"] .json .s { color: #a5d6a7; } :root[data-theme="dark"] .json .n { color: #f78c6c; }

/* ===== Modal / toast ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .12s; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; width: min(640px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { width: min(900px, 100%); }
.modal-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow); font-size: 13px; animation: fade .15s; word-break: break-word; }
.toast.success { border-left-color: var(--brand); } .toast.error { border-left-color: var(--danger); } .toast.warn { border-left-color: var(--warn); }

/* ===== Storage ===== */
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); }
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.crumbs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.crumbs a { cursor: pointer; text-decoration: none; }
.preview img { max-width: 100%; max-height: 60vh; border-radius: var(--radius-sm); }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .split { grid-template-columns: 1fr; }
  .view { padding: 16px; }
}

/* spacing between stacked blocks */
.grid > .card + .card { margin-top: 0; }
.grid + .card, .card + .grid, .grid + .grid, .grid + div > .card:first-child { margin-top: 16px; }
