:root {
  color-scheme: light;
  --bg: #ececee;
  --panel: #e2e2e5;
  --surface: #ffffff;
  --fg: #1d1d1f;
  --muted: #6e6e75;
  --border: #c8c8cd;
  --border-strong: #a5a5ad;
  --hover: rgba(0, 0, 0, 0.06);
  --accent: #1f6feb;
  --accent-fg: #ffffff;
  --danger: #c62828;
  --ok: #2e7d32;
  --gutter: #f3f3f5;
  --gutter-fg: #9a9aa2;
  --sel: rgba(31, 111, 235, 0.2);

  --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", "DejaVu Sans Mono", "Liberation Mono", Consolas, monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --side-w: 60px;
  --bar-h: 32px;
  --status-h: 26px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #18181b;
    --panel: #1f1f23;
    --surface: #121215;
    --fg: #e6e6e9;
    --muted: #8d8d96;
    --border: #2f2f35;
    --border-strong: #4a4a52;
    --hover: rgba(255, 255, 255, 0.06);
    --accent: #4c8dff;
    --accent-fg: #ffffff;
    --danger: #ff6b6b;
    --ok: #5fbf6a;
    --gutter: #17171a;
    --gutter-fg: #5b5b64;
    --sel: rgba(76, 141, 255, 0.32);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #18181b;
  --panel: #1f1f23;
  --surface: #121215;
  --fg: #e6e6e9;
  --muted: #8d8d96;
  --border: #2f2f35;
  --border-strong: #4a4a52;
  --hover: rgba(255, 255, 255, 0.06);
  --accent: #4c8dff;
  --accent-fg: #ffffff;
  --danger: #ff6b6b;
  --ok: #5fbf6a;
  --gutter: #17171a;
  --gutter-fg: #5b5b64;
  --sel: rgba(76, 141, 255, 0.32);
}

* {
  box-sizing: border-box;
  border-radius: 0 !important;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.4 var(--ui);
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  height: 24px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: var(--hover); }
button:disabled { opacity: 0.4; cursor: default; background: transparent; }

.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.primary:hover { background: var(--accent); filter: brightness(1.1); }

input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }

code { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.hint { margin: 0 0 8px; font-size: 12px; }
.err { color: var(--danger); }

/* ---------- dialogs ---------- */

.dlg {
  width: min(680px, 92vw);
  max-height: 82vh;
  padding: 0;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--fg);
}

.dlg[open] { display: flex; flex-direction: column; }
.dlg::backdrop { background: rgba(0, 0, 0, 0.35); }
.dlg-wide { width: min(1000px, 95vw); }
.dlg-narrow { width: min(480px, 92vw); }
.dlg form { display: contents; }

.dlg-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding-left: 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.dlg-head h2 { flex: 1; margin: 0; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-x { width: 36px; height: 35px; padding: 0; font-size: 16px; }
.dlg-x:hover { background: var(--danger); color: #fff; }
.dlg-body { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; }

.dlg-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.dlg-foot button { height: 28px; padding: 0 14px; border-color: var(--border); }
.dlg-foot .primary { border-color: var(--accent); }
.msg { flex: 1; color: var(--muted); font-size: 12px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* rows of an editable list: drag handle, small checkbox with a label */
.drag-handle { color: var(--muted); text-align: center; cursor: grab; user-select: none; }
.check { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* right-click menu (shared/menu.js) */

.ctx-menu {
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.ctx-item { height: 28px; padding: 0 12px; text-align: left; }
.ctx-item.danger { color: var(--danger); }
.ctx-item:hover, .ctx-item:focus-visible { background: var(--hover); outline: none; }
