/* Magik Table web client — one stylesheet for the client and the admin console. */
:root {
  --accent: #2d7ff9;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 45%, transparent);
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f5;
  --ink: #1d1f25;
  --ink-2: #4b5059;
  --muted: #747a84;
  --faint: #9aa0a8;
  --line: #e1e4e8;
  --line-2: #eceef1;
  --hover: #f1f4f8;
  --selected: color-mix(in srgb, var(--accent) 9%, #ffffff);
  --danger: #d4334a;
  --danger-soft: #fff1f3;
  --ok: #1f7a3c;
  --ok-soft: #ecf9ef;
  --warn: #9a6400;
  --warn-soft: #fff7e6;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-2: 0 6px 24px rgba(16, 24, 40, .12), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-3: 0 18px 50px rgba(16, 24, 40, .22);
  --radius: 8px;
  --radius-lg: 12px;
  --row-h: 34px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15171c;
  --surface: #1d2027;
  --surface-2: #22262e;
  --surface-3: #2a2f38;
  --ink: #e9ebef;
  --ink-2: #c1c6ce;
  --muted: #959ba5;
  --faint: #737a85;
  --line: #333943;
  --line-2: #2b3038;
  --hover: #262b34;
  --selected: color-mix(in srgb, var(--accent) 18%, #1d2027);
  --danger-soft: #3a1d23;
  --ok-soft: #1a3324;
  --warn-soft: #3a2f17;
  --shadow-2: 0 8px 28px rgba(0, 0, 0, .45);
  --shadow-3: 0 18px 50px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 650; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------------ controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  font-weight: 550; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, .chip-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.93); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { height: 26px; padding: 0 9px; font-size: 12.5px; border-radius: 6px; }
.btn.big { height: 40px; padding: 0 18px; font-size: 15px; }
.btn[disabled] { opacity: .5; cursor: default; pointer-events: none; }
.btn svg, .icon-btn svg { flex: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 7px;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.small { width: 24px; height: 24px; border-radius: 5px; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px; border: 0;
  background: transparent; color: var(--ink-2); cursor: pointer; font-weight: 500; white-space: nowrap; }
.chip-btn:hover { background: var(--hover); color: var(--ink); }
.chip-btn.active { background: var(--accent-soft); color: var(--accent); }

.input, select.input, textarea.input { width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; }
textarea.input { height: auto; min-height: 110px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
/* multi-line text (long text fields, comments): a big box from the start, so it reads well and invites many lines */
textarea.input.long-text { min-height: 220px; }
textarea.input.comment-box { min-height: 140px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.small { height: 28px; font-size: 13px; }
.input.invalid { border-color: var(--danger); }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
label.field > .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 20px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff;
  border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(14px); }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--ink-2); font-weight: 550; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 650; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.soon { background: linear-gradient(90deg, #7b5cff22, #2d7ff922); color: #6a4fe0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--faint); }
.dot.ok { background: #22a35a; } .dot.err { background: var(--danger); } .dot.warn { background: #e6a700; }

.chip { display: inline-flex; align-items: center; max-width: 100%; height: 20px; padding: 0 8px; border-radius: 999px;
  font-size: 12.5px; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 4px; overflow: hidden; flex-wrap: nowrap; align-items: center; min-width: 0; }
.chips.wrap { flex-wrap: wrap; }
.link-chip { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 5px; font-size: 12.5px;
  background: var(--accent-soft); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; cursor: pointer; }
.link-chip:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.att-thumb.clickable { cursor: zoom-in; }
.att-thumb.clickable:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.att-thumb.att-file { display: inline-flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: var(--ink-2); }
.att-thumb { width: 26px; height: 26px; border-radius: 4px; object-fit: cover; border: 1px solid var(--line); background: var(--surface-3);
  display: inline-flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: var(--muted); flex: none; }
.stars { color: #f5b301; letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: var(--line); }
.cb { width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--faint); display: inline-flex; align-items: center;
  justify-content: center; flex: none; }
.cb.on { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ------------------------------------------------------------------ overlays */
.backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .42); z-index: 100; display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; animation: fade .12s ease-out; }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); width: min(560px, 100%);
  display: flex; flex-direction: column; max-height: 88vh; animation: pop .14s ease-out; }
.modal.wide { width: min(880px, 100%); }
.modal.xwide { width: min(1100px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line-2); }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.popover { position: fixed; z-index: 200; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-2); min-width: 200px; max-width: min(560px, calc(100vw - 16px)); max-height: min(520px, calc(100vh - 16px));
  overflow: auto; animation: pop .1s ease-out; }
.popover .pad { padding: 12px; }
.menu { padding: 5px; display: flex; flex-direction: column; min-width: 190px; }
.menu-item { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 6px; cursor: pointer; border: 0;
  background: transparent; text-align: left; color: var(--ink); white-space: nowrap; }
.menu-item:hover, .menu-item.focus { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item .kbd { margin-left: auto; color: var(--faint); font-size: 12px; }
.menu-item svg { color: var(--muted); }
.menu-sep { height: 1px; background: var(--line-2); margin: 4px 2px; }
.menu-label { font-size: 11.5px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .4px; padding: 7px 9px 3px; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column;
  gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1f2329; color: #fff; padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow-2); display: flex;
  gap: 12px; align-items: center; pointer-events: auto; animation: pop .15s ease-out; max-width: min(560px, 92vw); }
.toast.error { background: #a5162d; }
.toast button { background: transparent; border: 0; color: #9cc3ff; font-weight: 650; cursor: pointer; padding: 0; }
.tip { position: fixed; z-index: 400; background: #1f2329; color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px;
  pointer-events: none; max-width: 280px; box-shadow: var(--shadow-2); }

/* ------------------------------------------------------------------ auth */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-2); padding: 30px 30px 24px;
  display: flex; flex-direction: column; gap: 14px; }
.auth-card .logo { width: calc(var(--logo-size, 36px) + 12px); height: calc(var(--logo-size, 36px) + 12px); border-radius: 12px; margin: 0 auto 4px; display: flex; align-items: center;
  justify-content: center; background: var(--accent); color: #fff; overflow: hidden; }
.auth-card .logo img { width: 100%; height: 100%; object-fit: contain; background: var(--surface); }
.auth-card h1 { text-align: center; }
.auth-card .auth-name { text-align: center; font-weight: 750; font-size: 19px; color: var(--ink); margin-top: -6px; }
.auth-card .auth-name + h1 { font-size: 16px; font-weight: 600; color: var(--ink-2); margin-top: -10px; }
.auth-card .sub { text-align: center; color: var(--muted); margin-top: -8px; }
.notice { border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--accent-soft); color: var(--ink); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

/* ------------------------------------------------------------------ shell */
.topbar { height: max(52px, calc(var(--logo-size, 26px) + 14px)); display: flex; align-items: center; gap: 10px; padding: 0 12px 0 14px; background: var(--topbar, var(--accent));
  color: var(--topbar-ink, var(--accent-ink)); flex: none; }
.topbar .brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 16px; color: inherit; cursor: pointer;
  border: 0; background: transparent; padding: 4px 6px; border-radius: 7px; }
.topbar .brand:hover { background: rgba(255,255,255,.14); }
.topbar .brand img { width: auto; max-width: calc(var(--logo-size, 26px) * 4); height: var(--logo-size, 26px); border-radius: 6px; object-fit: contain; }
.topbar .crumb { opacity: .65; }
.topbar .base-name { font-weight: 700; font-size: 16px; color: inherit; border: 0; background: transparent; padding: 4px 8px;
  border-radius: 7px; cursor: pointer; display: flex; align-items: center; gap: 4px; max-width: 40vw; }
.topbar .base-name:hover { background: rgba(255,255,255,.14); }
.topbar .icon-btn, .topbar .chip-btn { color: inherit; opacity: .92; }
.topbar .icon-btn:hover, .topbar .chip-btn:hover { background: rgba(255,255,255,.16); color: inherit; opacity: 1; }
.topbar .ai-btn { background: rgba(255,255,255,.16); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,.25); color: inherit; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px; border: 0; cursor: pointer; flex: none; }
.app { height: 100%; display: flex; flex-direction: column; }
.conn-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 13px; padding: 5px; }

/* home */
.home { flex: 1; overflow-y: auto; }
.home-in { max-width: 1120px; margin: 0 auto; padding: 28px 20px 60px; display: flex; flex-direction: column; gap: 22px; }
.home-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.base-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.base-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; display: flex;
  gap: 12px; align-items: center; cursor: pointer; transition: box-shadow .12s, border-color .12s; position: relative; min-width: 0; }
.base-card:hover { box-shadow: var(--shadow-2); border-color: transparent; }
.base-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 750; font-size: 18px; flex: none; }
.base-card .more { position: absolute; top: 8px; right: 8px; opacity: 0; }
.base-card:hover .more { opacity: 1; }
.new-card { border: 1.5px dashed var(--line); background: transparent; justify-content: center; color: var(--muted); font-weight: 600; min-height: 80px; }
.new-card:hover { color: var(--accent); border-color: var(--accent-line); box-shadow: none; }
.ai-strip { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius-lg);
  background: linear-gradient(100deg, color-mix(in srgb, #7b5cff 12%, var(--surface)), color-mix(in srgb, var(--accent) 10%, var(--surface)));
  border: 1px solid var(--line); }

/* base screen */
.tabs { display: flex; align-items: flex-end; gap: 2px; padding: 0 10px; background: color-mix(in srgb, var(--topbar, var(--accent)) 86%, #000);
  color: var(--topbar-ink, var(--accent-ink)); height: 36px; flex: none; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { height: 30px; padding: 0 14px; border-radius: 7px 7px 0 0; border: 0; background: transparent; color: inherit; opacity: .85;
  cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tab:hover { background: rgba(255,255,255,.12); opacity: 1; }
.tab.on { background: var(--surface); color: var(--ink); opacity: 1; }
.tab .caret { opacity: .6; }
.workspace { flex: 1; display: flex; min-height: 0; background: var(--surface); }
.sidebar { width: 250px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--surface); min-height: 0; }
.sidebar.closed { display: none; }
.sidebar .find { padding: 10px 10px 6px; }
.view-list { flex: 1; overflow-y: auto; padding: 2px 6px; }
.view-item { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--ink);
  font-weight: 500; user-select: none; }
.view-item:hover { background: var(--hover); }
.view-item.on { background: var(--selected); font-weight: 650; }
.view-item .more { margin-left: auto; opacity: 0; }
.view-item:hover .more { opacity: 1; }
.view-item.drag-over { box-shadow: inset 0 2px 0 var(--accent); }
.sidebar .find { display: flex; gap: 6px; align-items: center; }
.sidebar .find .input { flex: 1; min-width: 0; }
.sidebar .find .new-view { flex: none; color: var(--accent); border: 1px solid var(--line); }
/* the view tree: tables ▸ (kinds ▸) views, each level collapsible */
.tree-table, .tree-group { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; user-select: none; color: var(--ink-2); }
.tree-table { font-weight: 650; margin-top: 2px; }
.tree-table.current { color: var(--ink); }
.tree-group { font-size: 12.5px; color: var(--muted); }
.tree-table:hover, .tree-group:hover { background: var(--hover); }
.tree-caret { display: inline-flex; width: 14px; color: var(--faint); flex: none; }
.tree-count { font-size: 11px; color: var(--faint); font-weight: 500; }
.tree-branch { padding-left: 14px; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--line); min-height: 44px;
  flex-wrap: wrap; background: var(--surface); }
.toolbar .view-title { font-weight: 700; display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 6px;
  cursor: pointer; border: 0; background: transparent; max-width: 280px; }
.toolbar .view-title:hover { background: var(--hover); }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.toolbar .search { width: 200px; }
.view-host { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; overflow: hidden; background: var(--surface-2); }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px 20px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.loading { margin: auto; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ grid */
.grid-wrap { flex: 1; overflow: auto; position: relative; background: var(--surface); outline: none; }
.grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; min-width: 100%; }
.grid th, .grid td { height: var(--row-h); border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: 0 8px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: left; vertical-align: middle; background: var(--surface); }
.grid thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); font-weight: 600; color: var(--ink-2);
  height: 34px; cursor: default; user-select: none; }
.grid th .th { display: flex; align-items: center; gap: 6px; }
.grid th .th .ico { color: var(--muted); flex: none; }
.grid th .th .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.grid th .th .more { opacity: 0; flex: none; }
.grid th:hover .th .more { opacity: 1; }
.grid th .resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.grid th { position: sticky; }
.grid th.drop-before { box-shadow: inset 3px 0 0 var(--accent); }
.grid .num { width: 108px; color: var(--faint); font-size: 12px; text-align: left; position: sticky; left: 0; z-index: 2; padding: 0 6px; }
.grid thead .num { z-index: 4; }
.grid td.primary, .grid th.primary { position: sticky; left: 108px; z-index: 2; border-right: 1px solid var(--line); }
.grid thead th.primary { z-index: 4; }
.grid tr:hover td { background: color-mix(in srgb, var(--hover) 70%, var(--surface)); }
.grid tr.sel td { background: var(--selected); }
/* the row of the selected cell: shaded across (a double-click opens the record) */
.grid tbody tr.cur-row td { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.grid td.cur { box-shadow: inset 0 0 0 2px var(--accent); }
.grid td.insel { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.grid td.ro { color: var(--ink-2); }
.grid td.align-right { text-align: right; }
/* the open-record button: always visible on every row, impossible to miss */
.open-rec { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--accent); cursor: pointer; padding: 0; flex: none; }
.grid tr:hover .open-rec, .grid tr.cur-row .open-rec, .card:hover .open-rec { border-color: var(--accent); background: var(--accent-soft); }
.open-rec:hover, .open-rec:focus-visible { background: var(--accent) !important; color: #fff; outline: none; }
.grid .num .numcell { display: flex; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.grid.tall .num .numcell { height: auto; }
.grid .num .open-rec { margin-left: auto; }
.card .card-open { margin: -4px -4px 0 0; }
.grid .num .rownum { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.grid .num input { margin: 0; flex: none; accent-color: var(--accent); }
/* the row checkbox shows on hover (or when ticked), the number otherwise: a calmer grid */
.grid tbody tr:not(:hover):not(.sel) .num input[type=checkbox] { opacity: 0; }
.grid .num .rowcolor { flex: none; margin-right: 0; }
.grid tr.add td { color: var(--muted); cursor: pointer; background: var(--surface); }
.grid tr.add td:hover { background: var(--hover); }
.grid tr.group td { background: var(--surface-2); font-weight: 650; height: 38px; cursor: pointer; border-bottom: 1px solid var(--line); }
.grid tr.group.d1 td { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.grid tr.group .count { color: var(--muted); font-weight: 500; margin-left: 8px; }
.grid tfoot td { position: sticky; bottom: 0; background: var(--surface-2); color: var(--muted); font-size: 12px; z-index: 3; cursor: pointer; }
.grid tfoot td:hover { color: var(--ink); }
.grid tfoot td.num, .grid tfoot td.primary { z-index: 4; }
.grid .rowcolor { display: inline-block; width: 4px; height: 18px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.grid.tall td { white-space: normal; vertical-align: top; padding-top: 6px; }
.grid.tall td .cellwrap { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.cell-editor { position: absolute; z-index: 20; background: var(--surface); box-shadow: 0 0 0 2px var(--accent), var(--shadow-2);
  border-radius: 3px; display: flex; }
.cell-editor input, .cell-editor textarea { border: 0; outline: none; width: 100%; padding: 6px 8px; background: transparent; }
.cell-editor textarea { min-height: 220px; min-width: 360px; resize: both; }

/* ------------------------------------------------------------------ cards (kanban / gallery) */
.board { flex: 1; overflow: auto; display: flex; gap: 12px; padding: 14px; align-items: flex-start; }
.stack { width: 272px; flex: none; background: var(--surface-3); border-radius: 10px; display: flex; flex-direction: column; max-height: 100%; }
.stack-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 6px; font-weight: 650; }
.stack-head .count { color: var(--muted); font-weight: 500; }
.stack-body { padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 40px; }
.stack-body.drop { background: var(--accent-soft); border-radius: 8px; }
.stack .add { margin: 0 8px 8px; justify-content: flex-start; color: var(--muted); }
.card { background: var(--surface); border-radius: 9px; box-shadow: var(--shadow-1), 0 0 0 1px var(--line-2); padding: 10px 11px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; transition: box-shadow .1s; min-width: 0; }
.card:hover { box-shadow: var(--shadow-2); }
.card.dragging { opacity: .45; }
.card .title { font-weight: 650; display: flex; align-items: flex-start; gap: 4px; }
.card .title > .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .cover { margin: -10px -11px 4px; height: 130px; border-radius: 9px 9px 0 0; background: var(--surface-3) center/cover no-repeat; }
.card .kv { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.card .kv .k { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .3px; font-weight: 650; }
.card .kv .v { min-height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .drop-line { height: 3px; background: var(--accent); border-radius: 2px; margin: -5px 0; }
.gallery { flex: 1; overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px; align-content: start; }
.gallery .card .cover { height: 160px; }

/* ------------------------------------------------------------------ calendar */
.cal { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.cal-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(100px, 1fr); overflow-y: auto; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.cal-dow div { padding: 6px 8px; font-size: 12px; font-weight: 650; color: var(--muted); }
.cal-day { border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: 4px; display: flex; flex-direction: column;
  gap: 3px; min-width: 0; overflow: hidden; }
.cal-day.other { background: var(--surface-2); }
.cal-day.other .dnum { color: var(--faint); }
.cal-day .dnum { font-size: 12px; font-weight: 650; padding: 1px 4px; align-self: flex-start; border-radius: 10px; }
.cal-day.today .dnum { background: var(--accent); color: #fff; }
.cal-day.drop { background: var(--accent-soft); }
.cal-ev { font-size: 12px; padding: 2px 6px; border-radius: 5px; cursor: pointer; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; flex: none; border-left: 3px solid transparent; }
.cal-ev:hover { filter: brightness(.96); }
.cal-more { font-size: 11.5px; color: var(--muted); padding: 0 6px; cursor: pointer; }
.cal-week { grid-auto-rows: 1fr; }
.cal-week .cal-day { min-height: 300px; }
.unscheduled { width: 230px; flex: none; border-left: 1px solid var(--line); overflow-y: auto; padding: 10px; display: flex; flex-direction: column;
  gap: 6px; background: var(--surface-2); }

/* ------------------------------------------------------------------ timeline */
.tl { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.tl-body { flex: 1; overflow: auto; position: relative; }
.tl-inner { position: relative; }
.tl-scale { position: sticky; top: 0; z-index: 5; background: var(--surface-2); border-bottom: 1px solid var(--line); height: 44px; }
.tl-tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line-2); font-size: 11.5px; color: var(--muted); padding: 4px 6px; white-space: nowrap; }
.tl-tick.major { border-left-color: var(--line); color: var(--ink-2); font-weight: 650; }
.tl-lines .tl-vline { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line-2); }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); opacity: .7; z-index: 3; }
.tl-lane { position: absolute; left: 0; right: 0; border-bottom: 1px solid var(--line-2); }
.tl-lane-label { position: sticky; left: 0; z-index: 4; display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; font-weight: 650;
  font-size: 12.5px; background: color-mix(in srgb, var(--surface) 88%, transparent); border-radius: 0 0 8px 0; }
.tl-bar { position: absolute; height: 26px; border-radius: 6px; display: flex; align-items: center; padding: 0 8px; font-size: 12.5px;
  white-space: nowrap; overflow: hidden; cursor: grab; box-shadow: var(--shadow-1); user-select: none; z-index: 2; }
.tl-bar.dragging { cursor: grabbing; opacity: .85; box-shadow: var(--shadow-2); }
.tl-bar .h { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; }
.tl-bar .h.l { left: 0; } .tl-bar .h.r { right: 0; }
.tl-bar.milestone { border-radius: 13px; }

/* ------------------------------------------------------------------ form view */
.formview { flex: 1; overflow: auto; display: flex; }
.form-builder { width: 300px; flex: none; border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.form-preview { flex: 1; overflow-y: auto; padding: 28px 16px 60px; }
.form-card { max-width: 640px; margin: 0 auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
  overflow: hidden; }
.form-card .band { height: 10px; background: var(--accent); }
.form-card .in { padding: 26px 30px 30px; display: flex; flex-direction: column; gap: 18px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field .lbl { font-weight: 650; }
.form-field .lbl .req { color: var(--danger); }
.form-field .desc { color: var(--muted); font-size: 13px; margin-top: -3px; }
.fb-field { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface); cursor: grab; }
.fb-field.off { opacity: .55; }
.fb-field.drag-over { box-shadow: 0 -2px 0 var(--accent); }
/* the form designer: elements and fields | the form | the selected item's settings */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented .chip-btn { border-radius: 0; }
.formview.designing { overflow: hidden; }
.fd-palette, .fd-props { flex: none; overflow-y: auto; background: var(--surface); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.fd-palette { width: 230px; border-right: 1px solid var(--line); }
.fd-props { width: 300px; border-left: 1px solid var(--line); gap: 12px; }
.fd-props h3 { margin: 0; font-size: 15px; }
.fd-palette .menu-label { margin-top: 8px; display: flex; align-items: center; }
.fd-tile { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--surface); cursor: grab; }
.fd-tile:hover { border-color: var(--accent-line); background: var(--hover); }
.fd-tile .fd-add { margin-left: auto; color: var(--faint); }
.fd-tile:hover .fd-add { color: var(--accent); }
.fd-canvas { background: var(--surface-3); }
.fd-head { border-radius: 8px; padding: 6px; margin: -6px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.fd-head h1 { margin: 0; }
.fd-head:hover, .fd-item:hover { box-shadow: 0 0 0 1px var(--accent-line); }
.fd-head.sel, .fd-item.sel { box-shadow: 0 0 0 2px var(--accent); }
.fd-brand { display: flex; align-items: center; gap: 12px; }
.fd-logo { max-height: 56px; max-width: 220px; object-fit: contain; }
.fd-company { font-weight: 700; font-size: 17px; color: var(--ink-2); }
.fd-items { display: flex; flex-direction: column; gap: 10px; min-height: 80px; }
.fd-item { position: relative; display: flex; gap: 6px; align-items: flex-start; border-radius: 8px; padding: 8px 8px 8px 4px; cursor: pointer; background: var(--surface); }
.fd-item.dragging { opacity: .4; }
.fd-item .fd-body { flex: 1; min-width: 0; pointer-events: none; }
.fd-grip { color: var(--faint); cursor: grab; padding-top: 2px; }
.fd-tools { display: flex; gap: 2px; opacity: 0; }
.fd-item:hover .fd-tools, .fd-item.sel .fd-tools { opacity: 1; }
.fd-marker { height: 3px; background: var(--accent); border-radius: 2px; margin: -6px 0; }
.fd-empty { border: 2px dashed var(--line); border-radius: 10px; padding: 34px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.fd-heading { margin: 6px 0 0; }
.fd-text { margin: 0; white-space: pre-wrap; color: var(--ink-2); }
.fd-divider { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.fd-spacer { height: 24px; }
.fd-image { display: block; max-width: 100%; border-radius: 8px; }
.fd-image.small { max-width: 180px; } .fd-image.medium { max-width: 360px; } .fd-image.full { width: 100%; }
.fd-image-empty { border: 1px dashed var(--line); border-radius: 8px; padding: 22px; display: flex; gap: 8px; align-items: center; justify-content: center; }
.fd-thumb { max-width: 100%; max-height: 120px; object-fit: contain; border: 1px solid var(--line-2); border-radius: 6px; background: var(--surface-2); }

/* ------------------------------------------------------------------ dashboard */
.dash { flex: 1; overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; align-content: start; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column;
  gap: 8px; min-height: 260px; min-width: 0; grid-column: span 2; }
.chart.s1 { grid-column: span 2; } .chart.s2 { grid-column: span 4; } .chart.s3 { grid-column: span 6; }
.chart.number { min-height: 140px; }
.chart .chart-head { display: flex; align-items: center; gap: 6px; }
.chart .chart-head h3 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart .big { font-size: 42px; font-weight: 750; letter-spacing: -1px; margin: auto 0; }
.chart svg { width: 100%; flex: 1; min-height: 180px; overflow: visible; }
.chart svg text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart svg .gridline { stroke: var(--line-2); }
.chart svg .axis { stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
@media (max-width: 900px) { .chart, .chart.s1, .chart.s2 { grid-column: span 6; } }

/* ------------------------------------------------------------------ report */
.report { flex: 1; display: flex; min-height: 0; }
.report-side { width: 280px; flex: none; border-right: 1px solid var(--line); background: var(--surface); padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.report-paper { flex: 1; overflow: auto; padding: 20px; background: var(--surface-3); display: flex; justify-content: center; }
.report-paper iframe { border: 0; background: #fff; box-shadow: var(--shadow-2); width: min(1100px, 100%); min-height: 100%; border-radius: 4px; }
.report-paper iframe.report-pdf { width: 100%; height: 100%; min-height: 70vh; }
.report-side { width: 320px; }
.rs-section { border: 1px solid var(--line-2); border-radius: 9px; padding: 0 10px; background: var(--surface); }
.rs-section > summary { cursor: pointer; padding: 9px 0; font-weight: 650; list-style: none; }
.rs-section > summary::-webkit-details-marker { display: none; }
.rs-section > summary::before { content: "▸ "; color: var(--faint); }
.rs-section[open] > summary::before { content: "▾ "; }
.rs-section > div { padding-bottom: 10px; }
.rs-three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* ------------------------------------------------------------------ expanded record */
.record { display: flex; min-height: 0; flex: 1; }
.record-main { flex: 1; overflow-y: auto; padding: 18px 22px 30px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.record-side { width: 320px; flex: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--surface-2); }
.rf { display: flex; flex-direction: column; gap: 5px; }
.rf .rl { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
.rf .rl svg { color: var(--muted); }
.rf .rv { min-height: 34px; }
.rf .ro-val { padding: 7px 10px; background: var(--surface-2); border-radius: 7px; min-height: 34px; white-space: pre-wrap; word-break: break-word; }
.comments { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.comment { background: var(--surface); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 10px; }
.comment .who { font-weight: 650; font-size: 12.5px; display: flex; gap: 8px; align-items: center; }
.comment .body { white-space: pre-wrap; word-break: break-word; margin-top: 3px; }
.comment-box { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.hist { font-size: 12.5px; border-left: 2px solid var(--line); padding: 2px 0 2px 10px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.att .thumb { cursor: zoom-in; }
.att { width: 96px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.att .thumb { width: 96px; height: 76px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface-3) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-weight: 750; color: var(--muted); font-size: 12px; cursor: pointer; }
.att .name { font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .x { position: absolute; top: 3px; right: 3px; display: none; background: var(--surface); }
.att:hover .x { display: inline-flex; }
.drop-zone { border: 1.5px dashed var(--line); border-radius: 8px; padding: 10px; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px; }
.drop-zone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ------------------------------------------------------------------ editors & pickers */
.option-list { display: flex; flex-direction: column; gap: 2px; max-height: 280px; overflow-y: auto; }
.option { display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: 6px; cursor: pointer; }
.option:hover, .option.focus { background: var(--hover); }
.option .tick { margin-left: auto; color: var(--accent); }
.choice-row { display: flex; align-items: center; gap: 6px; }
.color-swatch { width: 20px; height: 20px; border-radius: 6px; border: 0; cursor: pointer; flex: none; }
.swatches { display: grid; grid-template-columns: repeat(5, 22px); gap: 6px; padding: 8px; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px; }
.type-opt { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; background: transparent; text-align: left; }
.type-opt:hover { background: var(--hover); }
.type-opt.on { border-color: var(--accent-line); background: var(--accent-soft); }
.type-opt .tico { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.cond { display: grid; grid-template-columns: 70px minmax(120px, 1fr) minmax(110px, .8fr) minmax(130px, 1fr) 28px; gap: 6px; align-items: center; }
.formula-box { font-family: var(--mono); font-size: 13px; min-height: 90px; }
.fn-list { max-height: 180px; overflow-y: auto; border: 1px solid var(--line-2); border-radius: 7px; padding: 4px; font-size: 12.5px; }
.fn-list div { padding: 3px 6px; border-radius: 5px; cursor: pointer; font-family: var(--mono); }
.fn-list div:hover { background: var(--hover); }

/* ------------------------------------------------------------------ templates */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tpl { border: 1px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.tpl:hover { box-shadow: var(--shadow-2); border-color: transparent; }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ------------------------------------------------------------------ AI panel */
.ai-panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 100vw); background: var(--surface); box-shadow: var(--shadow-3);
  z-index: 150; display: flex; flex-direction: column; animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.ai-hero { padding: 22px 20px; background: linear-gradient(140deg, #6a4fe0, var(--accent)); color: #fff; display: flex; flex-direction: column; gap: 8px; }
.ai-feature { display: flex; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); }
.ai-feature .i { width: 30px; height: 30px; border-radius: 8px; background: color-mix(in srgb, #6a4fe0 14%, transparent); color: #6a4fe0;
  display: flex; align-items: center; justify-content: center; flex: none; }
.ai-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }

/* ------------------------------------------------------------------ admin */
.admin { display: flex; flex: 1; min-height: 0; }
.admin-nav { width: 230px; flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 12px 8px; display: flex;
  flex-direction: column; gap: 2px; overflow-y: auto; }
.admin-nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: var(--ink-2); font-weight: 550; }
.admin-nav a:hover { background: var(--hover); text-decoration: none; color: var(--ink); }
.admin-nav a.on { background: var(--selected); color: var(--ink); font-weight: 650; }
.admin-nav a svg { color: var(--muted); }
.admin-nav a.on svg { color: var(--accent); }
.admin-main { flex: 1; overflow-y: auto; }
.admin-in { max-width: 1000px; margin: 0 auto; padding: 24px 22px 70px; display: flex; flex-direction: column; gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.panel-head p { margin: 2px 0 0; }
.panel-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.panel-foot { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat .v { font-size: 22px; font-weight: 750; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--hover); }
.table-scroll { overflow-x: auto; }
.kv-list { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv-list .k { color: var(--muted); }
pre.detail { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 12px; overflow: auto; max-height: 340px; margin: 0;
  white-space: pre-wrap; word-break: break-word; }
.choice-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.choice-card { border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; background: var(--surface); }
.choice-card:hover { border-color: var(--accent-line); }
.choice-card.on { border-color: var(--accent); background: var(--accent-soft); }
.choice-card b { display: flex; gap: 8px; align-items: center; }
.port-pill { font-family: var(--mono); font-size: 12px; background: var(--surface-3); border-radius: 6px; padding: 1px 6px; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .sidebar { position: absolute; z-index: 30; top: 88px; bottom: 0; box-shadow: var(--shadow-2); }
  .toolbar .search { width: 140px; }
  .record { flex-direction: column; }
  .record-side { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
  .admin-nav { width: 64px; }
  .admin-nav a span { display: none; }
  .form-builder, .report-side, .fd-palette { display: none; }
  .fd-props { display: none; }
  .topbar .hide-sm { display: none; }
}
@media print {
  .topbar, .tabs, .sidebar, .toolbar { display: none !important; }
}

/* ---------------------------------------------------------------- base dashboards (drag and drop) */
.tab-sep { width: 1px; align-self: center; height: 18px; background: currentColor; opacity: .3; margin: 0 6px; flex: none; }
.tab.dash-tab { display: inline-flex; align-items: center; gap: 6px; }
.workspace.dash-mode .sidebar { display: none; }
.dash-wrap { flex: 1; display: flex; min-height: 0; min-width: 0; }
.dash-scroll { flex: 1; overflow: auto; padding: 16px; min-width: 0; }
.dash-grid { position: relative; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 74px; gap: 12px; min-height: 200px; }
.dash-wrap.editing .dash-grid { background-image: linear-gradient(to right, var(--line-2) 1px, transparent 1px); background-size: calc((100% + 12px) / 12) 100%; border-radius: 10px; min-height: 420px; outline: 1px dashed var(--line); outline-offset: 6px; }
.dash-empty { grid-column: 1 / -1; grid-row: 1 / span 4; }
.dash-w { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 12px; display: flex; flex-direction: column; min-width: 0; min-height: 0; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.dash-w .w-head { display: flex; align-items: center; gap: 6px; min-height: 26px; }
.dash-wrap.editing .dash-w .w-head { cursor: grab; user-select: none; touch-action: none; }
.dash-w.dragging { opacity: .85; z-index: 5; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.dash-w .w-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.dash-w .w-body > svg, .dash-w .w-body .col > svg { width: 100%; flex: 1; min-height: 0; overflow: visible; }
.dash-w svg text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.dash-w svg .gridline { stroke: var(--line-2); }
.dash-w .big { font-size: 40px; font-weight: 750; letter-spacing: -1px; }
.dash-w .legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.dash-w .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dash-w.t-number .w-body { justify-content: center; }
.dash-w .w-text h3 { margin: 4px 0; font-size: 18px; }
.dash-w .w-text p { margin: 2px 0; color: var(--ink-2, var(--ink)); }
.dash-w .w-list { overflow: auto; flex: 1; }
.dash-w .w-list table.list td, .dash-w .w-list table.list th { padding: 5px 8px; font-size: 13px; }
.w-resize { position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, var(--faint) 50%, var(--faint) 58%, transparent 58%, transparent 70%, var(--faint) 70%, var(--faint) 78%, transparent 78%); }
.dash-ghost { border: 2px dashed var(--accent); background: var(--accent-soft); border-radius: 12px; pointer-events: none; z-index: 1; }
.dash-palette { width: 220px; flex: none; border-left: 1px solid var(--line); padding: 12px; overflow: auto; background: var(--surface); }
.pal-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 8px; cursor: grab; background: var(--surface); user-select: none; }
.pal-item:hover { border-color: var(--accent-line); background: var(--hover); }
.pal-item .pal-ico { color: var(--accent); display: inline-flex; }
.dash-preview { min-height: 200px; height: 240px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; }
.dash-preview > svg { width: 100%; flex: 1; }
.dash-preview svg text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.dash-preview .big { font-size: 40px; font-weight: 750; }
@media (max-width: 760px) {
  .dash-grid { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .dash-w { grid-column: 1 / -1 !important; grid-row: auto !important; min-height: 220px; }
  .dash-palette { display: none; }
}
@media print { .dash-palette, .toolbar, .tabs, .topbar { display: none !important; } .dash-scroll { overflow: visible; } }

/* ---------------------------------------------------------------- templates gallery */
.tpl-cat { grid-column: 1 / -1; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 8px 2px -2px; }

/* ---------------------------------------------------------------- the kiosk app */
/* level 1: projects (.tabs) — level 2: what a project gives (.kiosk-tabs) — level 3: a table's views (.kiosk-sub) */
.kiosk-app .kiosk-badge { background: rgba(255,255,255,.22); color: inherit; margin-left: 2px; }
.kiosk-app .tab { display: inline-flex; align-items: center; gap: 4px; }
.tab-count { font-size: 11px; font-weight: 700; background: rgba(0,0,0,.14); border-radius: 9px; padding: 0 6px; margin-left: 4px; }
.tab.on .tab-count { background: var(--accent-soft); color: var(--accent); }
.kiosk-tabs { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; flex-wrap: nowrap; scrollbar-width: thin; }
.kiosk-project { font-weight: 750; color: var(--muted); padding-right: 8px; margin-right: 2px; border-right: 1px solid var(--line); white-space: nowrap; }
.ktab { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; max-width: 280px; flex: none; }
.ktab:hover { border-color: var(--accent-line); color: var(--ink); }
.ktab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ktab .badge { height: 18px; }
.kiosk-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface-2); }
.kiosk-sub { padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line-2); overflow-x: auto; display: flex; align-items: center; gap: 12px; }
.kiosk-sub .kiosk-new { height: 38px; padding: 0 18px; font-size: 15px; flex: none; box-shadow: var(--shadow-1); }
.kiosk-entry-dialog .form-preview { padding: 0; overflow: visible; }
.kiosk-entry-dialog .form-card { box-shadow: none; border: 0; margin: 0; max-width: none; }
.kiosk-entry-dialog .form-card .band { display: none; }
.toolbar .new-record { margin-left: 6px; }
.kiosk-sub .seg button { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.kiosk-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.kiosk-pane .view-host { flex: 1; }
.kiosk-user { display: inline-flex; align-items: center; gap: 8px; border: 0; background: rgba(255,255,255,.14); color: inherit; font: inherit;
  font-weight: 600; padding: 3px 10px 3px 3px; border-radius: 18px; cursor: pointer; }
.kiosk-user .avatar { width: 28px; height: 28px; font-size: 12px; }
body.kiosk .form-preview { font-size: 15px; }
body.kiosk .form-preview .btn.big { min-width: 140px; justify-content: center; }

/* ---- the console's branding page */
.logo-preview { min-width: 46px; height: 46px; max-width: 200px; border-radius: 10px; background: var(--surface-3); display: flex; align-items: center; justify-content: center; padding: 4px; overflow: hidden; }
.logo-preview img { max-height: 100%; max-width: 100%; object-fit: contain; }
.part-preview { width: 260px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; box-shadow: var(--shadow-1); }
.part-preview .pp-bar { display: flex; align-items: center; gap: 8px; padding: 0 12px; font-size: 14px; }
.part-preview .pp-bar img { max-width: 120px; object-fit: contain; }
.part-preview .pp-body { height: 74px; display: flex; align-items: center; gap: 14px; padding: 0 14px; }
.part-preview .pp-btn { padding: 5px 12px; border-radius: 7px; font-weight: 600; font-size: 13px; }

/* ---- departments and people pickers */
.dept-combo { max-width: 240px; }
.dept-combo .ellipsis { max-width: 160px; }
.dept-list { max-height: 300px; overflow: auto; display: flex; flex-direction: column; }
.dept-list .menu-item.on { background: var(--accent-soft); }
.people-list { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: var(--surface); }
.people-list .person-row { padding: 5px 0; border-bottom: 1px solid var(--line-2, var(--line)); width: 100%; }
.people-list .person-row:last-child { border-bottom: 0; }
.dept-chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; margin-left: 4px; white-space: nowrap; }
.dept-chip, .dot.c-blue { --c: #2d7ff9; } .c-teal { --c: #0f9d8a; } .c-green { --c: #1f8b4c; } .c-yellow { --c: #c79400; } .c-orange { --c: #f76808; }
.c-red { --c: #e5484d; } .c-pink { --c: #d6409f; } .c-purple { --c: #7b5cff; } .c-gray { --c: #6b7280; } .c-blue { --c: #2d7ff9; }
.dept-chip { background: color-mix(in srgb, var(--c, #2d7ff9) 14%, transparent); color: var(--c, #2d7ff9); }
.dot[class*="c-"] { background: var(--c); }
.dept-bar { display: flex; align-items: center; gap: 8px; }

/* ---- kiosk access: tables and their views */
.view-chip { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border-radius: 14px; border: 1px dashed var(--line);
  background: var(--surface); color: var(--ink-2); cursor: pointer; font: inherit; font-size: 13px; }
.view-chip:hover { border-color: var(--accent-line); color: var(--ink); }
.view-chip.on { border: 1px solid var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.access-tree { gap: 8px; max-height: 52vh; overflow: auto; }
.access-base { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.access-base > summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; list-style: none; }
.access-base > summary::-webkit-details-marker { display: none; }
.access-table { padding: 10px 12px 10px 34px; border-top: 1px solid var(--line); }
.access-table.on { background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.custom-view { display: flex; flex-direction: column; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.template-list { gap: 8px; max-height: 46vh; overflow: auto; }
.template-list .choice-card { flex-direction: row; align-items: center; gap: 12px; }
.report-row { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

/* ---- profiles and reporting lines */
.profile-section { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.profile-section h3 { margin: 0; font-size: 15px; }
.avatar.big { width: 52px; height: 52px; font-size: 19px; background: var(--accent-soft); color: var(--accent); }
.avatar.small { width: 26px; height: 26px; font-size: 11px; background: var(--accent-soft); color: var(--accent); flex: none; }
.team-list { display: flex; flex-direction: column; gap: 2px; max-height: 280px; overflow: auto; }
.team-row { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.person-combo { max-width: 320px; }
.org-tree, .org-tree ul { list-style: none; margin: 0; padding-left: 22px; }
.org-tree { padding-left: 0; max-height: 60vh; overflow: auto; }
.org-tree li { position: relative; padding: 3px 0; }
.org-tree ul li::before { content: ""; position: absolute; left: -14px; top: 0; bottom: 50%; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); width: 12px; }
.org-node { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.org-node:hover { border-color: var(--accent-line); }
.org-node.off { opacity: .55; }
tr.inactive td { opacity: .55; }

/* ---- the table catalog */
.cat { display: grid; grid-template-columns: 230px 1fr; gap: 14px; min-height: 52vh; }
.cat-side { display: flex; flex-direction: column; gap: 8px; }
.cat-nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; max-height: 52vh; }
.cat-area { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 0; border-radius: 7px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.cat-area:hover { background: var(--hover); }
.cat-area.on { background: var(--accent-soft); font-weight: 600; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; align-content: start; overflow: auto; max-height: 52vh; padding: 2px; }
.cat-head { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cat-card { border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); cursor: pointer; }
.cat-card:hover { border-color: var(--accent-line); }
.cat-card.on { border-color: var(--accent); background: var(--accent-soft); }
.cat-card.have { opacity: .6; cursor: default; }
.cat-check { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--line); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.cat-card.on .cat-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.cat-fields { display: flex; flex-wrap: wrap; gap: 4px; }
.cat-fields .chip { font-size: 11px; padding: 1px 7px; border-radius: 9px; background: var(--surface-3); color: var(--ink-2); }
.cat-plan { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); display: flex; flex-direction: column; gap: 3px; }
@media (max-width: 760px) { .cat { grid-template-columns: 1fr; } }
.day-pick { gap: 4px; } .day-pick .chip-btn { min-width: 38px; justify-content: center; border: 1px solid var(--line); }
.day-pick .chip-btn:not(.active) { background: var(--surface); color: var(--ink-2); } .day-pick .chip-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ------------------------------------------------------------------ Markdown fields */
.md { line-height: 1.55; word-break: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.25; } .md h1 { font-size: 22px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; } .md li.task { list-style: none; margin-left: -20px; } .md li.task input { margin-right: 6px; accent-color: var(--accent); }
.md code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.md pre { background: var(--surface-3); padding: 10px 12px; border-radius: 8px; overflow: auto; } .md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent-line); padding: 2px 12px; color: var(--ink-2); }
.md table { border-collapse: collapse; } .md th, .md td { border: 1px solid var(--line); padding: 4px 8px; } .md th { background: var(--surface-2); }
.md img { max-width: 100%; border-radius: 6px; } .md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md mark { background: #fff1a8; color: #1d1f25; padding: 0 2px; border-radius: 2px; }
.md-view { min-height: 120px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); cursor: text; }
.md-view:hover { border-color: var(--accent-line); } .md-view:focus { outline: none; border-color: var(--accent); }
.md-bar { display: flex; gap: 2px; align-items: center; padding: 4px; border: 1px solid var(--line); border-bottom: 0; border-radius: 7px 7px 0 0; background: var(--surface-2); }
.md-bar + .md-source { border-radius: 0 0 7px 7px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.md-tool { border: 0; background: none; min-width: 28px; height: 26px; border-radius: 5px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.md-tool:hover { background: var(--hover); color: var(--ink); }

/* ------------------------------------------------------------------ attachment preview */
.pv-modal { width: min(1200px, 96vw) !important; max-width: none !important; }
.pv-modal .modal-head .pv-head { gap: 8px; }
.pv { display: flex; align-items: center; gap: 8px; min-height: 60vh; }
.pv-stage { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; min-height: 60vh; background: var(--surface-3); border-radius: 10px; overflow: hidden; }
.pv-img { max-width: 100%; max-height: 74vh; object-fit: contain; display: block; }
.pv-frame { width: 100%; height: 74vh; border: 0; background: #fff; }
.pv-text { align-self: stretch; width: 100%; max-height: 74vh; overflow: auto; background: var(--surface); padding: 16px 20px; }
.pv-text pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pv-none { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 30px; }
.pv-ext { width: 84px; height: 100px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent); }
.pv-nav { flex: none; }
.rf .ro-val.md-ro { white-space: normal; }

/* the console's log viewer */
.log-entry { border: 1px solid var(--line-2); border-radius: 7px; padding: 6px 10px; background: var(--surface); }
.log-entry.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.log-entry.warn { border-color: color-mix(in srgb, #d9a400 45%, var(--line)); }
.log-line { display: flex; gap: 8px; align-items: center; min-width: 0; }
.log-line code { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: none; }
.log-entry pre.detail { max-height: 360px; overflow: auto; font-size: 12px; }

/* form designer: dragging (pointer based), required switches, entry-rule hints */
.fd-tile, .fd-item { touch-action: none; }
body.fd-dragging, body.fd-dragging * { cursor: grabbing !important; user-select: none; }
.fd-ghost { position: fixed; z-index: 9999; pointer-events: none; padding: 6px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink, #fff);
  font-weight: 600; box-shadow: var(--shadow-2); white-space: nowrap; }
.fd-item.dragging, .fd-tile.dragging { opacity: .4; }
.fd-marker { height: 4px; background: var(--accent); border-radius: 2px; margin: -2px 0; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.fd-req { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 10px; font-size: 11px; font-weight: 650; padding: 1px 8px; cursor: pointer; }
.fd-req.on { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.fd-item .fd-tools { align-items: center; }
.fd-item:has(.fd-req.on) .fd-tools, .fd-item .fd-tools:has(.fd-req) { opacity: 1; }
.rule-hint { font-style: italic; }
.after-msg { font-size: 15px; }

.big-code { font-size: 17px; letter-spacing: .5px; padding: 4px 10px; user-select: all; }
