
:root {
  /* Layout idea: a workbench. Data rail | marks card | ruled shelves over the canvas; dashboards on a 12-column board. */
  --page: #e8eaee;
  --panel: #fcfcfb;
  --rail: #f3f4f6;
  --ink: #0f1115;
  --ink-2: #4a4f5b;
  --accent: #2b3bb8;
  --muted: #7d828d;
  --line: #d8dbe1;
  --disc-bg: #dce7fa; --disc-ink: #163c74; --disc-line: #bacdef;
  --cont-bg: #d5eee0; --cont-ink: #0c5331; --cont-line: #a9dabd;
  --hover: rgba(15, 17, 21, .055);
  --tick: rgba(15, 17, 21, .13);
  --tick-strong: rgba(15, 17, 21, .26);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --scrim: rgba(15, 17, 21, .38);
  --font-display: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0b0c0e; --panel: #18191b; --rail: #121316; --ink: #eceef2; --ink-2: #b3b8c2;
    --accent: #95a3ff; --muted: #7b808b; --line: #2a2d33;
    --disc-bg: #172b4a; --disc-ink: #bdd4ff; --disc-line: #26446c;
    --cont-bg: #12321f; --cont-ink: #a9e6c4; --cont-line: #1f4e36;
    --hover: rgba(255, 255, 255, .06); --tick: rgba(255, 255, 255, .11); --tick-strong: rgba(255, 255, 255, .24);
    --grid: #2c2c2a; --axis: #3b3c40; --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0b0c0e; --panel: #18191b; --rail: #121316; --ink: #eceef2; --ink-2: #b3b8c2;
  --accent: #95a3ff; --muted: #7b808b; --line: #2a2d33;
  --disc-bg: #172b4a; --disc-ink: #bdd4ff; --disc-line: #26446c;
  --cont-bg: #12321f; --cont-ink: #a9e6c4; --cont-line: #1f4e36;
  --hover: rgba(255, 255, 255, .06); --tick: rgba(255, 255, 255, .11); --tick-strong: rgba(255, 255, 255, .24);
  --grid: #2c2c2a; --axis: #3b3c40; --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 400 13px/1.4 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

#app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.mark-word {
  font-family: var(--font-display); font-weight: 860; font-stretch: 125%;
  font-size: 19px; letter-spacing: -.01em; margin: 0; line-height: 1;
  display: flex; align-items: center; gap: 8px;
}
.mark-word svg { flex: none; }
.dataset {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--rail); font-size: 12px; color: var(--ink-2);
}
.dataset b { color: var(--ink); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.dataset .tag {
  white-space: nowrap;
  font-size: 10px; font-weight: 700; font-stretch: 75%; text-transform: uppercase; letter-spacing: .08em;
  color: var(--disc-ink); background: var(--disc-bg); padding: 2px 6px; border-radius: 4px;
}
.top .spacer { flex: 1; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--panel);
  font-weight: 560; font-size: 12.5px; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.quiet:hover { background: var(--hover); color: var(--ink); }
.btn svg { width: 14px; height: 14px; }

/* ---------- workbench grid ---------- */
.work {
  display: grid; min-height: 0; gap: 1px; background: var(--line);
  grid-template-columns: 228px 236px minmax(0, 1fr);
  grid-template-areas: "data cards stage";
}
.pane { background: var(--rail); overflow: auto; min-height: 0; }
.pane-data { grid-area: data; }
.pane-cards { grid-area: cards; padding: 10px; display: grid; gap: 12px; align-content: start; overflow-x: hidden; }
.pane-cards .card { min-width: 0; }
.stage { grid-area: stage; background: var(--panel); display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-height: 0; min-width: 0; }

.pane-head {
  position: sticky; top: 0; z-index: 2; background: var(--rail);
  padding: 10px 10px 8px; display: grid; gap: 8px; border-bottom: 1px solid var(--line);
}
.label-caps {
  font-family: var(--font-display); font-stretch: 68%; font-weight: 760;
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2);
}
.search {
  width: 100%; height: 30px; padding: 0 10px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel);
}
.field-group { padding: 8px 6px 4px; }
.field-group h3 { margin: 4px 6px 4px; }
.field {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 28px;
  padding: 3px 8px; border: 0; border-radius: 6px; background: transparent;
  text-align: left; cursor: grab; color: var(--ink);
}
.field:hover { background: var(--hover); }
.field:active { cursor: grabbing; }
.field .fname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ftype {
  flex: none; width: 26px; text-align: center; font-size: 10px; font-weight: 760; font-stretch: 70%;
  border-radius: 4px; padding: 2px 0; letter-spacing: .02em;
}
.ftype.d { color: var(--disc-ink); background: var(--disc-bg); }
.ftype.m { color: var(--cont-ink); background: var(--cont-bg); }
.pane-foot { padding: 10px 14px 16px; color: var(--muted); font-size: 12px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px; display: grid; gap: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.mark-select {
  width: 100%; height: 30px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--rail); padding: 0 8px; font-weight: 560;
}
.channels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.channel {
  min-width: 0;
  border: 1px dashed var(--line); border-radius: 7px; min-height: 52px; padding: 5px;
  display: grid; align-content: start; gap: 4px; background: var(--rail);
}
.channel .label-caps { font-size: 10px; display: flex; align-items: center; gap: 5px; }
.channel.detail-wide { grid-column: 1 / -1; }
.channel .empty, .filters .empty { color: var(--muted); font-size: 11.5px; }
.filters { min-height: 44px; border: 1px dashed var(--line); border-radius: 7px; padding: 6px; display: grid; gap: 5px; align-content: start; background: var(--rail); }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--rail)); }

/* shelves: the ruled rails */
.shelves { border-bottom: 1px solid var(--line); }
.shelf { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: stretch; }
.shelf + .shelf { border-top: 1px solid var(--line); }
.shelf .label-caps { display: flex; align-items: center; gap: 7px; padding: 0 12px; background: var(--rail); border-right: 1px solid var(--line); }
.shelf-drop {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 42px; padding: 7px 10px 11px;
  background-image:
    repeating-linear-gradient(90deg, var(--tick-strong) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, var(--tick) 0 1px, transparent 1px 8px);
  background-size: 100% 7px, 100% 4px;
  background-position: left bottom, left bottom;
  background-repeat: repeat-x;
}
.shelf-drop.over { background-color: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
.shelf-drop .empty { color: var(--muted); font-size: 12px; }
.caret { position: absolute; width: 2px; top: 7px; bottom: 11px; background: var(--accent); border-radius: 1px; pointer-events: none; }

/* pills */
.pill {
  min-width: 0;
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  height: 26px; padding: 0 4px 0 5px; border-radius: 6px; border: 1px solid;
  font-weight: 620; font-size: 12px; font-stretch: 88%; cursor: grab; text-align: left;
  user-select: none;
}
.pill::before {
  content: ""; flex: none; width: 4px; height: 12px; opacity: .55;
  background-image: radial-gradient(currentColor 1px, transparent 1.3px);
  background-size: 4px 4px;
}
.pill.disc { background: var(--disc-bg); color: var(--disc-ink); border-color: var(--disc-line); }
.pill.cont { background: var(--cont-bg); color: var(--cont-ink); border-color: var(--cont-line); }
.pill .plabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill .psub { font-weight: 450; opacity: .8; white-space: nowrap; }
.pill .x {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 4px;
  font-size: 14px; line-height: 1; opacity: .7;
}
.pill .x:hover { background: rgba(127, 127, 127, .2); opacity: 1; }
.pill.dragging { opacity: .35; }
.channel .pill, .filters .pill { width: 100%; justify-content: space-between; }

/* view bar */
.viewbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 14px; }
.title-input {
  flex: 1 1 220px; min-width: 0; border: 1px solid transparent; border-radius: 6px; background: transparent;
  font-family: var(--font-display); font-weight: 720; font-stretch: 100%; font-size: 17px;
  padding: 3px 6px; margin-left: -6px; text-wrap: balance;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--accent); outline: none; background: var(--rail); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--rail); }
.seg button { border: 0; background: transparent; height: 28px; padding: 0 12px; font-weight: 580; font-size: 12.5px; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.tools { display: flex; gap: 4px; flex-wrap: wrap; }

.viewport { position: relative; min-height: 0; min-width: 0; overflow: auto; padding: 4px 14px 14px; }
#chart { min-height: 100%; }
#chart .vega-embed { display: block; }
#chart .vega-embed summary { display: none; }
.empty-state {
  height: 100%; min-height: 260px; display: grid; place-content: center; text-align: center; gap: 12px;
  color: var(--ink-2); padding: 24px;
}
.empty-state h2 { margin: 0; font-family: var(--font-display); font-stretch: 112%; font-size: 22px; font-weight: 780; color: var(--ink); text-wrap: balance; }
.empty-state p { margin: 0; max-width: 46ch; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--line); background: var(--rail); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; }
.chip:hover { border-color: var(--accent); }
.error-box { border: 1px solid var(--line); border-left: 3px solid #d03b3b; background: var(--rail); border-radius: 8px; padding: 12px 14px; max-width: 60ch; margin: 18px auto; }
.hero { display: grid; place-content: center; text-align: center; min-height: 260px; height: 100%; gap: 6px; }
.hero-value { font-family: var(--font-display); font-size: clamp(48px, 9vw, 84px); font-weight: 760; letter-spacing: -.02em; line-height: 1; }
.hero-label { color: var(--ink-2); font-weight: 560; }

/* data table */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 100%; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid th { position: sticky; top: 0; background: var(--rail); font-weight: 650; z-index: 1; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover td { background: var(--hover); }
.table-note { color: var(--muted); font-size: 12px; margin: 8px 2px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* sql */
.sql-wrap { display: grid; gap: 10px; }
pre.sql {
  margin: 0; padding: 14px 16px; border-radius: 8px; background: var(--rail); border: 1px solid var(--line);
  font: 12.5px/1.6 var(--font-mono); overflow-x: auto; white-space: pre;
}
pre.sql .kw { color: var(--accent); font-weight: 500; }
pre.sql .str { color: var(--cont-ink); }
pre.sql .cm { color: var(--muted); }

/* sheet tabs */
.tabs {
  display: flex; align-items: stretch; gap: 0; background: var(--rail); border-top: 1px solid var(--line);
  min-height: 38px; padding: 0 8px; overflow-x: auto;
}
.tab {
  border: 0; background: transparent; padding: 0 14px; font-weight: 580; color: var(--ink-2);
  border-right: 1px solid var(--line); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.tab:first-child { border-left: 1px solid var(--line); }
.tab[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: inset 0 2px 0 var(--accent); }
.tab:hover { color: var(--ink); }
.tab .kind { font-size: 10px; font-weight: 760; font-stretch: 70%; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.tab-add { border: 0; background: transparent; padding: 0 12px; color: var(--ink-2); font-size: 13px; font-weight: 600; white-space: nowrap; }
.tab-add:hover { color: var(--ink); background: var(--hover); }
.status { margin-left: auto; padding: 0 8px 0 16px; display: flex; align-items: center; gap: 14px; color: var(--muted); font: 11.5px var(--font-mono); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* menu, modal, toast, drop overlay */
.menu {
  position: fixed; z-index: 50; min-width: 210px; max-width: min(320px, calc(100vw - 24px)); max-height: min(70vh, 520px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 5px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .16), 0 2px 6px rgba(0, 0, 0, .08);
}
.menu h4 { margin: 6px 8px 3px; }
.menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent;
  text-align: left; padding: 6px 8px; border-radius: 6px; font-size: 12.5px;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button .chk { width: 14px; flex: none; color: var(--accent); font-weight: 800; }
.menu button[disabled] { opacity: .4; cursor: default; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }
.menu .danger { color: #c23434; }

.modal { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: grid; place-items: center; padding: 16px; }
.modal-card {
  width: min(420px, 100%); max-height: min(80vh, 640px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal-head { padding: 14px 16px 8px; display: grid; gap: 4px; }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 17px; font-weight: 740; }
.modal-head p { margin: 0; color: var(--ink-2); font-size: 12.5px; }
.modal-body { overflow: auto; padding: 4px 16px 10px; display: grid; gap: 8px; align-content: start; }
.modal-foot { padding: 10px 16px 14px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); }
.checklist { display: grid; gap: 1px; }
.checklist label { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 5px; }
.checklist label:hover { background: var(--hover); }
.checklist .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.row-actions { display: flex; gap: 6px; }
.range-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); }
.range-grid input { height: 32px; border: 1px solid var(--line); border-radius: 7px; padding: 0 8px; background: var(--rail); }

.toast {
  position: fixed; z-index: 70; left: 50%; bottom: 56px; transform: translateX(-50%);
  background: var(--ink); color: var(--panel); padding: 9px 14px; border-radius: 8px; font-size: 12.5px;
  max-width: min(520px, calc(100vw - 32px)); box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.dropzone {
  position: fixed; inset: 10px; z-index: 80; border: 2px dashed var(--accent); border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 88%, transparent); display: grid; place-items: center;
  font-family: var(--font-display); font-size: 22px; font-weight: 760; font-stretch: 112%; pointer-events: none;
}
.loading { display: grid; place-items: center; height: 100%; color: var(--muted); }

#vg-tooltip-element.vg-tooltip.custom-theme {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14); font: 12px/1.45 var(--font-body); padding: 8px 10px;
}
#vg-tooltip-element.vg-tooltip.custom-theme td.key { color: var(--ink-2); font-weight: 500; padding-right: 10px; }
#vg-tooltip-element.vg-tooltip.custom-theme td.value { font-variant-numeric: tabular-nums; font-weight: 620; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* medium: marks card folds under the data pane */
@media (max-width: 1080px) {
  .work { grid-template-columns: 224px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "data stage" "cards stage"; }
  .pane-cards { border-top: 1px solid var(--line); }
}
/* phone: one column, page scrolls */
@media (max-width: 720px) {
  html, body { height: auto; }
  #app { height: auto; min-height: 100%; }
  .work { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; grid-template-areas: "stage" "data" "cards"; }
  .pane { overflow: visible; }
  .stage { grid-template-rows: auto auto auto; }
  .viewport { height: 440px; }
  .shelf { grid-template-columns: 78px minmax(0, 1fr); }
  .shelf .label-caps { padding: 0 8px; }
  .dataset b { max-width: 170px; }
  .dataset > span:not(.tag) { display: none; }
  .status { display: none; }
  .top { padding: 8px 12px; }
  .dash { padding: 10px; }
}

/* ---------- Vizora additions ---------- */
:root { --good: #006300; --bad: #d03b3b; }
:root[data-theme="dark"] { --good: #0ca30c; --bad: #e66767; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --good: #0ca30c; --bad: #e66767; } }
.mark-word svg rect:first-child { fill: var(--accent); }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn.small { height: 24px; padding: 0 8px; font-size: 12px; }
a.btn { text-decoration: none; color: inherit; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pane-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ftype.e { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.field.err .fname { color: var(--bad); }
.ftable { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70px; }
.pill.bad { background: color-mix(in srgb, var(--bad) 12%, var(--panel)); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.stack { display: grid; gap: 5px; font-size: 12.5px; color: var(--ink-2); font-weight: 560; }
.stack .search, .stack select { color: var(--ink); font-weight: 400; }
.empty-state.small { min-height: 0; padding: 12px; }
.empty-state.small h2 { font-size: 15px; }
.full { min-height: 0; overflow: auto; background: var(--page); }

/* calc editor */
.modal-card.wide { width: min(920px, 100%); }
.calc-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(220px, 1fr); gap: 16px; }
.calc-main { display: grid; gap: 10px; align-content: start; }
textarea.formula {
  width: 100%; min-height: 140px; resize: vertical; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--rail); font: 13px/1.55 var(--font-mono); color: var(--ink);
}
textarea.formula:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.calc-status { font-size: 12.5px; padding: 8px 10px; border-radius: 8px; background: var(--rail); border-left: 3px solid var(--line); line-height: 1.5; }
.calc-status.ok { border-left-color: var(--good); }
.calc-status.bad { border-left-color: var(--bad); color: var(--ink); }
.calc-status code { font: 12px var(--font-mono); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-right: 2px; }
.calc-examples { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.calc-side { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; min-height: 0; }
.calc-ref { overflow: auto; max-height: 340px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: var(--rail); }
.calc-ref h4 { margin: 8px 6px 2px; }
.ref { display: flex; justify-content: space-between; gap: 8px; width: 100%; border: 0; background: transparent; padding: 5px 6px; border-radius: 5px; text-align: left; font: 12px var(--font-mono); }
.ref:hover { background: var(--hover); }
.ref small { font: 11px var(--font-body); color: var(--muted); white-space: nowrap; }

/* data source */
.source { padding: 16px; display: grid; gap: 18px; max-width: 1400px; }
.src-block { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 12px; min-width: 0; }
.src-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.src-head h2 { margin: 0; font-family: var(--font-display); font-size: 17px; font-weight: 760; }
.tcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 10px; }
.tcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--rail); display: grid; gap: 8px; align-content: start; }
.tcard-head { display: grid; gap: 2px; }
.tcard h3 { margin: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.join-desc { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.jtag { font-size: 10.5px; font-weight: 760; font-stretch: 75%; text-transform: uppercase; letter-spacing: .07em; color: var(--disc-ink); background: var(--disc-bg); padding: 2px 6px; border-radius: 4px; margin-right: 4px; }
.join-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 10px; align-items: end; }
.join-eq { font-size: 20px; font-weight: 700; padding-bottom: 4px; color: var(--muted); }
.join-stats { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.fields-grid td { vertical-align: middle; }
.cell-input { width: 100%; min-width: 140px; height: 28px; border: 1px solid transparent; border-radius: 6px; background: transparent; padding: 0 6px; font-weight: 560; }
.cell-input:hover { border-color: var(--line); }
.cell-input:focus { border-color: var(--accent); background: var(--rail); outline: none; }
.cell-select { height: 28px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 0 4px; }
tr.is-hidden td { opacity: .55; }
.err-text { color: var(--bad); font-size: 12px; white-space: normal; }
td.sample { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.btn.danger, .danger { color: var(--bad); }

/* matrix, KPI, gauge */
table.matrix th.rh, table.matrix th.ch { background: var(--rail); }
table.matrix th.ch { text-align: center; border-left: 1px solid var(--line); }
table.matrix th.rl { font-weight: 600; text-align: left; background: var(--panel); position: sticky; left: 0; }
table.matrix .tot { font-weight: 700; border-left: 1px solid var(--line); }
table.matrix tr.total td, table.matrix tr.total th { font-weight: 700; border-top: 2px solid var(--line); background: var(--rail); }
.kpi, .gauge { height: 100%; display: grid; align-content: center; gap: 4px; padding: 4px 6px; min-height: 120px; }
.kpi-label { color: var(--ink-2); font-weight: 600; font-size: 12.5px; }
.kpi-value { font-family: var(--font-display); font-size: clamp(28px, 4.2vw, 44px); font-weight: 760; letter-spacing: -.02em; line-height: 1.05; }
.kpi-delta { font-size: 12px; font-weight: 600; display: flex; gap: 5px; align-items: center; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--bad); }
svg.spark { width: 100%; height: 40px; display: block; margin-top: 4px; }
.gauge svg { width: 100%; max-width: 320px; max-height: 190px; justify-self: center; }
.gauge-value { font-family: var(--font-display); font-size: 26px; font-weight: 760; fill: var(--ink); }
.gauge-axis { font-size: 10px; fill: var(--muted); }
.gauge-target { text-align: center; color: var(--ink-2); font-size: 12px; }
.sheet-kpi { max-width: 420px; }

/* dashboard */
.dash-bar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.dash-bar .title-input { flex: 0 1 360px; }
.sel-note { flex: 1 1 200px; color: var(--ink-2); font-size: 12.5px; }
.canvas { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 30px; gap: 12px; padding: 14px 16px 40px; align-content: start; }
.canvas > .empty-state { grid-column: 1 / -1; grid-row: span 8; }
.canvas.editing {
  background-image: repeating-linear-gradient(90deg, color-mix(in srgb, var(--accent) 7%, transparent) 0 calc((100% - 11 * 12px) / 12), transparent calc((100% - 11 * 12px) / 12) calc((100% - 11 * 12px) / 12 + 12px));
  background-origin: content-box; background-clip: content-box;
}
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 10px 6px; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 4px; min-width: 0; min-height: 0; overflow: hidden; }
.tile.kind-text { grid-template-rows: minmax(0, 1fr); background: transparent; border-color: transparent; padding: 4px 4px; }
.canvas.editing .tile.kind-text { border: 1px dashed var(--line); background: var(--panel); }
.tile.is-source { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 22px; }
.tile-head h3 { margin: 0; font-family: var(--font-display); font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-body { min-height: 0; overflow: auto; }
.tile.kind-sheet .tile-body { overflow: hidden; }
.icon-btn { border: 0; background: transparent; width: 26px; height: 22px; border-radius: 5px; color: var(--ink-2); font-size: 16px; line-height: 1; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.text-menu { position: absolute; top: 6px; right: 6px; }
.drag-handle { position: absolute; inset: 0 0 auto 0; height: 34px; cursor: grab; z-index: 2; background: linear-gradient(var(--hover), transparent); }
.drag-handle::after { content: ""; position: absolute; left: 50%; top: 6px; width: 28px; height: 4px; margin-left: -14px; border-radius: 2px; background: var(--muted); opacity: .5; }
.canvas.editing .tile-head { padding-right: 0; position: relative; z-index: 3; pointer-events: none; }
.canvas.editing .tile-head .icon-btn { pointer-events: auto; }
.resize { position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px; cursor: nwse-resize; z-index: 3; background: linear-gradient(135deg, transparent 50%, var(--muted) 50%, var(--muted) 58%, transparent 58%, transparent 70%, var(--muted) 70%, var(--muted) 78%, transparent 78%); opacity: .8; }
.tile.moving { opacity: .85; box-shadow: 0 12px 30px rgba(0, 0, 0, .18); z-index: 5; }
.canvas.editing .tile-body { pointer-events: none; }
.canvas.editing .tile.kind-text .tile-body, .canvas.editing .tile.kind-slicer .tile-body { pointer-events: auto; }
.text-tile h2 { margin: 2px 0 4px; font-family: var(--font-display); font-size: 24px; font-weight: 800; font-stretch: 112%; letter-spacing: -.01em; text-wrap: balance; }
.text-tile p { margin: 0; color: var(--ink-2); max-width: 90ch; }
.text-edit { width: 100%; height: 100%; resize: none; border: 0; background: transparent; font: 14px/1.5 var(--font-body); color: var(--ink); padding: 4px; }
.slicer { display: grid; gap: 6px; align-content: start; }
.sl-all { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 12.5px; padding: 2px 4px; }
.sl-list { display: grid; gap: 1px; }
.sl-list label { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 5px; font-size: 12.5px; }
.sl-list label:hover { background: var(--hover); }
.sl-list .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.slicer.range-grid { grid-template-columns: 1fr; }

@media (max-width: 1080px) { .calc-grid { grid-template-columns: 1fr; } .calc-ref { max-height: 200px; } }
@media (max-width: 720px) {
  .canvas { display: flex; flex-direction: column; gap: 10px; padding: 10px; }
  .tile { min-height: calc(var(--rows) * 30px + (var(--rows) - 1) * 12px); }
  .tile.kind-sheet .tile-body { height: calc(var(--rows) * 30px + (var(--rows) - 1) * 12px - 40px); }
  #editLayoutBtn { display: none; }
  .join-row { grid-template-columns: 1fr; }
  .join-eq { display: none; }
  .top-actions a.btn { display: none; }
}
