[hidden] { display: none !important; }
:root {
  --bg: #f6f7f9; --card: #fff; --ink: #14181f; --muted: #6b7380; --line: #e4e7ec;
  --accent: #2463eb; --accent-ink: #fff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --code-bg: #0f1724; --code-ink: #dbe4f0;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --r: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  max-width: 920px; margin-inline: auto;
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; font-weight: 700; }
.sync { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--ink); }
.sync:active { transform: scale(.97); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px #16a34a22; }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px #dc262622; }
.dot.busy { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.stats b { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats span { color: var(--muted); font-size: 12px; }
.stats .has { color: var(--warn); }

.boot { display: flex; align-items: center; gap: 12px; justify-content: center; padding: 60px 0; color: var(--muted); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -14px; padding-inline: 14px; scrollbar-width: none; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 500; scroll-snap-align: start; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.editor { position: relative; border-radius: var(--r); background: var(--code-bg); overflow: hidden; height: 172px; }
.editor .hl, .editor textarea {
  margin: 0; position: absolute; inset: 0; padding: 14px; font: 13.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word;
  overflow: auto; tab-size: 2; border: 0;
}
.editor .hl { color: var(--code-ink); pointer-events: none; }
.editor textarea { background: transparent; color: transparent; caret-color: #fff; resize: none; outline: none; -webkit-text-fill-color: transparent; }
.editor textarea::selection { background: #3b82f655; -webkit-text-fill-color: transparent; }
.tk-k { color: #7cb7ff; font-weight: 600; }
.tk-f { color: #f0b86e; }
.tk-s { color: #9fe0a3; }
.tk-n { color: #f59fb8; }
.tk-c { color: #6c7a90; font-style: italic; }
.tk-o { color: #c6a7ff; }

.runbar { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.run { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 11px 22px; font-weight: 650; font-size: 15px; }
.run:active { transform: scale(.97); }
.run:disabled { opacity: .55; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 12px; padding: 11px 18px; color: var(--ink); }
.meta { color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.meta b { color: var(--ink); }

.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; border-radius: var(--r); padding: 10px 12px; font: 13px/1.45 var(--mono); white-space: pre-wrap; margin-bottom: 10px; }
.plan { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; font: 12px/1.5 var(--mono); white-space: pre; overflow-x: auto; margin-bottom: 10px; }

.results { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; max-height: 62vh; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.results:empty { display: none; }
table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: #f9fafb; font-weight: 600; font-size: 12px; color: var(--muted); z-index: 1; }
td.num { text-align: right; }
td.json { font: 12px var(--mono); color: #475569; }
td.null { color: #b0b7c3; }
tbody tr:last-child td { border-bottom: 0; }
tbody.editable tr { cursor: pointer; }
tbody.editable tr:active td { background: #eef4ff; }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #fff4cc; } }
.more { padding: 10px 12px; color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; }

.sheet { border: 0; padding: 0; border-radius: 20px 20px 0 0; width: 100%; max-width: 560px; margin: auto auto 0; max-height: 88vh; background: var(--card); color: var(--ink); }
.sheet::backdrop { background: #0f172a66; }
@media (min-width: 700px) { .sheet { border-radius: 20px; margin: auto; } }
.sheet form { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet h2 { font-size: 17px; margin: 0; }
.x { border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; color: var(--muted); }
.fields { display: grid; gap: 10px; max-height: 60vh; overflow: auto; padding: 4px 0; }
.fields label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.fields input, .fields select, .fields textarea { font: 16px/1.3 inherit; font-family: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; width: 100%; }
.fields textarea { font: 13px/1.4 var(--mono); min-height: 84px; }
.fields input:read-only { color: var(--muted); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
