:root {
  color-scheme: light dark;
  --page: #f5f5f7; --surface: #fff; --surface-2: #f9f9fb; --surface-3: #0000000a;
  --ink: #1d1d1f; --ink-2: #3a3a3c; --muted: #86868b; --line: #00000014; --line-strong: #00000024;
  --accent: #007aff; --accent-ink: #0066d6; --hover: #007aff12; --accent-soft: #007aff1f;
  --good: #34c759; --good-ink: #248a3d; --good-soft: #34c75921;
  --warn: #ff9500; --warn-ink: #c76a00; --warn-soft: #ff950021;
  --bad: #ff3b30; --bad-ink: #d70015; --bad-soft: #ff3b3014;
  --primary-bg: #007aff; --primary-ink: #fff;
  --shadow: 0 0 0 0.5px #0000000d, 0 1px 2px #0000000a; --shadow-lg: 0 0 0 0.5px #00000026, 0 22px 50px -10px #00000040;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #1e1e1e; --surface: #2a2a2a; --surface-2: #262626; --surface-3: #ffffff0f;
    --ink: #f5f5f7; --ink-2: #d1d1d6; --muted: #98989d; --line: #ffffff14; --line-strong: #ffffff24;
    --accent: #0a84ff; --accent-ink: #409cff; --hover: #0a84ff17; --accent-soft: #0a84ff2e;
    --good: #30d158; --good-ink: #30d158; --good-soft: #30d1581f;
    --warn: #ff9f0a; --warn-ink: #ffb340; --warn-soft: #ff9f0a1f;
    --bad: #ff453a; --bad-ink: #ff6961; --bad-soft: #ff453a1f;
    --primary-bg: #0a84ff; --primary-ink: #fff;
    --shadow: 0 0 0 0.5px #ffffff12; --shadow-lg: 0 0 0 0.5px #ffffff1f, 0 22px 50px -10px #000000b3;
  }
}
:root[data-theme="dark"] {
    --page: #1e1e1e; --surface: #2a2a2a; --surface-2: #262626; --surface-3: #ffffff0f;
    --ink: #f5f5f7; --ink-2: #d1d1d6; --muted: #98989d; --line: #ffffff14; --line-strong: #ffffff24;
    --accent: #0a84ff; --accent-ink: #409cff; --hover: #0a84ff17; --accent-soft: #0a84ff2e;
    --good: #30d158; --good-ink: #30d158; --good-soft: #30d1581f;
    --warn: #ff9f0a; --warn-ink: #ffb340; --warn-soft: #ff9f0a1f;
    --bad: #ff453a; --bad-ink: #ff6961; --bad-soft: #ff453a1f;
    --primary-bg: #0a84ff; --primary-ink: #fff;
    --shadow: 0 0 0 0.5px #ffffff12; --shadow-lg: 0 0 0 0.5px #ffffff1f, 0 22px 50px -10px #000000b3;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 26px; letter-spacing: -0.02em; margin: 2px 0 2px; }
h2 { font-size: 15px; margin: 0 0 12px; }
p { margin: 6px 0 12px; }
code { font: 12px var(--mono); background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
kbd { font: 11px var(--mono); color: var(--muted); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--accent-ink); font-weight: 700; margin: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Controls */
button, input, textarea, select { font: inherit; color: var(--ink); }
button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
button:hover:not(:disabled) { background: var(--surface-3); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.small { height: 28px; padding: 0 10px; font-size: 12px; }
button.primary { background: var(--primary-bg); color: var(--primary-ink); border-color: var(--primary-bg); }
button.primary:hover:not(:disabled) { background: var(--primary-bg); opacity: .88; }
button.primary kbd, button.primary .kbd-hint { background: transparent; color: inherit; opacity: .6; border-color: currentColor; }
button.approve { background: var(--good); border-color: var(--good); color: #fff; }
button.approve:hover:not(:disabled) { background: var(--good); opacity: .9; }
button.danger-outline { color: var(--bad-ink); }
button.danger-outline:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--ink); }
.icon-button { width: 30px; height: 30px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.icon-button:hover:not(:disabled) { color: var(--ink); }
.icon-button.bordered { width: 34px; height: 34px; border-color: var(--line-strong); background: var(--surface); }
input, select, textarea { border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); padding: 0 10px; font-size: 13px; }
input, select { height: 34px; min-width: 0; }
textarea { padding: 8px 10px; resize: vertical; width: 100%; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button:focus-visible, a:focus-visible, summary:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
input[readonly] { background: var(--surface-3); color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar.end { justify-content: flex-end; }
.push-right { margin-left: auto; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 16px; height: 56px; padding: 0 max(20px, calc((100vw - 1400px) / 2)); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 20px; height: 20px; color: var(--accent); }
.brand-tag { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 999px; padding: 1px 8px; }
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 12px; flex: 0 0 auto; }
.who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.who strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { font-size: 11px; color: var(--muted); }
main { max-width: 1440px; margin: auto; padding: 28px 20px 40px; }
.heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 20px; }
.heading p.muted { margin-bottom: 0; }

/* Notices */
.notice { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; margin-bottom: 16px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); font-size: 13px; }
.notice #notice { flex: 1; overflow-wrap: anywhere; }
.notice.success { border-left-color: var(--good); }
.notice.error { border-left-color: var(--bad); background: linear-gradient(var(--bad-soft), var(--bad-soft)), var(--surface); }
.notice.progress #notice::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; vertical-align: -1px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* View tabs */
.views { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.views button { height: 38px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 0 12px; margin-bottom: -1px; }
.views button:hover:not(:disabled) { background: none; color: var(--ink); }
.views button.active { color: var(--ink); border-bottom-color: var(--accent); }

/* Browse */
.browse-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.collections { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); }
.collections button { height: 30px; border: 0; border-radius: 6px; background: none; color: var(--muted); }
.collections button.active { background: var(--surface-3); color: var(--ink); box-shadow: var(--shadow); }
.count { font-size: 11px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.count:empty { display: none; }
.count .pending { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--warn-soft); color: var(--warn-ink); }
.filters { display: flex; gap: 8px; align-items: center; flex: 1; justify-content: flex-end; min-width: min(100%, 320px); }
.search { position: relative; display: flex; align-items: center; flex: 1; max-width: 420px; }
.search .icon { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding-left: 32px; padding-right: 30px; }
.search kbd { position: absolute; right: 8px; pointer-events: none; }
.search input:focus + kbd, .search input:not(:placeholder-shown) + kbd { display: none; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr); gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 0; }
.panel.pad { padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 12px; }
.panel-head code { background: none; padding: 0; color: var(--muted); }
.table-panel { overflow: hidden; }
.table-scroll { overflow: auto; max-height: calc(100vh - 300px); min-height: 240px; overscroll-behavior: contain; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted); font: 600 11px var(--mono); text-transform: none; letter-spacing: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
#records tr { cursor: pointer; }
#records tr:hover td { background: var(--hover); }
#records tr.selected td { background: var(--accent-soft); }
#records tr.selected td:first-child { box-shadow: inset 3px 0 var(--accent); }
#records tr:focus-visible { outline-offset: -2px; }
.key-cell { font: 12px var(--mono); color: var(--accent-ink); white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.name-cell { font-weight: 550; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-cell small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.date-cell { color: var(--muted); white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.version-cell { font: 11px var(--mono); color: var(--muted); }
.tags { display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; max-width: 220px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-soft); color: var(--good-ink); }
.pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill.bad { background: var(--bad-soft); color: var(--bad-ink); }
.empty-row td { text-align: center; padding: 48px 12px; color: var(--muted); cursor: default; }
.skeleton td::after { content: ""; display: block; height: 10px; border-radius: 4px; background: var(--surface-3); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; }
.pager-buttons { display: flex; gap: 6px; margin-left: auto; }

/* Editor */
.editor { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.empty-state { display: grid; justify-items: center; text-align: center; padding: 64px 24px; }
.empty-state .icon { width: 28px; height: 28px; color: var(--muted); margin-bottom: 4px; }
.empty-state p { margin: 2px 0; }
#edit { padding: 16px 18px 18px; }
.editor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.editor-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.editor-title h2 { margin: 0; font: 600 15px var(--mono); overflow-wrap: anywhere; }
.dirty { font-size: 11px; font-weight: 600; color: var(--warn-ink); }
.dirty::before { content: "● "; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 14px; font-size: 12px; }
.meta div { display: flex; gap: 5px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; }
.meta dd.mono { font: 11px/1.6 var(--mono); }
.editor-tabs { display: flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--surface-3); margin-bottom: 14px; width: max-content; }
.editor-tabs button { height: 26px; border: 0; background: none; color: var(--muted); padding: 0 12px; font-size: 12px; border-radius: 5px; }
.editor-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label { font-size: 12px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; gap: 8px; }
.field > label .muted { font-weight: 400; }
.field input:not([type=checkbox]), .field textarea { width: 100%; }
.field textarea { min-height: 76px; }
.field-hint { font-size: 11.5px; color: var(--muted); margin: 0; }
.field-hint.error { color: var(--bad-ink); }
.checks { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.readonly-list { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin: 0; }
#json-view label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; }
#record-value, #sql { font: 12px/1.6 var(--mono); tab-size: 2; white-space: pre; }
#record-value { min-height: 340px; }
#record-value.invalid { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.review { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.review p { margin: 0 0 8px; font-size: 12.5px; }
.review .toolbar { margin-top: 10px; }
.actions { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.actions #delete { margin-left: auto; }

/* Structure and SQL */
.schema-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 16px; align-items: start; }
.schema-list { display: grid; gap: 10px; }
.schema-list pre { margin: 4px 0 0; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.6 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--ink-2); }
.data-table.compact td, .data-table.compact th { padding: 7px 10px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.query-head p { margin-top: 0; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 12px; }
#sql { min-height: 130px; margin-bottom: 10px; }
.inline-error { margin: 12px 0 0; padding: 8px 12px; border-radius: 7px; background: var(--bad-soft); color: var(--bad-ink); font-size: 13px; overflow-wrap: anywhere; }
.result-scroll { margin-top: 12px; max-height: 60vh; min-height: 0; border: 1px solid var(--line); border-radius: 8px; }
.result-scroll:has(table:empty) { display: none; }
.sql-cell { white-space: pre-wrap; min-width: 100px; max-width: 520px; overflow-wrap: anywhere; font: 12px/1.5 var(--mono); vertical-align: top; }
.sql-cell.null { color: var(--muted); font-style: italic; }

/* Help and dialog */
.help { margin-top: 20px; max-width: 900px; font-size: 13px; color: var(--muted); }
.help summary { cursor: pointer; font-weight: 600; color: var(--ink-2); width: max-content; }
.help ul { margin: 8px 0 0; padding-left: 20px; }
.help li { margin: 3px 0; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 32px)); padding: 22px; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: #0007; backdrop-filter: blur(2px); }
dialog h2 { font-size: 17px; }
.push-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.push-stats div { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.push-stats strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.push-stats span { font-size: 12px; color: var(--muted); }

/* Embedded in the administrators' dashboard tab */
.embedded body { background: var(--page); }
.embedded .topbar, .embedded .heading .eyebrow, .embedded .heading p.muted { display: none; }
.embedded main { max-width: none; padding: 16px 16px 24px; }
.embedded h1 { font-size: 20px; }
.embedded .heading { align-items: center; margin-bottom: 14px; }
.embedded .editor { top: 12px; max-height: calc(100vh - 24px); }
.embedded .table-scroll { max-height: calc(100vh - 250px); }

/* Sign-in page (shared stylesheet) */
.login { max-width: 400px; margin: 14vh auto; padding: 32px; border: 0; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-lg); }
.login label { display: block; font-size: 12px; font-weight: 600; margin: 16px 0 6px; }
.login input { width: 100%; height: 40px; }
.login button { margin-top: 16px; width: 100%; height: 40px; }
#error { color: var(--bad-ink); overflow-wrap: anywhere; font-size: 13px; }

@media (max-width: 1000px) {
  .workspace, .schema-grid { grid-template-columns: minmax(0, 1fr); }
  .editor { position: static; max-height: none; }
  .table-scroll { max-height: 420px; }
  .wide { display: none; }
}
@media (max-width: 700px) {
  .topbar { padding: 0 16px; }
  .who small, #logout span, .brand-tag { display: none; }
  main { padding: 20px 16px 32px; }
  .heading { display: block; }
  .file-actions { margin-top: 14px; }
  h1 { font-size: 23px; }
  .collections { width: 100%; }
  .collections button { flex: 1; padding: 0 6px; }
  .filters { min-width: 100%; }
  .search { max-width: none; }
  .search kbd, .hint, .kbd-hint { display: none; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .login { margin: 8vh 16px; padding: 24px; }
  .push-stats strong { font-size: 18px; }
}
