/* Analytix, xperitus graphical profile, look "Option A": dark blue header, white
   workspace, orange (brand red #FF4330) for actions and active states.
   Palette (brandbook): dark blue #1E274A, light blue #D8ECE9, blue-green #47A8A4,
   red #FF4330 (accent, sparingly), grey 1 #3A3B3B, grey 2 #828586.
   Tints in 20% steps only. Font: Jost (Arial fallback). */
:root {
  --dark: #1E274A;
  --dark-80: #4B526E;        /* secondary text, passes 4.5:1 on white */
  --dark-40: #A5A9B7;        /* input borders */
  --dark-20: #D2D4DB;        /* panel borders */
  /* Crisp theme (0.10): neutral greys instead of light blue, so dark blue + orange stand out. */
  --light: #E8EAF0;          /* chips, soft fills (dark blue 10%) */
  --light-60: #F1F2F5;
  --light-40: #F4F5F7;       /* page ground */
  --light-80: #E8EAF0;       /* hairlines */
  --bg: #F4F5F7;
  --line: #DFE2E7;           /* card and panel borders */
  --muted: #5B6274;          /* secondary text, 6:1 on white */
  --green: #47A8A4;
  --red: #FF4330;
  --grey1: #3A3B3B;
  --orange: #FF4330;
  --orange-40: #FFB4AC;
  --orange-20: #FFD9D6;
  --grey-10: #E9EAED;    /* dark blue 10% */
  --radius: 3px;
  --font: Jost, Arial, sans-serif;
  --mono: ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--dark); background: #fff; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--dark); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
input[type=checkbox], input[type=radio] { accent-color: var(--orange); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; height: 38px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--dark); background: #fff; cursor: pointer; }
.btn:hover { background: var(--grey-10); }
/* Main call to action. White on brand orange is 3.4:1, so the text is large and bold
   (19px / 700 counts as large text, which needs 3:1). */
.btn-cta { height: 42px; padding: 0 22px; border: 0; border-radius: var(--radius); background: var(--orange); color: #fff; font-size: 19px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.btn-cta:hover { background: #E63A28; }
.btn-cta:disabled { background: var(--orange-40); color: var(--dark); cursor: not-allowed; }
.btn-primary { background: var(--dark); color: #fff; border-color: var(--dark); font-weight: 500; }
.btn-primary:hover { background: #2f3a63; }
.btn-primary:disabled { opacity: .55; cursor: progress; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn-dashed { border: 1px dashed var(--orange); background: #fff; }
.input, .select { height: 36px; border: 1px solid var(--dark-40); border-radius: var(--radius); padding: 0 10px; background: #fff; }
.input:focus, .select:focus { border-color: var(--dark); }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: var(--radius); background: transparent; cursor: pointer; }
.icon-btn:hover { border-color: var(--dark-20); background: #fff; }
.icon-btn svg { width: 14px; height: 14px; stroke: var(--dark); fill: none; stroke-width: 1.5; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; background: var(--dark); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 34px; }
.login-logo { height: 46px; width: auto; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: var(--radius); border: 1px solid var(--dark-20); padding: 22px 20px 20px; display: flex; flex-direction: column; gap: 6px; }
.login-card h1 { margin: 0 0 10px; font-size: 19px; font-weight: 600; }
.login-card label { font-size: 13px; font-weight: 500; color: var(--dark-80); margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.login-card .input, .login-card .select { width: 100%; height: 40px; font-size: 15px; }
.login-card .input { background: #EDF3FB; }
.info { width: 15px; height: 15px; display: inline-grid; place-items: center; border: 1.3px solid var(--dark-80); border-radius: 50%; font-size: 10px; font-weight: 600; cursor: help; }
.btn-login { margin-top: 16px; height: 44px; border: 0; border-radius: var(--radius); background: var(--orange); color: #fff; font-weight: 700; font-size: 19px; cursor: pointer; }
.btn-login:disabled { opacity: .65; cursor: progress; }
.form-error { margin-top: 10px; padding: 9px 11px; border-radius: var(--radius); background: #FFE3E0; color: #7A1A10; font-size: 13px; line-height: 1.4; }

/* ---------- app shell ---------- */
.topbar { background: var(--dark); color: #fff; padding: 10px 28px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; }
.brand { display: flex; align-items: center; gap: 16px; flex: 1 1 260px; }
.brand img { height: 28px; width: auto; display: block; }
.brand .divider { width: 1px; height: 24px; background: var(--dark-80); }
.brand .product { font-weight: 300; font-size: 22px; color: var(--light); text-decoration: none; }
.topbar .right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.env-tag { border: 1px solid var(--orange); color: #fff; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: var(--radius); letter-spacing: .04em; }
.topbar a, .topbar .btn-ghost { color: #fff; text-decoration: none; }
.topbar .btn-ghost { height: 34px; border: 1px solid #4B526E; }
.topbar .btn-ghost:hover { background: #2f3a63; }
.mainnav { display: flex; gap: 22px; align-items: center; }
.mainnav a { color: var(--light); text-decoration: none; padding: 8px 0; }
.mainnav a:hover { color: #fff; }
.mainnav a[aria-current="page"] { color: #fff; font-weight: 500; box-shadow: inset 0 -3px 0 var(--orange); }

.titlebar { background: #fff; padding: 20px 28px 4px; display: flex; align-items: center; gap: 12px; }
.titlebar .bar { width: 4px; height: 28px; background: var(--orange); }
.titlebar h1 { margin: 0; font-weight: 300; font-size: 32px; }
.titlebar { flex-wrap: wrap; }
.titlebar h1 { flex: 1 1 300px; }
.title-actions { display: flex; gap: 10px; align-items: center; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 190px; background: #fff; border: 1px solid var(--dark-20); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(30, 39, 74, .14); padding: 4px; display: flex; flex-direction: column; }
.menu button { text-align: left; padding: 9px 12px; border: 0; background: transparent; border-radius: var(--radius); cursor: pointer; font-size: 14px; }
.menu button:hover, .menu button:focus-visible { background: var(--light); }
.chip-label { border: 0; background: transparent; color: inherit; font: inherit; padding: 2px 4px; border-radius: var(--radius); min-width: 40px; }
.chip-label:hover { background: rgba(255,255,255,.35); }
.chip.mea .chip-label:hover { background: rgba(255,255,255,.12); }
.chip.dim .chip-label:focus, .chip.mea .chip-label:focus, .chip-label:focus { outline: 2px solid var(--orange); background: #fff; color: var(--dark); }
.chip.mea:focus-within { background: #fff; color: var(--dark); box-shadow: inset 0 0 0 1px var(--dark); }
.chip.mea:focus-within select { background: var(--grey-10); }
.chip .grip { font-size: 11px; letter-spacing: -2px; opacity: .55; cursor: grab; margin-right: -2px; }
.chip[draggable="true"] { cursor: grab; }
.shelf.drop-here { border-color: var(--orange); border-style: solid; background: var(--orange-20); }
.field[draggable="true"] { cursor: grab; }
.kpi { position: relative; }
.kpi-x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border: 0; border-radius: var(--radius); background: transparent; color: var(--dark-80); font-size: 16px; cursor: pointer; }
.kpi-x:hover { background: var(--grey-10); }
.kpi-picks { display: flex; flex-wrap: wrap; gap: 6px 18px; padding-left: 26px; }
table.grid tbody tr:not(.total):hover td { background: var(--light); }
table.grid th[draggable="true"] { cursor: grab; }
table.grid th.drop-before { box-shadow: inset 3px 0 0 var(--orange); }
.chart-head { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.chart-head h3 { flex: 1; margin: 0; }
.chart-head .icon-btn { width: 28px; height: 28px; color: var(--dark-80); }

.workspace { display: flex; flex-wrap: wrap; gap: 20px; padding: 20px 28px; align-items: flex-start; }
.panel { background: #fff; border: 1px solid var(--dark-20); border-radius: var(--radius); }
.panel-head { font-size: 15px; font-weight: 500; }
.muted { color: var(--dark-80); font-size: 13px; }

/* ---------- fields panel ---------- */
.fields-panel { flex: 1 1 300px; max-width: 360px; min-width: 280px; display: flex; flex-direction: column; }
.source-box { padding: 16px; border-bottom: 1px solid var(--light-80); display: flex; flex-direction: column; gap: 8px; }
.source-row { display: flex; gap: 8px; }
.source-row .input { flex: 1; min-width: 0; text-transform: uppercase; }
.field-search { padding: 12px 16px 6px; }
.field-search .input { width: 100%; }
.field-list-head { display: grid; grid-template-columns: minmax(0, 1fr) 52px 58px 32px; gap: 4px; padding: 6px 16px; font-size: 12px; color: var(--dark-80); }
.field-list-head span:nth-child(n+2) { text-align: center; }
.field-group { padding: 10px 16px 4px; font-size: 15px; font-weight: 500; border-top: 1px solid var(--light-80); }
.field-list { list-style: none; margin: 0; padding: 0 8px 10px; max-height: 62vh; overflow-y: auto; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) 52px 58px 32px; gap: 4px; align-items: center; padding: 5px 8px; border-radius: var(--radius); }
.field:hover { background: var(--grey-10); }
.field .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.field .label { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; }
.field .tag { font-size: 11px; color: var(--dark-80); white-space: nowrap; }
.field .check { display: grid; place-items: center; }
.field input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; }
.alias { font-family: var(--mono); font-size: 11px; padding: 2px 5px; border-radius: 3px; min-width: 42px; text-align: center; flex: none; }
.alias.dim { background: var(--light); color: var(--dark); }
.alias.mea { background: var(--dark); color: #fff; }
.field-label-wrap { display: flex; flex-direction: column; min-width: 0; }

.wide-input { width: 100%; }
.source-filters { display: flex; gap: 6px; margin-top: 8px; }
.source-filters .select { flex: 1; min-width: 0; height: 32px; font-size: 13px; }
.obj-results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.obj-results:empty { display: none; }
.obj-result { display: flex; flex-direction: column; gap: 2px; padding: 7px 8px; border-radius: var(--radius); cursor: pointer; }
.obj-result:hover, .obj-result.active { background: var(--light); }
.obj-result .top { display: flex; align-items: center; gap: 8px; }
.obj-result .desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.obj-result .meta { font-size: 12px; color: var(--dark-80); padding-left: 2px; }
.obj-more { font-size: 12px; color: var(--dark-80); padding: 6px 8px; }
.selected-source { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.sel-main { font-size: 15px; font-weight: 500; }

/* ---------- query + results ---------- */
.main-col { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.query { padding: 16px 18px; display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 12px 14px; align-items: start; }
.query .row-label { font-size: 15px; font-weight: 500; padding-top: 7px; }
.shelf { display: flex; flex-wrap: wrap; gap: 8px; min-height: 40px; border: 1px dashed var(--dark-40); border-radius: var(--radius); padding: 5px; align-items: center; }
.shelf .empty { font-size: 13px; color: var(--dark-80); padding: 0 6px; }
.chip { height: 32px; display: inline-flex; align-items: center; gap: 6px; padding: 0 4px 0 12px; border-radius: var(--radius); font-size: 14px; }
.chip.dim { background: var(--light); }
.chip.mea { background: var(--dark); color: #fff; }
.chip select { height: 24px; border: 0; border-radius: var(--radius); padding: 0 2px; font-size: 12px; font-weight: 600; background: rgba(255,255,255,.15); color: inherit; }
.chip.mea select option { color: var(--dark); }
.chip .x { width: 24px; height: 24px; border: 0; background: transparent; color: inherit; cursor: pointer; border-radius: var(--radius); font-size: 16px; line-height: 1; }
.chip .x:hover { background: rgba(0,0,0,.08); }
.chip.mea .x:hover { background: rgba(255,255,255,.15); }
.chip label { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.filters { display: flex; flex-direction: column; gap: 6px; }
.filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 8px; background: #fff; border: 1px dashed var(--orange); border-radius: var(--radius); }
.filter .fname { font-weight: 500; min-width: 120px; }
.filter .select, .filter .input { height: 32px; }
.filter .input { width: 160px; }
.filter .input.wide { width: 240px; }
.sortrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sortrow .input { width: 70px; }
.run-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-top: 4px; border-top: 1px solid var(--light-80); }
.plan { font-size: 13px; color: var(--dark-80); }

.results { padding: 16px 18px; display: flex; flex-direction: column; gap: 16px; }
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.results-head h2 { margin: 0; font-size: 22px; font-weight: 300; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi { background: #fff; border: 1px solid var(--dark-20); border-top: 4px solid var(--orange); border-radius: var(--radius); padding: 14px 16px; }
.kpi .k-label { font-size: 13px; color: var(--dark-80); }
.kpi .k-value { font-size: 30px; font-weight: 300; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.chart { display: flex; flex-direction: column; gap: 6px; }
.chart h3 { margin: 0 0 2px; font-size: 15px; font-weight: 500; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 220px) minmax(0, 1fr) 130px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .b-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--grey-10); height: 16px; border-radius: 3px; }
.bar { background: var(--green); height: 16px; border-radius: 3px; }
.bar.neg { background: var(--dark-40); }
.bar-row .b-val { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; border: 1px solid var(--light-80); border-radius: var(--radius); max-height: 70vh; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { position: sticky; top: 0; background: var(--dark); color: #fff; font-weight: 500; text-align: left; padding: 9px 12px; white-space: nowrap; }
table.grid th button { all: unset; cursor: pointer; }
table.grid th button:focus-visible { outline: 2px solid var(--green); }
table.grid td { padding: 7px 12px; border-bottom: 1px solid var(--light-80); white-space: nowrap; }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tr.total td { background: var(--grey-10); font-weight: 500; position: sticky; bottom: 0; }
.notice { padding: 9px 11px; border-radius: var(--radius); background: var(--light); font-size: 13px; line-height: 1.45; }
.notice.error { background: #FFE3E0; color: #7A1A10; white-space: pre-wrap; }
.empty-state { padding: 36px 18px; text-align: center; color: var(--dark-80); }
.empty-state strong { display: block; color: var(--dark); font-size: 18px; font-weight: 400; margin-bottom: 6px; }

.tabs { display: flex; gap: 4px; margin-bottom: -18px; }
.tab { height: 42px; padding: 0 20px; border: 1px solid transparent; border-bottom: 0; border-radius: var(--radius) 8px 0 0; background: transparent; cursor: pointer; font-size: 15px; }
.tab[aria-selected="true"] { background: #fff; border-color: var(--dark-20); font-weight: 500; box-shadow: inset 0 -3px 0 var(--orange); position: relative; top: 1px; }
.layout { padding: 16px 18px; display: flex; flex-direction: column; gap: 18px; }
.lay-section { display: flex; flex-direction: column; gap: 10px; }
.lay-section + .lay-section { border-top: 1px solid var(--light-80); padding-top: 16px; }
.lay-section h3 { margin: 0; font-size: 20px; font-weight: 300; }
.check-line { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check-line input { width: 18px; height: 18px; accent-color: var(--orange); }
.lay-card { border: 1px solid var(--dark-20); background: #fff; border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.lay-card-head { display: flex; align-items: center; gap: 4px; }
.lay-card-head .spacer { flex: 1; }
.lay-grid { display: grid; grid-template-columns: 60px minmax(0, 1fr) 60px minmax(0, 1fr); gap: 8px 10px; align-items: center; }
.lay-grid .select, .lay-grid .input { width: 100%; height: 34px; }
.lay-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 22px 28px; }
.chart { margin: 0; min-width: 0; }
.pie-wrap { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
svg.pie { width: 190px; height: 190px; flex: none; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 180px; min-width: 0; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.legend li { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto 52px; gap: 8px; align-items: center; }
.legend .swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--dark-20); }
.legend .l-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .l-val, .legend .l-pct { text-align: right; font-variant-numeric: tabular-nums; }
.legend .l-pct { color: var(--dark-80); }

/* ---------- modes: home (landing / run) and designer ---------- */
body.mode-home .designer-frame, body.mode-home .fields-panel, body.mode-home .tabs, body.mode-home #queryNav, body.mode-home #queryPanel, body.mode-home #layoutPanel, body.mode-home #optionsPanel, body.mode-home .designer-only { display: none !important; }
body.mode-designer .home-only { display: none !important; }
.menu-toggle { width: 42px; height: 42px; flex: none; border: 1px solid var(--dark); border-radius: var(--radius); background: #fff; cursor: pointer; display: inline-grid; place-items: center; }
.menu-toggle svg path { stroke: var(--dark); stroke-width: 1.8; }
.menu-toggle[aria-expanded="true"] { background: var(--dark); }
.menu-toggle[aria-expanded="true"] svg path { stroke: #fff; }
.title-block h1 { flex: none; margin: 0; }
.title-block { flex: 1 1 360px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.crumb { font-size: 13px; color: var(--dark-80); min-height: 0; }
.crumb:empty { display: none; }
.title-sub { font-size: 14px; color: var(--dark-80); }
.title-sub:empty { display: none; }
.title-sub .link { background: none; border: 0; padding: 0; color: var(--dark); text-decoration: underline; cursor: pointer; font: inherit; }
.title-sub .unsaved { color: #A3200F; }
.title-input { font: inherit; font-weight: 300; font-size: 32px; color: var(--dark); border: 0; border-bottom: 1px dashed var(--dark-40); padding: 0 0 2px; background: transparent; width: 100%; max-width: 760px; }
.title-input:focus { outline: none; border-bottom: 2px solid var(--orange); }
.titlebar .bar { display: none; }
.split { display: inline-flex; }
.split #saveBtn { border-radius: var(--radius) 0 0 var(--radius); font-weight: 500; }
.split .split-arrow { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; padding: 0 10px; }
.scrim { position: fixed; inset: 0; background: rgba(30, 39, 74, .35); z-index: 30; }
.reports-menu { position: fixed; left: 0; top: 0; bottom: 0; width: min(340px, 90vw); background: var(--dark); color: #fff; z-index: 31; padding: 18px 14px; display: flex; flex-direction: column; gap: 12px; box-shadow: 8px 0 24px rgba(30,39,74,.3); padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
.rm-head { display: flex; align-items: center; padding: 0 4px; }
.rm-head span { flex: 1; font-size: 22px; font-weight: 300; }
.rm-close { width: 34px; height: 34px; border: 0; background: transparent; color: var(--light); font-size: 24px; cursor: pointer; border-radius: var(--radius); }
.rm-close:hover { background: #2C3660; }
.rm-close.dark { color: var(--dark-80); }
.rm-close.dark:hover { background: var(--grey-10); }
.rm-search { height: 38px; border-radius: var(--radius); border: 0; background: #2C3660; color: #fff; padding: 0 12px; }
.rm-search::placeholder { color: var(--light); }
.rm-tree { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.rm-folder { display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--radius); background: transparent; color: #fff; font-weight: 500; cursor: pointer; text-align: left; }
.rm-folder:hover { background: #2C3660; }
.rm-folder .count { margin-left: auto; font-size: 12px; color: var(--light); font-weight: 400; }
.rm-report { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px 7px 38px; border: 0; border-radius: var(--radius); background: transparent; color: #fff; cursor: pointer; text-align: left; }
.rm-report:hover { background: #2C3660; }
.rm-report[aria-current="true"] { background: #fff; color: var(--dark); font-weight: 500; }
.rm-report .rname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-report .lock { font-size: 11px; opacity: .8; }
.rm-empty { color: var(--light); font-size: 13px; padding: 4px 10px 8px 38px; }
.rm-foot { font-size: 12px; color: var(--light); }
.star { color: var(--dark-40); }
.star.on { color: var(--orange); }
.info-card { position: fixed; z-index: 32; left: min(370px, 5vw); top: 120px; width: min(560px, 90vw); max-height: calc(100vh - 150px); overflow-y: auto; background: #fff; border-radius: var(--radius); border-top: 4px solid var(--orange); box-shadow: 0 18px 50px rgba(30,39,74,.35); padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 900px) { .info-card { left: 5vw; } }
.info-card h2 { margin: 0; font-weight: 300; font-size: 26px; }
.info-grid { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 7px 12px; font-size: 14px; }
.info-grid dt { color: var(--dark-80); }
.info-grid dd { margin: 0; }
.info-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.save-dialog { width: min(580px, calc(100vw - 32px)); border: 0; border-radius: var(--radius); padding: 0; box-shadow: 0 18px 50px rgba(30,39,74,.35); color: var(--dark); }
.save-dialog::backdrop { background: rgba(30, 39, 74, .45); }
.sd-head { padding: 20px 24px 6px; display: flex; align-items: center; gap: 10px; }
.sd-head .bar { width: 4px; height: 24px; background: var(--orange); }
.sd-head h2 { margin: 0; font-weight: 300; font-size: 26px; flex: 1; }
.sd-body { padding: 10px 24px 4px; display: flex; flex-direction: column; gap: 14px; }
.sd-foot { padding: 16px 24px 20px; display: flex; justify-content: flex-end; gap: 10px; }
.field-block { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.field-block .input { width: 100%; height: 40px; font-size: 15px; font-weight: 400; }
.field-block .muted { font-weight: 400; }
.textarea { height: auto !important; padding: 10px 12px; resize: vertical; font-size: 14px !important; line-height: 1.4; }
.req { color: var(--orange); }
.name-check { font-size: 13px; font-weight: 400; min-height: 18px; }
.name-check.ok { color: #1F6F6B; }
.name-check.bad { color: #A3200F; }
.toggles { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--dark-20); border-radius: var(--radius); }
.toggle-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; cursor: pointer; }
.toggle-row + .toggle-row { border-top: 1px solid var(--grey-10); }
.toggle-row > span { display: flex; flex-direction: column; gap: 2px; }
.toggle-row strong { font-weight: 500; }
.toggle-row.disabled { opacity: .5; cursor: not-allowed; }
input.switch { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; flex: none; border-radius: 11px; background: var(--dark-40); position: relative; cursor: pointer; margin: 1px 0 0; transition: background .15s; }
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
input.switch:checked { background: var(--orange); }
input.switch:checked::after { left: 19px; }
input.switch:disabled { cursor: not-allowed; }
.versions { display: flex; flex-direction: column; }
.version-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--grey-10); font-size: 13px; }
.version-row .v { font-weight: 600; }
.version-row .v.current { color: var(--orange); }
.opt-grid .span-2 { grid-column: 1 / -1; }
.opt-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 20px; }
@media (max-width: 800px) { .opt-grid { grid-template-columns: 1fr; } }
.danger { color: #A3200F; border-color: #A3200F; }
.landing-empty { padding: 36px 18px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--dark-80); }
.landing-empty strong { color: var(--dark); font-size: 20px; font-weight: 300; }

/* ---------- joins ---------- */
.query-nav { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--grey-10); }
.qnav { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 12px; border: 1px solid var(--dark-20); border-radius: var(--radius); background: #fff; cursor: pointer; text-align: left; max-width: 340px; }
.qnav:hover { background: var(--grey-10); }
.qnav.active { border: 2px solid var(--orange); padding: 3px 11px; }
.qnav .qname { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qnav .qsub { font-size: 12px; color: var(--dark-80); white-space: nowrap; }
.qnav.add { border-style: dashed; border-color: var(--orange); }
.qnav.add:disabled { opacity: .5; cursor: not-allowed; }
.qtag { padding: 2px 8px; border-radius: var(--radius); background: var(--dark); color: #fff; font-size: 11px; font-weight: 600; letter-spacing: .03em; white-space: nowrap; }
.qnav.join .qtag, .qtag.join { background: var(--orange); }
.join-editor { grid-column: 1 / -1; border: 2px solid var(--orange); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.jhead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.jhead .input { width: 200px; font-weight: 500; }
.jhead .spacer { flex: 1; }
.jrow { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; align-items: start; }
.jlabel { font-weight: 500; padding-top: 8px; }
.jcol { display: flex; flex-direction: column; gap: 8px; }
.join-types { display: flex; flex-wrap: wrap; gap: 8px; }
.jt { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--dark-40); border-radius: var(--radius); background: #fff; cursor: pointer; font-size: 13px; }
.jt.on { border: 2px solid var(--orange); padding: 5px 11px; font-weight: 500; }
.venn-line { fill: none; stroke: var(--dark); stroke-width: 1.2; }
.venn-fill { fill: var(--dark-40); opacity: .6; }
.jt.on .venn-fill { fill: var(--orange); opacity: .9; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr) minmax(110px, auto) 32px; gap: 8px; align-items: center; }
.pair .select { width: 100%; background: var(--light); border-color: var(--light); }
.pair .eq { text-align: center; font-weight: 700; color: #1F6F6B; }
.tc { font-size: 12px; }
.tc.ok { color: #1F6F6B; }
.tc.warn { color: #6B3A00; }
.suggest { padding: 7px 10px; border-radius: var(--radius); background: var(--orange-20); font-size: 13px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--dark); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; align-self: flex-start; }
.drag-keys { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; border: 1px dashed var(--dark-40); border-radius: var(--radius); background: var(--grey-10); }
.keychip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius); background: var(--light); font-size: 13px; cursor: grab; }
.field.drop-key { outline: 2px solid var(--orange); background: var(--orange-20); }
.radio-line { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.radio-line input { accent-color: var(--orange); width: 16px; height: 16px; }
.notice.warn { background: #FFF4E0; color: #6B3A00; }
.key-note { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 5px; border-radius: 3px; background: #fff; color: var(--dark-80); }
@media (max-width: 700px) { .jrow { grid-template-columns: 1fr; } .pair { grid-template-columns: 1fr; } }

/* ---------- custom fields ---------- */
.calc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.alias.calc { background: var(--orange-20); color: var(--dark); font-style: italic; }
.field.calc { grid-template-columns: minmax(0, 1fr) 52px 58px 64px; }
.calc-actions { display: flex; }
.calc-actions .icon-btn { width: 28px; height: 28px; }
.calc-dialog { width: min(680px, calc(100vw - 32px)); }
.cd-body { display: flex; flex-direction: column; gap: 12px; }
.cd-fields { display: flex; flex-direction: column; gap: 6px; }
.cd-row { display: flex; gap: 6px; align-items: center; }
.cd-row .select { flex: 1; }
.cd-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cd-insert { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cd-insert .select { flex: 1 1 260px; min-width: 0; height: 32px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.mono { font-family: var(--mono) !important; font-size: 13px !important; }
.field-block .select { width: 100%; height: 40px; font-weight: 400; }

/* ---------- more charts ---------- */
.svg-wrap { width: 100%; overflow-x: auto; }
svg.colchart, svg.mapchart { width: 100%; height: auto; display: block; }
svg.colchart .axis { font-size: 11px; fill: var(--dark-80); font-family: var(--font); }
svg.colchart .grid-line { stroke: var(--grey-10); }
svg.colchart .zero-line { stroke: var(--dark-40); }
.bar-track.stack { display: flex; overflow: hidden; }
.bar-track.stack .seg { height: 16px; }
.bar-track.stack .seg:first-child { border-radius: 3px 0 0 3px; }
.legend.inline { flex-direction: row; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; }
.legend.inline li { display: inline-flex; gap: 6px; grid-template-columns: none; }
.map-legend { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 6px; font-size: 12px; }
.map-step { width: 26px; height: 10px; display: inline-block; }
svg.mapchart .map-label { fill: var(--dark); font-family: var(--font); paint-order: stroke; stroke: #fff; stroke-width: 0.25px; }
.lay-card > .lay-grid + .lay-grid { margin-top: 2px; }

/* ---------- console ---------- */
.console { padding: 18px 24px; display: flex; flex-direction: column; gap: 18px; max-width: 1200px; }
.console section { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.console h2 { margin: 0; font-size: 22px; font-weight: 300; }
.env-table { width: 100%; border-collapse: collapse; }
.env-table th { text-align: left; font-weight: 500; font-size: 13px; padding: 6px 8px; background: var(--grey-10); }
.env-table td { padding: 6px 8px; border-bottom: 1px solid var(--light-80); }
.env-table .input { width: 100%; }
.env-table td.c { text-align: center; }
.users { display: flex; flex-wrap: wrap; gap: 8px; }
.user-chip { height: 32px; display: inline-flex; align-items: center; gap: 6px; padding: 0 4px 0 12px; border-radius: var(--radius); background: var(--light); }
.user-chip .x { width: 24px; height: 24px; border: 0; background: transparent; cursor: pointer; border-radius: var(--radius); font-size: 16px; }
.user-chip.locked { padding-right: 12px; }
.add-user { display: flex; gap: 8px; }
.add-user .input { width: 180px; text-transform: uppercase; }
.save-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

@media (max-width: 700px) {
  .charts { grid-template-columns: 1fr; }
  .lay-grid { grid-template-columns: 60px minmax(0, 1fr); }
  .query { grid-template-columns: 1fr; }
  .query .row-label { padding-top: 0; }
  .bar-row { grid-template-columns: 100px minmax(0, 1fr) 100px; }
  .titlebar h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


/* =====================================================================
   Crisp theme (0.10). Everything visual is driven by the tokens above and
   the rules below, so new screens that use the standard classes
   (panel, btn, btn-cta, chip, lay-card, notice, field-block, table.grid)
   get this look without extra work.
   ===================================================================== */
body { background: var(--bg); }
:focus-visible { outline: 2px solid var(--dark); outline-offset: 2px; }
input[type=checkbox], input[type=radio], .field input[type=checkbox], .check-line input, .radio-line input { accent-color: var(--dark); }
input.switch:checked { background: var(--dark); }

/* header and title strip */
.topbar { padding: 0 24px; min-height: 48px; }
.brand img { height: 22px; }
.brand .product { font-size: 18px; color: #fff; }
.titlebar { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 24px; align-items: center; }
.title-block h1, .titlebar h1 { font-size: 24px; font-weight: 400; }
.title-input { font-size: 24px; font-weight: 400; }
.crumb { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.menu-toggle { width: 36px; height: 36px; border-color: var(--line); }
.btn { height: 34px; border-radius: var(--radius); }
.btn-cta { height: 36px; padding: 0 18px; font-size: 18.7px; } /* 14pt bold = large text: white on orange passes */
.btn-small { height: 30px; }

/* layout */
.workspace { gap: 16px; padding: 16px 24px; }
.main-col { gap: 16px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: none; }
.panel-head, .field-group, .row-label, .lay-section h3, .console h2, .results-head h2 {
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.results-head h2 { font-size: 12px; }
.row-label, .query .row-label { padding-top: 9px; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.muted, .plan, .title-sub { color: var(--muted); }

/* Query / Layout / Options: plain text tabs */
.tabs { margin-bottom: 0; gap: 22px; border-bottom: 1px solid var(--line); }
.tab { height: 40px; padding: 0; border: 0; background: transparent; color: var(--muted); }
.tab[aria-selected="true"] { background: transparent; border: 0; color: var(--dark); font-weight: 500; box-shadow: inset 0 -2px 0 var(--dark); top: 1px; }

/* main / join queries: folder tabs above the query panel */
.query-nav { display: flex; align-items: flex-end; gap: 0; flex-wrap: wrap; padding: 0; border: 0; margin-bottom: -17px; position: relative; z-index: 2; }
.qnav { height: 40px; max-width: 380px; padding: 0 28px 0 14px; margin: 0 -10px 0 0; border: 0; border-radius: 0; background: #E6E8EC; color: var(--muted);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 100%, 0 100%); gap: 8px; }
.qnav:hover { background: #DCDFE5; }
.qnav.active { background: #fff; color: var(--dark); height: 42px; border: 0; padding: 0 28px 0 14px; box-shadow: inset 0 2px 0 var(--dark); z-index: 3; }
.qnav.join.active { box-shadow: inset 0 2px 0 var(--orange); }
.qnav .qtag, .qnav.join .qtag { background: none; color: inherit; padding: 0; font-size: 10px; font-weight: 700; letter-spacing: .07em; }
.qnav.join.active .qtag { color: #C42B1B; }
.qnav .qsub, .qnav.active .qsub { display: none; }
.qnav.add { clip-path: none; height: 30px; margin: 0 0 6px 18px; padding: 0 12px; border: 1px dashed var(--dark-40); border-radius: var(--radius); background: transparent; color: var(--dark); }
.qnav.add:hover { background: #fff; }
#queryPanel { border-top-left-radius: 0; }
.join-editor { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 0 0 14px; }
.qtag.join { background: none; color: #C42B1B; padding: 0; font-size: 10px; font-weight: 700; letter-spacing: .07em; }
.jlabel { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding-top: 9px; }
.join-types { gap: 0; }
.jt { border-radius: 0; border: 1px solid var(--line); margin-left: -1px; padding: 5px 12px; }
.jt:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.jt:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.jt.on { background: var(--dark); color: #fff; border: 1px solid var(--dark); padding: 5px 12px; font-weight: 500; }
.jt.on .venn-line { stroke: #fff; }
.jt.on .venn-fill { fill: #fff; opacity: .9; }
.pair .select { background: var(--light); border-color: var(--light); }
.suggest { background: var(--light-60); border: 1px solid var(--line); }

/* shelves and chips */
.shelf { border: 1px dashed var(--line); border-radius: var(--radius); }
.chip { border-radius: var(--radius); height: 30px; }
.chip.dim { background: var(--light); }
.filter { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); }
.query { gap: 10px 14px; }

/* field list */
.alias, .alias.dim, .alias.mea, .alias.calc { background: transparent; color: var(--muted); padding: 0; min-width: 40px; text-align: left; }
.alias.calc { font-style: italic; }
.field { border-radius: 0; border-bottom: 1px solid var(--light-60); }
.field:hover { background: var(--light-60); }
.obj-result:hover, .obj-result.active { background: var(--light); }

/* results: a dashboard of cards on the grey page */
.results { background: transparent; border: 0; padding: 0; gap: 16px; }
.results > .empty-state, .results > .landing-empty, .results > .notice { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.results-head { padding: 0 2px; }
.kpis { gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpi { background: #fff; border: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .k-label { font-size: 13px; color: var(--muted); }
.kpi .k-value { font-size: 30px; font-weight: 500; letter-spacing: -.01em; }
.charts { gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.chart { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.chart h3, .chart-head h3 { font-size: 14px; font-weight: 500; }
.bar-track { background: var(--light-60); border-radius: 2px; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table.grid th { background: #fff; color: var(--muted); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--line); }
table.grid th button { color: var(--muted); }
table.grid td { border-bottom: 1px solid var(--light-60); }
table.grid tbody tr:not(.total):hover td { background: var(--light-60); }
table.grid tr.total td { background: var(--light-60); }
.notice { background: var(--light-60); border-radius: var(--radius); }
.notice.error { background: #FDECEA; }

/* Layout and Options tabs, console */
.layout { gap: 16px; }
.lay-card { background: #fff; border: 1px solid var(--line); }
.toggles { border-color: var(--line); }
.env-table th { background: var(--light-60); }
.user-chip { background: var(--light); }
.info-card { border-top: 2px solid var(--dark); border-radius: var(--radius); }
.save-dialog { border-radius: var(--radius); }
.login-card { border-radius: var(--radius); }
.btn-login { border-radius: var(--radius); font-size: 18.7px; }
.rm-search { border-radius: var(--radius); }

/* ---------- subtotals and pivots ---------- */
.st-wrap { display: flex; flex-direction: column; gap: 10px; }
.st-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.st-toggle { width: 22px; height: 22px; border: 0; background: transparent; color: var(--muted); cursor: pointer; margin-right: 4px; padding: 0; font-size: 12px; }
.st-toggle:hover { color: var(--dark); }
table.grid tr.st-sub td { background: var(--light-60); font-weight: 500; }
table.grid tr.st-sub.lvl-1 td { background: #FAFAFB; }
.st-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.st-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 12px; }
.st-card-head .st-name { font-weight: 500; }
.st-card-head .spacer { flex: 1; }
.st-val { display: inline-flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.st-val .muted { font-size: 11px; }
.st-total { background: var(--light-60); }
.table-wrap.flat { border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.pivots { display: flex; flex-direction: column; gap: 16px; }
.pivot .chart-head { gap: 12px; }
.check-line.small { font-size: 13px; color: var(--muted); }
table.pivot-grid th.grp, table.pivot-grid td.grp { border-left: 1px solid var(--line); }
table.pivot-grid th.tot { background: var(--light-60); }
table.pivot-grid .sticky { position: sticky; left: 0; background: #fff; z-index: 1; }
table.pivot-grid tr.st-sub .sticky, table.pivot-grid tr.total .sticky { background: var(--light-60); }
.pv-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; }
.pv-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.pv-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; align-items: center; }
.pv-checks { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.select.small { height: 30px; font-size: 13px; }
.muted.pad { padding: 14px 16px; margin: 0; }
@media (max-width: 700px) { .pv-row { grid-template-columns: 1fr; } }

/* charts keep their height on wide screens */
svg.mapchart { max-height: 460px; }
body.tab-layout .fields-panel, body.tab-options .fields-panel { display: none; }

/* ---------- designer frame (0.12): numbered tabs on one white frame ---------- */
.workspace { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
.designer-frame { display: flex; flex-direction: column; }
.frame-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.frame-tabs .tab { height: auto; padding: 11px 20px; font-size: 15px; color: var(--muted); background: transparent; border: 1px solid transparent; border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0; box-shadow: none; display: inline-flex; align-items: center; gap: 8px; top: 0; }
.frame-tabs .tab:hover { color: var(--dark); background: #fff; }
.frame-tabs .tab[aria-selected="true"] { background: #fff; color: var(--dark); font-weight: 500; border-color: var(--line); margin-bottom: -1px; padding-bottom: 12px;
  box-shadow: inset 0 3px 0 var(--orange); }
.tab-num { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--dark-40); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.tab[aria-selected="true"] .tab-num { background: var(--dark); border-color: var(--dark); color: #fff; }
.tab-sum { font-size: 12px; font-weight: 400; color: var(--muted); }
.tab-sum:not(:empty)::before { content: "· "; }
.frame-body { background: #fff; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); padding: 16px; display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.frame-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 0; }
.frame-body .fields-panel { border: 1px solid var(--line); }
.frame-main #layoutPanel, .frame-main #optionsPanel { border: 0; padding: 0; }
.frame-main .query-nav { margin-bottom: -1px; }
.frame-main #queryPanel { border-radius: 0 var(--radius) var(--radius) var(--radius); }
@media (max-width: 700px) { .frame-tabs .tab { padding: 9px 12px; } .tab-sum { display: none; } }
