/* Palettes: onedarkbleak.nvim — light = "light", dark = "bleak" */
:root {
  color-scheme: light;
  --bg: #f5efe2;
  --panel: #faf6ee;
  --soft: #f0e8d6;
  --canvas: #f5efe2;
  --dot: #dccfb4;
  --line: #e6dcc6;
  --line2: #dccfb4;
  --hover: #f0e8d6;
  --fg: #1c1812;
  --muted: #5e5440;
  --faint: #8a7e60;
  --accent: #3a4658;
  --accent-fg: #faf6ee;
  --accent-soft: #e5e0d2;
  --err: #7a2e22;
  --warn: #7e5414;
  --sel: rgba(58, 70, 88, .18);
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 14px rgba(60, 40, 10, .06);
  --box-shadow: drop-shadow(0 1px 1px rgba(60, 40, 10, .06)) drop-shadow(0 4px 7px rgba(60, 40, 10, .06));
  --tok-tbl: #a25a00;
  --tok-type: #2b5c94;
  --tok-flag: #b0392a;
  --tok-arrow: #4a7d12;
  --tok-ref: #4a7d12;
  --tok-com: #8a7e60;
  --edge: #5e5440;
  --box-bg: #fffcf5;
  --box-head: #fffcf5;
  --box-head-fg: #1c1812;
  --box-border: #d3cab2;
  --dv-s: 70%; --dv-l: 84%; /* data view row colours: saturation and lightness (the hue varies) */
  --key-l: .52; --key-c: .16; /* key colours (PK/FK badges, key dots): OKLCH lightness and chroma */
  --row-hover: #f5efe2;
  --toast: #1c1812;
  --toast-fg: #faf6ee;

  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --code-size: 13px; /* editor text size, set from the Text menu */
  --code-lh: 20px;
}
/* Dark: follow the system unless the user picked light, or when the user picked dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101012;
    --panel: #1b1c1e;
    --soft: #232427;
    --canvas: #141414;
    --dot: #2c2d31;
    --line: #2c2d31;
    --line2: #35363b;
    --hover: #2c2d31;
    --fg: #d4ccbf;
    --muted: #a8a8a4;
    --faint: #5a5b5e;
    --accent: #8ab1c8;
    --accent-fg: #141414;
    --accent-soft: #1f2a31;
    --err: #c4928e;
    --warn: #c8a878;
    --sel: rgba(138, 177, 200, .25);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
    --box-shadow: drop-shadow(0 1px 1px rgba(0, 0, 0, .4)) drop-shadow(0 6px 9px rgba(0, 0, 0, .35));
    --tok-tbl: #c8a878;
    --tok-type: #8ab1c8;
    --tok-flag: #d4a8a0;
    --tok-arrow: #a8c896;
    --tok-ref: #a8c896;
    --tok-com: #6e6f72;
    --edge: #818387;
    --box-bg: #1b1c1e;
    --box-head: #1b1c1e;
    --box-head-fg: #d4ccbf;
    --box-border: #37383d;
    --dv-s: 40%; --dv-l: 32%; --key-l: .74; --key-c: .085;
    --row-hover: #232427;
    --toast: #d4ccbf;
    --toast-fg: #141414;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101012;
  --panel: #1b1c1e;
  --soft: #232427;
  --canvas: #141414;
  --dot: #2c2d31;
  --line: #2c2d31;
  --line2: #35363b;
  --hover: #2c2d31;
  --fg: #d4ccbf;
  --muted: #a8a8a4;
  --faint: #5a5b5e;
  --accent: #8ab1c8;
  --accent-fg: #141414;
  --accent-soft: #1f2a31;
  --err: #c4928e;
  --warn: #c8a878;
  --sel: rgba(138, 177, 200, .25);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  --box-shadow: drop-shadow(0 1px 1px rgba(0, 0, 0, .4)) drop-shadow(0 6px 9px rgba(0, 0, 0, .35));
  --tok-tbl: #c8a878;
  --tok-type: #8ab1c8;
  --tok-flag: #d4a8a0;
  --tok-arrow: #a8c896;
  --tok-ref: #a8c896;
  --tok-com: #6e6f72;
  --edge: #818387;
  --box-bg: #1b1c1e;
  --box-head: #1b1c1e;
  --box-head-fg: #d4ccbf;
  --box-border: #37383d;
  --dv-s: 40%; --dv-l: 32%; --key-l: .74; --key-c: .085;
  --row-hover: #232427;
  --toast: #d4ccbf;
  --toast-fg: #141414;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 13px/1.4 var(--font); color: var(--fg); background: var(--bg);
  display: flex; flex-direction: column; -webkit-font-smoothing: antialiased;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.spacer { flex: 1; }
.ico { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.thin { stroke-width: 1.4; }
.vsep { width: 1px; height: 20px; background: var(--line); flex: none; }
.vsep.sm { height: 18px; margin: 0 2px; }
[hidden] { display: none !important; }

/* Scrollbars in the app's palette: thin, a thumb in the border colour, no track.
   Chrome and Firefox use the standard properties; Safari uses the -webkit- ones. */
* { scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
*:hover { scrollbar-color: var(--faint) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
}
.icon-btn.sm { width: 30px; height: 30px; border-radius: 7px; }
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.btn-primary {
  height: 32px; display: flex; align-items: center; gap: 7px; padding: 0 12px;
  border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-fg); font-weight: 500;
}
.btn-primary .chev { opacity: .8; margin-left: -2px; }
#exportBtn { padding: 0 10px 0 12px; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .45; cursor: default; filter: none; }
.btn-outline {
  height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); font-size: 12.5px;
}
.btn-outline:hover { background: var(--hover); }
.select {
  appearance: none; -webkit-appearance: none; height: 32px; padding: 0 32px 0 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 13px; cursor: pointer;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%238a857c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 9px center;
}
.select:hover { border-color: var(--line2); }

/* segmented control: soft track, active item raised */
.seg { display: flex; padding: 2px; gap: 2px; background: var(--soft); border-radius: 8px; }
.seg button {
  height: 26px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font-weight: 500; font-size: 12.5px;
}
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
/* Simple / SQL: the chosen one filled, so it reads as a switch between the two */
#modeSeg { border: 1px solid var(--line2); }
#modeSeg button.on { background: var(--accent); color: var(--accent-fg); box-shadow: none; }
#modeSeg button:not(.on):hover { background: var(--hover); }
.icon-seg button { width: 30px; padding: 0; display: grid; place-items: center; }
.icon-seg .fill { fill: currentColor; stroke: none; opacity: .35; }
/* in the canvas toolbar the editor-width buttons look like its other tools */
.card .icon-seg { background: transparent; padding: 0; }
.card .icon-seg button { height: 30px; border-radius: 7px; }
.card .icon-seg button:hover { background: var(--hover); }
.card .icon-seg button.on { background: var(--accent-soft); color: var(--accent); box-shadow: none; }

/* editor collapsed: the canvas takes the whole width */
body.panel-collapsed #left, body.panel-collapsed #split { display: none; }

/* ─── App bar ─────────────────────────────────────────────────────────────── */
.appbar {
  height: 52px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 32px; height: 32px; flex: none; display: block; }
/* narrow screens: drop the toolbar labels (the buttons keep their tooltips) */
@media (max-width: 760px) { .appbar .tool .lbl { display: none; } .appbar .tool { padding: 0 8px; } }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 38px; width: 230px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 5px; display: flex; flex-direction: column; gap: 1px;
}
.menu-label { padding: 6px 9px 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.menu button {
  display: flex; justify-content: space-between; align-items: center; height: 32px; padding: 0 9px;
  border: 0; background: transparent; border-radius: 6px; text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu .ext { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.menu-sep { height: 1px; background: var(--line); margin: 4px; }
.menu-left { right: auto; left: 0; width: 220px; }
.ctx-menu { position: fixed; right: auto; width: auto; min-width: 200px; outline: none; }
.ctx-menu button { gap: 24px; }
.menu button.danger { color: var(--err); }
.menu button:disabled { opacity: .4; cursor: default; background: transparent; }
#themeList, #notationList, #dataLangList { display: flex; flex-direction: column; gap: 1px; }
#themeList button, #notationList button, #dataLangList button { justify-content: flex-start; gap: 8px; width: 100%; }
#themeList .check, #notationList .check, #dataLangList .check { width: 12px; color: var(--accent); font-weight: 600; }
#themeList .theme-name, #notationList .item-name, #dataLangList .item-name { flex: 1; }
.swatches { display: flex; gap: 3px; }
.swatches i { width: 10px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(128, 128, 128, .25); }
.size-row { display: flex; align-items: center; gap: 4px; padding: 2px 5px 4px 9px; }
.size-row .scheme-name { flex: 1; }
.menu .size-row button { width: 28px; height: 28px; padding: 0; justify-content: center; border-radius: 6px; }
.menu .size-row button:disabled { opacity: .35; cursor: default; background: transparent; }
.menu .switch-row { width: 100%; justify-content: space-between; padding: 0 9px; }
.switch { width: 30px; height: 18px; border-radius: 9px; background: var(--line2); position: relative; flex: none; transition: background .15s; }
.switch i { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--panel); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: left .15s; }
.switch-row[aria-checked="true"] .switch { background: var(--accent); }
.switch-row[aria-checked="true"] .switch i { left: 14px; }
#sizeLabel { min-width: 44px; text-align: center; font: 12px var(--mono); color: var(--muted); }

/* Theme menu: Auto / Light / Dark above the themes (it stays open, so you see the change) */
.menu .mode-pick { margin: 2px 4px 2px; }
.menu .mode-pick button { flex: 1; justify-content: center; height: 26px; padding: 0 8px; }
.menu .mode-pick button[aria-checked="true"] { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* ─── Tabs ─────────────────────────────────────────────────────────────────── */
.tabbar {
  height: 38px; flex: none; display: flex; align-items: center; gap: 4px; padding: 0 8px 0 10px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
/* the tabs stand on the bar's bottom line; the open one is the panel below, so the line stops under it */
.tabs { display: flex; align-items: flex-end; align-self: stretch; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  height: 31px; display: flex; align-items: center; gap: 4px; padding: 0 4px 0 12px; flex: none; margin-bottom: -1px;
  border-radius: 8px 8px 0 0; color: var(--muted); font-size: 12.5px; font-weight: 500; cursor: pointer;
  max-width: 180px; outline: none; border: 1px solid transparent; border-bottom: 0;
}
.tab:hover { background: var(--hover); color: var(--fg); }
.tab.on { background: var(--panel); color: var(--fg); border-color: var(--line); height: 32px; }
.tab:focus-visible { border-color: var(--accent); }
.tab-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-close {
  width: 20px; height: 20px; display: grid; place-items: center; flex: none; padding: 0;
  border: 0; border-radius: 5px; background: transparent; color: var(--faint); opacity: 0;
}
.tab:hover .tab-close, .tab.on .tab-close { opacity: 1; }
.tab-close:hover { background: var(--line); color: var(--fg); }
.tab-scroll { width: 26px; height: 26px; border-radius: 6px; flex: none; }
.tab-scroll:disabled { opacity: .3; }

.tab-rename {
  flex: 1; min-width: 0; height: 22px; padding: 0 6px; border: 1px solid var(--accent); border-radius: 5px;
  background: var(--box-bg); color: var(--fg); font: 500 12.5px var(--font); outline: none;
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */
main { flex: 1; display: flex; min-height: 0; }
#left {
  width: 420px; flex: none; display: flex; flex-direction: column; min-width: 0;
  background: var(--panel); position: relative;
}
#split {
  width: 9px; margin: 0 -4px; flex: none; cursor: col-resize; position: relative; z-index: 6;
  display: flex; justify-content: center;
}
#split i { width: 1px; height: 100%; background: var(--line); }
#split.active i { background: var(--accent); }
#right { flex: 1; min-width: 0; position: relative; overflow: hidden; container: canvas / inline-size; }

/* ─── Editor ──────────────────────────────────────────────────────────────── */
.editor-head {
  height: 46px; flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 12px; border-bottom: 1px solid var(--line);
  container-type: inline-size;
}
/* with the database menu beside SQL, a narrow editor keeps just the ? of Syntax */
@container (max-width: 470px) {
  .editor-head:has(#dialectWrap:not([hidden])) .help-btn { padding: 0 8px; }
  .editor-head:has(#dialectWrap:not([hidden])) .help-btn .lbl { display: none; }
}
#dialectBtn { font-size: 12.5px; color: var(--muted); padding: 0 6px 0 9px; }
#dialectBtn:hover, #dialectBtn[aria-expanded="true"] { color: var(--fg); }
#dialectMenu { width: 180px; }
.help-btn {
  height: 30px; display: flex; align-items: center; gap: 6px; padding: 0 10px 0 8px;
  border: 0; border-radius: 7px; background: transparent; color: var(--muted);
  font-size: 12.5px; font-weight: 500;
}
.help-btn:hover { background: var(--hover); color: var(--fg); }
.help-btn.on { background: var(--accent-soft); color: var(--accent); }
.help-btn .q {
  width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid currentColor;
  display: grid; place-items: center; font-size: 10px; font-weight: 600; line-height: 1;
}

/* the diagram's name, above its text */
.docname { flex: none; padding: 10px 12px 6px 18px; }
#docName {
  width: 100%; height: 30px; padding: 0 8px; margin-left: -8px; border: 1px solid transparent; border-radius: 7px;
  background: transparent; color: var(--fg); font: 600 14.5px var(--font); letter-spacing: -.01em; outline: none;
}
#docName:hover { border-color: var(--line); }
#docName:focus { border-color: var(--accent); background: var(--box-bg); }
#docName::placeholder { color: var(--faint); }

/* a transparent textarea over a highlighted <pre> */
.editor { flex: 1; display: flex; min-height: 0; position: relative; }
.gutter {
  width: 46px; flex: none; overflow: hidden; padding: 14px 0 214px; text-align: right;
  font: calc(var(--code-size) - 1px)/var(--code-lh) var(--mono); color: var(--faint); user-select: none; background: var(--panel);
}
.gutter div { height: var(--code-lh); padding-right: 12px; }
.gutter div.error { color: var(--err); font-weight: 600; }
.gutter div.warn { color: var(--warn); font-weight: 600; }
.code { flex: 1; position: relative; min-width: 0; }
.code pre, .code textarea {
  position: absolute; inset: 0; margin: 0; padding: 14px 16px 14px 6px;
  font: var(--code-size)/var(--code-lh) var(--mono); white-space: pre; tab-size: 2; border: 0; overflow: auto;
}
/* the gutter and the highlight layer get room to scroll as far as the textarea can
   (its horizontal scrollbar adds to its scroll height), so lines never drift apart */
.code pre { overflow: hidden; pointer-events: none; color: var(--fg); padding-bottom: 214px; }
/* both layers keep the same room for a scrollbar, so wrapped lines break at the same place */
.code pre, .code textarea { scrollbar-gutter: stable; }
#hl > div { min-height: var(--code-lh); }
.code.wrap pre, .code.wrap textarea { white-space: pre-wrap; overflow-wrap: anywhere; }
.code textarea { background: transparent; color: transparent; caret-color: var(--fg); resize: none; outline: none; }
.code textarea::selection { background: var(--sel); }
/* suggestions while typing (complete.js) */
.complete {
  position: fixed; z-index: 35; min-width: 180px; max-width: 360px; max-height: 232px; overflow: auto; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.cpl-item {
  display: flex; align-items: center; gap: 14px; height: 26px; padding: 0 8px; border-radius: 5px;
  font: 12.5px var(--mono); white-space: nowrap; cursor: pointer;
}
.cpl-item .hint { margin-left: auto; font: 11.5px var(--font); color: var(--muted); }
.cpl-item.on { background: var(--accent); color: var(--accent-fg); }
.cpl-item.on .hint { color: inherit; opacity: .75; }
.h-tbl { color: var(--fg); } /* plain: the colours in the editor belong to the keys */
.h-col { color: var(--fg); }
.h-type { color: var(--tok-type); }
.h-flag, .h-kw { color: var(--tok-flag); }
.h-arrow { color: var(--tok-arrow); }
.h-ref { color: var(--tok-ref); }
.h-hue { color: oklch(var(--key-l) var(--key-c) var(--h)); } /* a key's colour, as in the diagram */
.h-com { color: var(--tok-com); }
.h-str { color: var(--tok-arrow); }
.h-error { text-decoration: underline wavy var(--err); text-decoration-skip-ink: none; }
.h-warn { text-decoration: underline wavy var(--warn); text-decoration-skip-ink: none; }

/* syntax reference: covers the editor, not its header or status bar */
#help {
  container-type: inline-size;
  position: absolute; inset: 0; background: var(--panel); overflow: auto; z-index: 5;
  padding: 18px 20px 28px; display: flex; flex-direction: column; gap: 14px; line-height: 1.55;
}
.help-head { display: flex; align-items: center; gap: 8px; }
.help-title { font-weight: 600; font-size: 14px; }
.help-code {
  margin: 0; padding: 12px 14px; background: var(--soft); border-radius: 8px;
  font-family: var(--mono); color: var(--fg);
  /* the longest line is ~36 characters (≈ 22em): shrink a little in a narrow editor so it
     still fits; below 10px it wraps instead. Never scrollbars. */
  font-size: clamp(10px, calc((100cqi - 70px) / 22), 12px); line-height: 1.65;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: baseline; }
.help-grid code { font: 12px var(--mono); }
.help-grid b { font-weight: 600; }
.hsep { height: 1px; background: var(--line); flex: none; }
.help-keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; color: var(--muted); }
.help-keys span:nth-child(odd) { color: var(--fg); }
.t-com { color: var(--tok-com); }
.t-tbl { color: var(--tok-tbl); }
.t-type { color: var(--tok-type); }
.t-flag { color: var(--tok-flag); }
.t-arrow { color: var(--tok-arrow); }

.statusbar {
  height: 32px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); min-width: 0;
}
.status {
  display: flex; align-items: center; gap: 7px; border: 0; background: transparent; padding: 0;
  min-width: 0; color: inherit; cursor: default; font-size: 12px;
}
.status.has-problems { cursor: pointer; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.status.error .dot { background: var(--err); }
.status.error .status-text { color: var(--err); }
.status.warn .dot { background: var(--warn); }
.status.warn .status-text { color: var(--warn); }
.status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status .chev { display: none; flex: none; transition: transform .15s; }
.status.has-problems .chev { display: block; }
.status[aria-expanded="true"] .chev { transform: rotate(180deg); }

/* all problems, expanded from the status bar; click one to jump to its line */
.problem-list {
  flex: none; max-height: 40%; overflow: auto; padding: 4px; border-top: 1px solid var(--line);
  background: var(--panel); font-size: 12.5px; line-height: 1.45;
}
.problem {
  display: grid; grid-template-columns: 7px auto 1fr; gap: 8px; align-items: baseline; width: 100%;
  padding: 5px 8px; border: 0; border-radius: 6px; background: transparent; text-align: left; color: var(--fg);
}
.problem:hover { background: var(--hover); }
.problem .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--err); transform: translateY(-1px); }
.problem.warn .dot { background: var(--warn); }
.problem .where { font: 11.5px var(--mono); color: var(--muted); white-space: nowrap; }
.problem-row { display: flex; align-items: center; gap: 6px; }
.problem-row .problem { flex: 1; min-width: 0; }
/* a problem that one click fixes: Create table X */
.fix-btn { flex: none; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
.problem-row .fix-btn { margin-right: 4px; }
.summary { white-space: nowrap; }

/* ─── Canvas ──────────────────────────────────────────────────────────────── */
#canvas {
  width: 100%; height: 100%; display: block; background-color: var(--canvas);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.3px);
  touch-action: none; user-select: none;
}
#canvas .tbl { cursor: grab; }
#canvas .tbl .row { cursor: pointer; }
#canvas.panning, #canvas.dragging, #canvas.dragging .tbl, #canvas.dragging .row { cursor: grabbing; }

.card {
  position: absolute; display: flex; align-items: center; gap: 2px; padding: 4px; z-index: 4;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.card-tl { top: 12px; left: 12px; }
.card-br { right: 12px; bottom: 12px; }
.card-tr { top: 12px; right: 12px; }
.card-text { padding: 0 2px 0 8px; color: var(--muted); white-space: nowrap; }
@media (max-width: 760px) { .card-text { display: none; } } /* room for the top-left card */
/* Presentation mode: only the canvas and its zoom controls */
body.presenting .appbar, body.presenting .tabbar, body.presenting #left, body.presenting #split,
body.presenting .card-tl, body.presenting #storageNotice, body.presenting #selectHint { display: none; }
.tool {
  height: 30px; display: flex; align-items: center; gap: 6px; padding: 0 11px 0 9px;
  border: 0; border-radius: 7px; background: transparent; font-weight: 500; white-space: nowrap;
}
.tool:hover { background: var(--hover); }
.tool.on { background: var(--accent-soft); color: var(--accent); }
.tool.icon { width: 30px; padding: 0; justify-content: center; }
/* the finder (the magnifier in the app bar, ⌘F / ⌘K): a table or column by name; the view goes to it.
   It drops down from the magnifier, in the app bar's right corner; while presenting (no app bar) it floats over the canvas. */
.find-slot { position: relative; }
#findBtn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
.finder {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: 340px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.finder.floating { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 40; width: min(380px, calc(100% - 24px)); }
.finder input {
  width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--box-bg); font-size: 13px;
}
.finder input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.find-list { max-height: 360px; overflow: auto; margin-top: 4px; display: flex; flex-direction: column; gap: 1px; }
.find-list:empty { display: none; }
.find-item {
  display: flex; align-items: center; gap: 12px; flex: none; height: 30px; padding: 0 9px;
  border: 0; border-radius: 6px; background: none; text-align: left; font: 12.5px var(--mono);
}
.find-item .where { margin-left: auto; font: 11.5px var(--font); color: var(--muted); white-space: nowrap; }
.find-item b { font-weight: 600; color: var(--accent); }
.find-item.on { background: var(--hover); }
.find-empty { padding: 8px 9px; color: var(--muted); font-size: 12.5px; }
.zoom-label { min-width: 50px; justify-content: center; padding: 0; font: 12px var(--mono); color: var(--muted); }
.zoom-label:hover { color: var(--fg); }
#notationBtn.er { color: var(--warn); }
#notationIco { display: flex; }
.notation-ico text { font: 600 9px var(--mono); fill: currentColor; stroke: none; }
.notation-ico text.big { font-size: 12px; }
.notation-ico text[text-anchor] { font-size: 8px; letter-spacing: -.04em; }

/* the note explaining why ER notation doesn't fit SQL tables */
.note {
  position: absolute; top: 12px; right: 12px; z-index: 9; width: 400px; max-width: calc(100% - 24px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 14px 16px; font-size: 12.5px; line-height: 1.55; max-height: calc(100% - 120px); overflow: auto;
}
.note-title { font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.note p { margin: 0 0 8px; color: var(--muted); }
.note b { color: var(--fg); font-weight: 600; }
.note ul { margin: 0 0 8px; padding-left: 18px; color: var(--muted); }
.note li { margin-bottom: 3px; }
.note code { font: 11.5px var(--mono); color: var(--tok-flag); }
.note-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.note-actions .btn-outline, .note-actions .btn-primary { height: 30px; border-radius: 7px; }


.empty {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  text-align: center; color: var(--muted); align-content: center; gap: 6px;
}
.empty-title { font-weight: 600; color: var(--fg); font-size: 14px; }
.empty b { font-weight: 600; }
.empty .examples { margin-top: 10px; max-width: 420px; line-height: 1.8; }
.empty .examples button {
  pointer-events: auto; border: 0; background: none; padding: 0; font: inherit;
  color: var(--accent); cursor: pointer;
}
.empty .examples button:hover { text-decoration: underline; }

/* The messages at the bottom of the canvas stand in one column, so that none covers another:
   a toast in the middle, above a notice at the left. The canvas under the column stays usable. */
.canvas-msgs {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 8;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.canvas-msgs > * { pointer-events: auto; }
/* A card over the whole page, when nothing on it may be used: until the app has started
   (#loading), or when the tab is out of date (#outdatedNotice). Nothing in it waits for
   another download, so a slow connection shows it complete. */
.cover {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.cover[hidden] { display: none; }
.cover-card {
  display: flex; align-items: center; gap: 12px; max-width: 420px; padding: 16px 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  color: var(--muted); font-size: 14px; line-height: 1.5;
}
#loading { opacity: 0; animation: loading-in .2s .3s forwards; } /* a fast start never shows it */
#outdatedNotice .cover-card { flex-direction: column; align-items: stretch; gap: 16px; padding: 20px 22px 18px; color: var(--fg); }
#outdatedReload { align-self: flex-end; }
.loading-spin {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--line2); border-top-color: var(--accent); animation: loading-spin .8s linear infinite;
}
@keyframes loading-in { to { opacity: 1; } }
@keyframes loading-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spin { animation-duration: 2.4s; } }
#toast {
  align-self: center; flex: none; margin-bottom: 4px;
  height: 36px; padding: 0 6px 0 14px; border-radius: 9px; background: var(--toast); color: var(--toast-fg);
  display: flex; gap: 10px; align-items: center; font-size: 12.5px; box-shadow: var(--shadow); white-space: nowrap;
}
#toastAct {
  height: 26px; padding: 0 9px; border: 0; border-radius: 6px; background: transparent;
  color: var(--accent); font-weight: 600;
}

/* "only saved in this browser", bottom-left of the canvas until dismissed (the zoom card is at the right) */
.notice {
  align-self: flex-start; max-width: min(520px, calc(100% - 276px)); /* beside the zoom bar */
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  font-size: 12.5px; line-height: 1.45; color: var(--muted);
}
/* a canvas too narrow for a notice beside the zoom bar: the messages go above it, full width */
@container canvas (max-width: 640px) {
  .canvas-msgs { bottom: 60px; }
  .notice { max-width: 100%; }
}
.notice .ico { color: var(--warn); }
.notice b { color: var(--fg); font-weight: 600; }
.notice .btn-outline { flex: none; height: 30px; }

/* small confirmation dialog */
.dlg.confirm { width: 440px; }
.dlg.confirm p { margin: 0 0 18px; color: var(--muted); line-height: 1.55; }
.dlg.confirm b { color: var(--fg); font-weight: 600; }

/* ─── Table dialog ────────────────────────────────────────────────────────── */
.dlg-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40;
  display: grid; place-items: center; padding: 16px;
}
.dlg {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25); padding: 18px 20px;
  width: 780px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto;
}
.dlg h2 { font-size: 14.5px; font-weight: 600; margin: 0 0 14px; letter-spacing: -.01em; }
.dlg input[type=text], .dlg input:not([type]) {
  font: 13px var(--mono); height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--box-bg); color: var(--fg); width: 100%; min-width: 0;
}
.dlg input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dlg input.invalid { border-color: var(--err); outline-color: var(--err); }
.dlg input::placeholder { color: var(--faint); }
.dlg input.c-type::placeholder { color: var(--muted); } /* the type a column gets when none is written: as good as typed */
.field { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-weight: 500; }
.field input { max-width: 280px; }
.col-grid, .col-row {
  display: grid; gap: 6px; align-items: center;
  grid-template-columns: 16px minmax(110px, 1.2fr) minmax(90px, .8fr) 174px minmax(150px, 1.6fr) 28px;
}
.col-head { font-size: 11px; color: var(--muted); padding: 0 0 4px; text-transform: uppercase; letter-spacing: .06em; }
.col-row { padding: 3px 0; }
/* drag a row by its grip to move it */
.grip { display: grid; place-items: center; height: 28px; color: var(--faint); cursor: grab; user-select: none; touch-action: none; }
.grip svg { width: 10px; height: 16px; fill: currentColor; }
.col-row:hover .grip { color: var(--muted); }
.col-row.dragging { margin: 0 -6px; padding: 3px 6px; border-radius: 8px; background: var(--soft); box-shadow: var(--shadow); }
#tdCols.reordering, #tdCols.reordering * { cursor: grabbing; user-select: none; }
/* PK / NULL / UNIQUE / AUTO: filled when on, faint when off (outlined on hover); one that can't apply to the column is left out, in its place */
.c-flags { display: grid; grid-template-columns: 30px 42px 54px 42px; gap: 2px; }
.pill {
  height: 24px; padding: 0; border: 1px solid transparent; border-radius: 12px; background: transparent;
  font: 500 10px var(--mono); letter-spacing: .03em; color: var(--faint);
}
.pill:hover:not(:disabled), .pill:focus-visible { border-color: var(--line2); color: var(--fg); }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.pill[aria-pressed="true"]:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-fg); filter: brightness(1.08); }
.pill:disabled { cursor: default; }
.pill[aria-pressed="true"]:disabled { opacity: .6; } /* on because of the name (Id): not a choice */
.pill.gone { visibility: hidden; }
.c-fk { display: flex; align-items: center; min-width: 0; }
/* what a foreign key points to; its × (not a foreign key) shows on hover */
.fk-chip {
  position: relative; display: flex; min-width: 0; height: 28px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--tok-ref);
}
.fk-chip:hover { background: var(--hover); }
.fk-label {
  font: 12px var(--mono); padding: 0 8px; border: 0; background: none; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fk-unlink {
  position: absolute; right: 2px; top: 2px; width: 22px; height: 22px; padding: 0; line-height: 1;
  border: 0; border-radius: 5px; background: var(--hover); color: var(--muted); opacity: 0;
}
.fk-chip:hover .fk-label, .fk-chip:focus-within .fk-label { padding-right: 28px; } /* room for the × */
.fk-chip:hover .fk-unlink, .fk-chip:focus-within .fk-unlink { opacity: 1; }
.fk-unlink:hover { background: var(--line2); color: var(--fg); }
.c-actions { display: flex; justify-content: flex-end; }
.icon-x {
  width: 28px; height: 28px; padding: 0; line-height: 1; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted);
}
.icon-x:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
.icon-x:disabled { opacity: .35; cursor: default; }
.icon-btn.link { width: 30px; height: 28px; border: 1px solid transparent; border-radius: 7px; color: var(--faint); }
.icon-btn.link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.col-row.fk-open .fk-chip, .col-row.fk-open .icon-btn.link { border-color: var(--accent); color: var(--accent); }
#tdAdd { margin: 8px 0 20px; }
/* why Save didn't: under the field it is about */
.field-error { color: var(--err); font-size: 12.5px; margin: 0 0 6px; }
.field + .field-error { margin: -10px 0 12px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; }
.dlg-actions .btn-outline, .dlg-actions .btn-primary { height: 32px; padding: 0 14px; border-radius: 8px; font-size: 13px; }
.btn-outline.danger { color: var(--err); }
.btn-outline.danger.armed { background: var(--err); border-color: var(--err); color: var(--panel); }

/* foreign-key chooser, opened under a column row */
.fk-panel {
  display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr); gap: 12px;
  margin: 4px 0 10px; padding: 10px; border: 1px solid var(--accent); border-radius: 10px; background: var(--soft);
}
.fk-left, .fk-right { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fk-list {
  height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--box-bg);
  display: flex; flex-direction: column; padding: 3px;
}
.fk-item {
  border: 0; border-radius: 6px; background: none; text-align: left; padding: 5px 8px;
  font: 12.5px var(--mono); flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fk-item:hover { background: var(--hover); }
.fk-item.on { background: var(--accent); color: var(--accent-fg); }
.fk-item em { font-style: normal; opacity: .65; font-family: inherit; }
.fk-item b { font: 600 9.5px var(--mono); color: var(--accent); margin-left: 6px; letter-spacing: .02em; }
.fk-item i { font: italic 11px var(--font); color: var(--warn); margin-left: 6px; }
.fk-item.on i, .fk-item.on b, .fk-item.on .h-hue { color: inherit; }
.fk-empty { color: var(--muted); font-size: 12.5px; padding: 8px; }
.fk-pk { display: flex; align-items: center; gap: 6px; font-size: 13px; height: 30px; cursor: pointer; }
.fk-pk input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.fk-foot { display: flex; align-items: center; gap: 8px; }
.fk-foot .btn-outline, .fk-foot .btn-primary { height: 30px; border-radius: 7px; }
#fkPreview { font: 12.5px var(--mono); color: var(--tok-ref); }
/* the diagram's key colours: a primary key column and its box, an arrow's target, in the chooser the tables and their keys */
.dlg .h-hue, .dlg input.c-name.h-hue, #fkPreview.h-hue { color: oklch(var(--key-l) var(--key-c) var(--h)); }
.dlg .pill.h-hue[aria-pressed="true"] { background: oklch(var(--key-l) var(--key-c) var(--h)); border-color: oklch(var(--key-l) var(--key-c) var(--h)); color: var(--accent-fg); }
