/* ==========================================================================
   DB Portal — harbor-chart palette: ink navy surfaces, periwinkle signal accent,
   amber reserved for "attention" (NULL values, warnings).
   ========================================================================== */
:root {
  --bg: #0d1620;
  --panel: #111c28;
  --panel-2: #172636;
  --line: #22364a;
  --line-soft: #1a2a3a;
  --text: #dce7f1;
  --muted: #8aa0b5;
  --accent: #8ba7ff;
  --accent-strong: #a9bcff;
  --on-accent: #0b1430;
  --amber: #e9b458;
  --danger: #ff8e8e;
  --danger-bg: #3a1c24;
  --ok: #7fd6a5;
  --ok-bg: #133027;
  --focus: #c4d2ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --font-ui: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 6px;
  --sidebar-w: 300px;
  --topbar-h: 52px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --panel-2: #e9eff6;
  --line: #ccd8e4;
  --line-soft: #e0e8f0;
  --text: #14202b;
  --muted: #586d80;
  --accent: #3557d6;
  --accent-strong: #2a47b3;
  --on-accent: #ffffff;
  --amber: #a26a0a;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --ok: #1b6b46;
  --ok-bg: #e2f4ea;
  --focus: #3557d6;
  --shadow: 0 10px 30px rgba(20, 32, 43, .18);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.35rem; font-weight: 650; letter-spacing: -.012em; margin: 0 0 .25rem; line-height: 1.25; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: .75rem 1rem; }
.spacer { flex: 1; }
.lede { color: var(--muted); max-width: 62ch; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .5rem .9rem; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.small { padding: .3rem .65rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: .5rem .65rem; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
label { display: block; font-weight: 550; }
label.inline { display: inline-flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--muted); }
label.inline select { width: auto; max-width: 220px; padding: .3rem .5rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 450; color: var(--muted); font-size: .85rem; }
label.check input { width: auto; }
kbd { font: .75rem var(--font-mono); padding: 1px 5px; border-radius: 4px; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); opacity: .85; }
.chip { display: inline-block; margin-left: .5rem; padding: 0 .45rem; border-radius: 99px; font-size: .75rem; border: 1px solid var(--line); }
.chip.warn { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 55%, transparent); }

.notice { padding: .6rem .8rem; border-radius: var(--radius); border: 1px solid var(--line); margin: 0 0 1rem; }
.notice.error { color: var(--danger); background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.notice.ok { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.notice pre { margin: .4rem 0 0; white-space: pre-wrap; font: .85rem var(--font-mono); }

/* ---------- auth pages ---------- */
.auth-body { display: grid; place-items: center; min-height: 100%; padding: 1.5rem; }
.auth-card {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 1.75rem; box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 1.25rem; }
.stack { display: grid; gap: .9rem; margin-top: 1.1rem; }
.stack label { display: grid; gap: .35rem; }
.code-input { font: 1.6rem var(--font-mono); letter-spacing: .35em; text-align: center; padding: .6rem; }
.subtle-link { color: var(--muted); font-size: .85rem; text-align: center; }

/* ---------- app shell ---------- */
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.app {
  display: grid; height: 100vh; height: 100dvh; overflow: hidden;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 1rem; padding: 0 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar-target { color: var(--muted); font: .82rem var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.topbar-right form { margin: 0; }
.who { color: var(--muted); font-size: .85rem; }

.sidebar { grid-area: side; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.sidebar-head { display: grid; gap: .7rem; padding: .85rem; border-bottom: 1px solid var(--line); }
.search-row { display: flex; gap: .35rem; }
.tree { flex: 1; overflow: auto; padding: .4rem 0 1rem; }

/* tree with guide rails: the vertical rail under each database ties its tables to it */
.tree ul { list-style: none; margin: 0; padding: 0; }
.db-row {
  display: flex; align-items: center; gap: .4rem; width: 100%; padding: .32rem .85rem;
  background: none; border: 0; color: var(--text); font: inherit; font-weight: 550; text-align: left; cursor: pointer;
}
.db-row:hover { background: var(--panel-2); }
.db-row .chev { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2.2; transition: transform .12s ease; }
.db-row[aria-expanded="true"] .chev { transform: rotate(90deg); }
.db-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-row.selected .name { color: var(--accent); }
.db-row.system .name { color: var(--muted); font-weight: 450; }
.tbl-list { margin-left: calc(.85rem + 6px); border-left: 1px solid var(--line); padding: .1rem 0 .3rem; }
.tbl-list a, .tbl-list .note {
  display: flex; align-items: center; gap: .5rem; padding: .22rem .85rem .22rem .9rem; color: var(--text);
  font: .86rem var(--font-mono); text-decoration: none;
}
.tbl-list a:hover { background: var(--panel-2); }
.tbl-list a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.tbl-list .note { color: var(--muted); font-family: var(--font-ui); }
.tbl-list .kind { color: var(--muted); font: .72rem var(--font-ui); margin-left: auto; }
.tbl-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { grid-area: main; overflow: auto; padding: 1.4rem 1.6rem 2.5rem; min-width: 0; }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.view-head .actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.crumb { font-family: var(--font-mono); font-size: 1.2rem; }
.crumb .sep { color: var(--muted); margin: 0 .35em; font-weight: 400; }
.crumb .db { color: var(--muted); font-weight: 500; }

/* ---------- data grid ---------- */
.grid-wrap { overflow: auto; max-height: 68vh; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font: .84rem var(--font-mono); }
table.grid th, table.grid td { padding: .38rem .8rem; text-align: left; border-bottom: 1px solid var(--line-soft); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.grid th {
  position: sticky; top: 0; z-index: 2; background: var(--panel-2); font: 600 .8rem var(--font-ui);
  border-bottom: 1px solid var(--line); color: var(--text);
}
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
table.grid .rownum {
  position: sticky; left: 0; z-index: 1; text-align: right; color: var(--muted); background: var(--panel-2);
  border-right: 1px solid var(--line); min-width: 3.2rem; user-select: none;
}
table.grid th.rownum { z-index: 3; }
table.grid td.num { text-align: right; color: var(--accent-strong); }
table.grid td.null { color: var(--amber); font-style: italic; opacity: .85; }
table.grid td.long { cursor: zoom-in; }
table.grid td.long:hover { text-decoration: underline dotted; }
table.plain td, table.plain th { white-space: normal; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }

.pager { display: flex; align-items: center; gap: .75rem; margin-top: .8rem; flex-wrap: wrap; }
.pager .info { color: var(--muted); font-size: .86rem; }
.pager select { width: auto; padding: .25rem .4rem; }

.section-title { font-size: 1rem; font-weight: 650; margin: 1.6rem 0 .6rem; }
pre.ddl { margin: 0; padding: 1rem; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font: .84rem/1.55 var(--font-mono); }

/* ---------- query editor ---------- */
.editor { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.editor-bar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; padding: .55rem .7rem; border-bottom: 1px solid var(--line); }
.editor textarea {
  display: block; border: 0; border-radius: 0; background: var(--bg); min-height: 190px; resize: vertical;
  font: .9rem/1.55 var(--font-mono); padding: .9rem 1rem; tab-size: 2;
}
.editor textarea:focus { box-shadow: none; }
.editor:focus-within { border-color: var(--accent); }
.editor-foot { padding: .35rem .8rem; font-size: .8rem; border-top: 1px solid var(--line); }
#q-results { margin-top: 1.2rem; display: grid; gap: 1.4rem; }
.result-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .5rem; flex-wrap: wrap; }
.result-head strong { font-weight: 650; }

/* ---------- dialog ---------- */
dialog { width: min(760px, 92vw); max-height: 80vh; padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(3, 8, 14, .6); }
.dialog-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); }
dialog pre { margin: 0; padding: 1rem; overflow: auto; max-height: 62vh; white-space: pre-wrap; word-break: break-word; font: .85rem/1.55 var(--font-mono); }

/* ---------- responsive ---------- */
.only-narrow { display: none; }
.scrim { display: none; }
@media (max-width: 860px) {
  body.app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .only-narrow { display: inline-grid; }
  .topbar-target, .who { display: none; }
  .sidebar { position: fixed; z-index: 30; top: var(--topbar-h); bottom: 0; left: 0; width: min(320px, 86vw); transform: translateX(-102%); transition: transform .18s ease; }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.sidebar-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 20; background: rgba(3, 8, 14, .5); }
  .main { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


/* ---------- role badges, admin users page, invite page ---------- */
.who { display: inline-flex; align-items: center; color: var(--muted); font-size: .85rem; }
.admin-page { height: auto; min-height: 100%; }
.admin-page .topbar { position: sticky; top: 0; z-index: 5; }
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.admin-wrap h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.25rem; margin: 0 0 1.25rem; }
.invite-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.invite-form label { flex: 1 1 200px; display: grid; gap: .3rem; }
.small { font-size: .82rem; }
.table-scroll { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
table.users th { text-align: left; font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
table.users th, table.users td { padding: .55rem .6rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.inline-form { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.inline-form select { width: auto; padding: .25rem .4rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: flex-start; }
.row-actions form { margin: 0; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
details.del > summary { list-style: none; cursor: pointer; }
details.del > summary::-webkit-details-marker { display: none; }
.del-form { display: grid; gap: .5rem; margin-top: .5rem; padding: .6rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); min-width: 220px; }
.linkbox pre { user-select: all; word-break: break-all; margin: .5rem 0; padding: .6rem .7rem; background: var(--bg); color: var(--text); border-radius: var(--radius); border: 1px solid var(--line); }
.qr { display: inline-block; padding: .4rem; background: #fff; border-radius: 8px; line-height: 0; }
.qr svg { width: 210px; height: 210px; display: block; }
.manual-key { font: .85rem var(--font-mono); word-break: break-all; color: var(--text); }













.qr {
  display: inline-block;
  background: #fff;
  padding: 16px;
  border-radius: 8px;
}
.qr svg {
  display: block;
  max-width: none;
  width: auto;
  height: auto;
  filter: none;
  opacity: 1;
  shape-rendering: crispEdges;
}
.qr svg path {
  stroke: #000 !important;
}
.qr svg path:first-child {
  fill: #fff !important;
  stroke: none !important;
}
