:root {
  --red: #e4000f;
  --blue: #0a64c8;
  --yellow: #ffcb05;
  --green: #1aa64b;
  --ink: #1d2330;
  --paper: #fbf7ee;
  --card: #ffffff;
  --line: #e6ddc9;
  --muted: #7a8194;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}

body {
  display: flex;
  flex-direction: column;
  /* Pin the whole app to the viewport; all scrolling happens in inner panes. */
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue), #0a4ea0);
  color: #fff;
  padding: 18px 24px 0;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.topbar h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.5px;
}
.topbar .star { color: var(--yellow); }
.topbar .dot { color: var(--red); }
.tagline {
  margin: 4px 0 14px;
  color: #d6e4f7;
  font-size: 14px;
}
.tabs { display: flex; gap: 6px; }
.tab {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #eaf1fb;
  font: 600 14px var(--sans);
  padding: 9px 18px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
}
.tab:hover { background: rgba(255, 255, 255, 0.22); }
.tab.active {
  background: var(--paper);
  color: var(--ink);
}

/* ---------- layout ---------- */
/* main is a flex container; the active panel is its single flex child and
   fills it. min-height/min-width: 0 lets inner scroll panes actually bound. */
main { flex: 1; min-height: 0; display: flex; }
.panel { display: none; min-height: 0; min-width: 0; }
.panel.active { display: flex; flex: 1; }

#tab-query { gap: 16px; padding: 16px 24px; min-height: 0; }

.sidebar {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  padding-right: 6px;
}
.sidebar-section { margin-bottom: 22px; }
.sidebar-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 0 0 10px;
}

.examples { display: flex; flex-direction: column; gap: 6px; }
.example {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}
.example:hover {
  border-color: var(--blue);
  background: #f1f7ff;
}

/* schema tree */
.schema-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 12px 0 4px;
}
.schema details { border-bottom: 1px solid var(--line); }
.schema summary {
  list-style: none;
  cursor: pointer;
  padding: 5px 2px;
  font-size: 13px;
}
.schema summary::-webkit-details-marker { display: none; }
.schema summary::before {
  content: "▸";
  color: var(--muted);
  margin-right: 6px;
  font-size: 10px;
}
.schema details[open] summary::before { content: "▾"; }
.schema-name {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--blue);
}
.schema-name:hover { text-decoration: underline; }
.cols { list-style: none; margin: 0 0 6px; padding: 0 0 0 18px; }
.cols li { padding: 2px 0; font-size: 12px; }
.cols .col { font-family: var(--mono); }
.cols .ctype { color: var(--muted); font-size: 11px; }

/* foreign-key join hints */
.fk-join {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--blue);
  font: 600 11px var(--mono);
  border-radius: 5px;
  padding: 1px 6px;
  cursor: pointer;
}
.fk-join:hover { background: #eef4ff; border-color: var(--blue); }
.fk-ref {
  border: none;
  background: none;
  padding: 0 0 0 2px;
  color: var(--muted);
  font-weight: 500;
}
.fk-ref:hover { background: none; color: var(--blue); text-decoration: underline; }
.fk-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 2px 0 4px 18px;
}
.fk-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 8px 18px;
}

/* ---------- workspace ---------- */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.editor-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
#sql {
  width: 100%;
  height: 170px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  background: #fcfbf7;
}
#sql:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

/* CodeMirror editor (replaces the textarea when the CDN loads). */
.CodeMirror {
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  background: #fcfbf7;
}
.CodeMirror-focused { outline: 2px solid var(--blue); border-color: var(--blue); }
.CodeMirror-gutters { background: #f4efe1; border-right: 1px solid var(--line); }
.CodeMirror-hints {
  font-family: var(--mono);
  font-size: 13px;
  z-index: 30;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.CodeMirror-hint-active { background: var(--blue); color: #fff; }
.editor-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 9px 14px;
  font: 600 13px var(--sans);
  cursor: pointer;
  color: var(--ink);
}
.btn:hover { background: #f4f0e6; }
.btn.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.btn.primary:hover { background: #c00010; }
.btn kbd {
  font: inherit;
  font-size: 11px;
  opacity: 0.8;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 0 4px;
}
.status { font-size: 13px; color: var(--muted); }

/* ---------- results ---------- */
.results { flex: 1; min-height: 0; overflow: auto; }
.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  background: var(--card);
  margin-bottom: 12px;
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  position: sticky;
  top: 0;
  background: #f4efe1;
  text-align: left;
  font-family: var(--mono);
  font-weight: 700;
  padding: 9px 12px;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid #f0ead9;
  vertical-align: top;
  font-family: var(--mono);
  white-space: pre-wrap;
  max-width: 520px;
}
tbody tr:hover { background: #fbfaf4; }
.null { color: #b9b29e; font-style: italic; }

.error {
  background: #fff1f1;
  border: 1px solid #f3b6b6;
  color: #a4000c;
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
}
.note {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 12px;
}

/* ---------- map ---------- */
.map-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  min-height: 0;
  width: 100%;
}
.map-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.map-controls label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
#map-level,
#map-area {
  font: 600 14px var(--mono);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.map-bg-toggle { cursor: pointer; user-select: none; }
.map-bg-toggle input { cursor: pointer; margin: 0; }
.map-bg-toggle.disabled { opacity: 0.4; cursor: not-allowed; }
.map-bg-toggle.disabled input { cursor: not-allowed; }
#map-svg image { image-rendering: auto; }

/* Camera-trigger zones overlaid on the Map tab. */
.cam-zone-g { cursor: help; }
.cam-zone {
  fill: #7c3aed;
  fill-opacity: 0.1;
  stroke: #7c3aed;
  stroke-width: 1.5;
  stroke-opacity: 0.9;
}
.cam-zone-g:hover .cam-zone { fill-opacity: 0.22; }
.cam-zone-label {
  fill: #5b21b6;
  font: 600 9px ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 2.5px;
  stroke-linejoin: round;
  pointer-events: none;
}
.legend { display: flex; gap: 6px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}
.legend-item.off { opacity: 0.4; }
.legend-item .swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}
.map-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(#f3eee0 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, #f3eee0 1px, transparent 1px) 0 0 / 40px 40px,
    var(--card);
  overflow: hidden;
}
#map-svg { display: block; cursor: grab; touch-action: none; }
#map-svg.panning { cursor: grabbing; }
.map-tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  background: rgba(29, 35, 48, 0.95);
  color: #fff;
  font-size: 12px;
  font-family: var(--mono);
  padding: 7px 10px;
  border-radius: 8px;
  max-width: 280px;
  z-index: 5;
  line-height: 1.45;
}
.map-tooltip .muted { color: #b9c2d6; }

/* ---------- save (nested EEPROM layout, treemap-styled) ---------- */
.save-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  min-height: 0;
  width: 100%;
}
.save-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.save-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.save-crumb {
  appearance: none;
  background: none;
  border: none;
  font: 600 14px var(--sans);
  color: var(--blue);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
}
.save-crumb:not(.current):hover { background: #eef4ff; }
.save-crumb.current { color: var(--ink); cursor: default; }
.save-sep { color: var(--muted); }
.save-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: auto;
}
#save-svg { display: block; }

.save-bandlabel { fill: var(--muted); font: 600 11px var(--mono); }

/* the persistent 512-byte minimap + scale ruler at the top of the stage */
.save-rulertitle { fill: var(--ink); font: 700 11px var(--sans); }
.save-rulertick { fill: var(--muted); font: 500 9px var(--mono); }
.save-rulerlab { fill: var(--ink); font: 600 10px var(--mono); }
.save-mini { cursor: pointer; }
.save-mini rect { shape-rendering: crispEdges; }
.save-mini:hover rect { stroke: var(--ink); stroke-width: 1.5; }
.save-mini-here { fill: none; stroke: var(--ink); stroke-width: 2; pointer-events: none; }
.save-seg { cursor: default; }
.save-seg.link { cursor: pointer; }
.save-seg rect { stroke: var(--paper); stroke-width: 1; transition: stroke 0.1s; }
.save-seg.link:hover rect { stroke: var(--ink); stroke-width: 2; }
.save-seg.sel rect { stroke: var(--blue); stroke-width: 2; }
.save-seg.unused rect { stroke-dasharray: 2 2; stroke: #cdd2de; }

/* wrapping, ellipsizing tile labels (foreignObject + HTML, like the treemap) */
.save-fo { overflow: hidden; pointer-events: none; }
.save-lab {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 3px 5px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-family: var(--mono);
  line-height: 1.12;
  overflow: hidden;
}
.save-lab .nm {
  font-weight: 700;
  font-size: 11px;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}
.save-lab .sb {
  font-size: 9px;
  opacity: 0.75;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- heatmap ---------- */
.heat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  min-height: 0;
  width: 100%;
}
.heat-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.heat-controls label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.heat-controls select {
  font: 600 13px var(--mono);
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.heat-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
table.heatmap {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11px;
}
table.heatmap th,
table.heatmap td {
  border-bottom: 1px solid #f0ead9;
  border-right: 1px solid #f0ead9;
}
table.heatmap td {
  width: 30px;
  min-width: 30px;
  height: 26px;
  text-align: center;
  font-family: var(--mono);
  cursor: default;
}
table.heatmap td:empty { background: #fcfbf7; }
table.heatmap td:not(:empty) { cursor: pointer; }
table.heatmap .rowhead {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f4efe1;
  text-align: left;
  white-space: nowrap;
  padding: 0 10px;
  font-family: var(--mono);
  font-weight: 600;
  cursor: pointer;
  width: 168px;
  min-width: 168px;
  max-width: 168px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.heatmap .rowhead:hover { color: var(--blue); }
table.heatmap tr.cat-row .rowhead {
  background: #e8dec5;
  font-weight: 700;
}
table.heatmap tr.beh-row .rowhead {
  background: #faf6ec;
  font-weight: 400;
  padding-left: 26px;
}
table.heatmap .twirl {
  display: inline-block;
  width: 12px;
  color: var(--muted);
  font-size: 10px;
}
table.heatmap .rowhead .muted { font-weight: 400; }
table.heatmap thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f4efe1;
}
table.heatmap .corner {
  left: 0;
  z-index: 4;
  background: #f4efe1;
  vertical-align: bottom;
  text-align: left;
  padding: 0 10px 8px;
}
table.heatmap .corner-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
table.heatmap .colhead {
  height: 132px;
  vertical-align: bottom;
  cursor: pointer;
  padding: 6px 0;
}
/* Vertical labels read bottom-to-top and stay within their own column, so the
   header never drifts sideways and leaves no empty band at the left. */
table.heatmap .colhead .rot {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-family: var(--mono);
  font-weight: 600;
  margin: 0 auto;
  max-height: 120px;
  overflow: hidden;
}
table.heatmap .colhead:hover .rot { color: var(--blue); }

/* ---------- treemap ---------- */
.tm-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  min-height: 0;
  width: 100%;
}
.tm-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
/* breadcrumb */
.tm-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tm-crumb {
  appearance: none;
  background: none;
  border: none;
  font: 600 14px var(--sans);
  color: var(--blue);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
}
.tm-crumb:not(.current):hover { background: #eef4ff; }
.tm-crumb.current { color: var(--ink); cursor: default; }
.tm-sep { color: var(--muted); }
/* group-by toggle (segmented control) */
.tm-groupby {
  margin-left: auto;
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.tm-mode {
  appearance: none;
  background: var(--card);
  border: none;
  font: 600 12px var(--mono);
  color: var(--muted);
  cursor: pointer;
  padding: 5px 11px;
}
.tm-mode + .tm-mode { border-left: 1px solid var(--line); }
.tm-mode:not(.active):hover { background: #eef4ff; color: var(--blue); }
.tm-mode.active { background: var(--blue); color: #fff; cursor: default; }

.tm-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
}
#tm-svg { display: block; }
.tm-tile { cursor: pointer; }
.tm-tile rect { stroke: var(--paper); stroke-width: 1; transition: stroke 0.1s; }
.tm-tile:hover rect { stroke: var(--ink); stroke-width: 2; }
.tm-fo { overflow: hidden; pointer-events: none; }
.tm-label {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 2px 5px;
  display: flex;
  font-family: var(--mono);
  line-height: 1.18;
  overflow: hidden;
}
.tm-label.parent { align-items: center; }
.tm-label.leaf { align-items: flex-start; padding-top: 3px; }
.tm-name {
  font-weight: 700;
  font-size: 11px;
}
.tm-label.parent .tm-name { white-space: nowrap; }
.tm-label.leaf .tm-name { white-space: normal; overflow-wrap: anywhere; }

/* ---------- graph ---------- */
.graph-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 12px;
  min-height: 0;
}
.graph-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.graph-search {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  min-width: 150px;
}
.graph-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
}
#graph-svg,
#act-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#graph-svg:active,
#act-svg:active {
  cursor: grabbing;
}
.graph-zoom {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.graph-zoom button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  color: var(--ink, #1d2330);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.graph-zoom button:hover {
  background: var(--card);
  border-color: #b9c2d6;
}
.graph-link {
  stroke-opacity: 0.55;
  transition: opacity 0.15s;
}
.graph-node {
  stroke: #fff;
  stroke-width: 1.5px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.graph-node.ghost {
  stroke: #9aa3b5;
  stroke-dasharray: 2 2;
}
.graph-node.selected {
  stroke: #1d2330;
  stroke-width: 2.5px;
}
.graph-label {
  font-size: 9px;
  fill: var(--muted);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 2.5px;
}
.graph-dim {
  opacity: 0.1;
}
line.graph-dim {
  stroke-opacity: 0.05;
}
/* Transition trigger labels on the Actions tab (shown for the selected node's
   outgoing edges). Halo via paint-order so they read over the edges. */
.graph-edge-label {
  font-size: 8.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  fill: #495057;
  pointer-events: all;
  cursor: help;
  paint-order: stroke;
  stroke: var(--card);
  stroke-width: 3px;
}
/* Inline trigger condition in the Actions dossier. */
.graph-dossier .cond {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #1c7ed6;
}

.graph-dossier {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 80%;
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 28px rgba(0, 0, 0, 0.07);
  overflow: auto;
  padding: 16px 18px;
  font-size: 13px;
}
.graph-dossier[hidden] {
  display: none;
}
.graph-dossier h3 {
  margin: 0 0 2px;
  font-size: 16px;
}
.graph-dossier .dossier-sub {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 14px;
}
.graph-dossier .dossier-close {
  position: absolute;
  top: 8px;
  right: 12px;
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.graph-dossier section {
  margin-bottom: 13px;
}
.graph-dossier h4 {
  margin: 0 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.graph-dossier ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.graph-dossier li {
  padding: 2px 0;
  line-height: 1.35;
  border-bottom: 1px solid var(--line);
}
.graph-dossier li:last-child {
  border-bottom: none;
}
.graph-dossier .src {
  color: var(--muted);
  font-size: 11px;
}
.graph-dossier a.src {
  color: #2b6cb0;
  text-decoration: none;
}
.graph-dossier a.src:hover {
  text-decoration: underline;
}
.graph-dossier .pill {
  display: inline-block;
  font-size: 10px;
  padding: 0 6px;
  border-radius: 999px;
  background: #eef1f8;
  color: #5a6478;
  margin-left: 4px;
}
.dossier-link {
  cursor: pointer;
  font-weight: 600;
  border-bottom: 1px dotted #aab;
}
.dossier-link:hover {
  color: #2b6cb0;
}

/* ---------- footer ---------- */
.footer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 12px 24px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
}
.footer a { color: var(--blue); }
.muted { color: var(--muted); font-weight: 400; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: rgba(29, 35, 48, 0.96);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- loading overlay ---------- */
.loading {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.3s;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading-box { text-align: center; color: var(--muted); }
.star.big {
  font-size: 52px;
  color: var(--yellow);
  animation: spin 1.4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  /* Phones: drop the viewport-pinned shell and let the page scroll naturally.
     (Desktop pins everything to the viewport and scrolls inner panes, which
     leaves no room on a small screen.) */
  html,
  body {
    height: auto;
  }
  body {
    overflow: visible;
  }
  main {
    display: block;
  }
  .panel.active {
    display: block;
  }

  .topbar {
    padding: 14px 14px 0;
  }
  .topbar h1 {
    font-size: 24px;
  }
  .tagline {
    font-size: 12.5px;
    margin-bottom: 10px;
  }
  .tabs {
    flex-wrap: wrap;
  }

  /* Query tab: editor + results first, examples/schema below. */
  #tab-query {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 14px;
  }
  .workspace {
    order: 1;
  }
  .sidebar {
    order: 2;
    width: 100%;
    overflow: visible;
    padding-right: 0;
  }
  .results {
    max-height: 60vh;
  }
  .editor-actions {
    flex-wrap: wrap;
  }
  .CodeMirror,
  #sql {
    height: 150px;
  }

  /* Visual tabs need an explicit height once the page (not a flex parent)
     provides the scroll. */
  .map-wrap,
  .heat-wrap,
  .tm-wrap {
    padding: 12px;
  }
  .map-stage,
  .tm-stage,
  .heat-scroll {
    height: 72vh;
    min-height: 320px;
  }
  .save-wrap {
    padding: 12px;
  }
  table.heatmap .rowhead,
  table.heatmap .corner {
    width: 120px;
    min-width: 120px;
    max-width: 120px;
  }
}
