/**
 * The look, borrowed from `expense/` and `read/`: a rail, a column, hairlines,
 * and colour rationed to the things that mean something.
 *
 * The palette is Notion's, for the reason those apps use it — this is a page
 * somebody opens several times a day, and the fastest interface to learn is one
 * that behaves like an interface they already know.
 *
 * Two things are specific to this app:
 *
 *   the figure     any number that can be asked where it came from gets a
 *                  dotted underline. That convention is the whole of the
 *                  discoverability of the trace panel, so it has to be
 *                  consistent everywhere and quiet everywhere.
 *
 *   the tablet     this is used at a meeting table and on site. Columns shrink
 *                  and then stack; nothing hides behind a menu, because a menu
 *                  is a thing to explain while a client waits.
 */

:root {
  color-scheme: light dark;

  --page: #ffffff;
  --rail: #f7f7f5;
  --sunken: #fbfbfa;
  --text: #37352f;
  --muted: #73716c;
  --faint: #91908c;
  --line: rgba(55, 53, 47, 0.09);
  --hover: rgba(55, 53, 47, 0.055);
  --active: rgba(55, 53, 47, 0.08);
  /* Alternating band on long lists. Deliberately below --hover: it has to be
     readable as rhythm and invisible as decoration. */
  --stripe: rgba(55, 53, 47, 0.028);

  --accent: #2383e2;
  --accent-ink: #1b6fc2;
  --accent-soft: rgba(35, 131, 226, 0.1);
  --accent-glow: rgba(35, 131, 226, 0.22);

  --danger: #c4554d;
  --danger-soft: rgba(196, 85, 77, 0.1);
  --ok: #0f7b6c;
  --ok-soft: rgba(15, 123, 108, 0.1);
  --warn: #cb7b37;
  --warn-soft: rgba(203, 123, 55, 0.11);
  --critical: #c4554d;

  /* Chart slices. Six, because nothing here has more categories than that at
     once, and a seventh would have to be a colour that means nothing. */
  --slice-1: #2383e2;
  --slice-2: #0f7b6c;
  --slice-3: #cb7b37;
  --slice-4: #9065b0;
  --slice-5: #c4554d;
  --slice-6: #7d8f9a;

  --paper: #ffffff;

  --shadow: 0 0 0 1px rgba(15, 15, 15, 0.05), 0 3px 6px rgba(15, 15, 15, 0.1),
    0 9px 24px rgba(15, 15, 15, 0.2);
  --focus: 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-glow);

  --sidebar-width: 236px;
  --radius: 6px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #191919;
    --rail: #202020;
    --sunken: #1d1d1d;
    --text: rgba(255, 255, 255, 0.81);
    --muted: rgba(255, 255, 255, 0.53);
    --faint: rgba(255, 255, 255, 0.4);
    --line: rgba(255, 255, 255, 0.094);
    --hover: rgba(255, 255, 255, 0.055);
    --active: rgba(255, 255, 255, 0.08);
    --stripe: rgba(255, 255, 255, 0.03);

    --accent: #4a9eff;
    --accent-ink: #6bb0ff;
    --accent-soft: rgba(74, 158, 255, 0.14);
    --accent-glow: rgba(74, 158, 255, 0.26);

    --danger: #ff7369;
    --danger-soft: rgba(255, 115, 105, 0.13);
    --ok: #4dab9a;
    --ok-soft: rgba(77, 171, 154, 0.13);
    --warn: #e0913f;
    --warn-soft: rgba(224, 145, 63, 0.13);
    --critical: #ff7369;

    --slice-1: #4a9eff;
    --slice-2: #4dab9a;
    --slice-3: #e0913f;
    --slice-4: #b18ad0;
    --slice-5: #ff7369;
    --slice-6: #93a5b1;

    --paper: #f7f7f5;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 6px 20px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.is-locked { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); }

/* ---------- Shell ---------- */

.app { display: flex; height: 100%; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--rail);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar__head { padding: 14px 14px 8px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.brand__mark { color: var(--text); flex: none; }

.nav { flex: 1; overflow-y: auto; padding: 4px 8px 20px; }

.nav__link,
.nav__scenario {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: 4px;
  color: var(--muted); font-size: 14px;
}
.nav__link--sub { padding-left: 16px; }
.nav__link:hover, .nav__scenario:hover { background: var(--hover); color: var(--text); }
.nav__link.is-active, .nav__scenario.is-active { background: var(--active); color: var(--text); font-weight: 500; }

.nav__section {
  padding: 14px 8px 4px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--faint);
}

.nav__scenario-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar__foot { padding: 12px 14px 16px; border-top: 1px solid var(--line); }
.sidebar__foot .muted { font-size: 11px; line-height: 1.5; }

.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line);
  min-height: 48px;
}

.topbar__drawer { display: none; }
.topbar__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.crumb { display: flex; align-items: center; gap: 6px; font-size: 14px; min-width: 0; }
.crumb__link { color: var(--muted); }
.crumb__link:hover { color: var(--text); }
.crumb__sep { color: var(--faint); }
.crumb__here { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status { font-size: 13px; color: var(--muted); }
.status.is-error { color: var(--danger); }

.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }

.tab {
  padding: 9px 12px; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--text); font-weight: 500; }
.tabs:empty { display: none; }

.main { flex: 1; overflow-y: auto; padding: 20px; max-width: 1400px; width: 100%; }

/* ---------- Blocks ---------- */

.panel { margin-bottom: 22px; }
.panel--side { background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.panel--error { border: 1px solid var(--danger); border-radius: 8px; padding: 16px; }
.panel--error h2 { margin-bottom: 6px; }
.panel--error p { margin-bottom: 12px; color: var(--muted); }

.panel__head { margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.panel__title { font-size: 15px; }
.panel__head .muted { flex-basis: 100%; }

.page-title { font-size: 22px; margin-bottom: 2px; }
.section-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 16px 0 8px; }

.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; align-items: start; margin-top: 20px; }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty__hint { margin-top: 6px; font-size: 13px; color: var(--faint); max-width: 46ch; margin-inline: auto; }
.loading { padding: 24px 0; color: var(--faint); font-size: 13px; }

/* ---------- Controls ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--page); color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); }
.btn--quiet { border-color: transparent; background: transparent; color: var(--muted); padding: 3px 7px; }
.btn--quiet:hover { background: var(--hover); color: var(--text); }
.btn--danger { color: var(--danger); }
.btn--danger.btn--primary { background: var(--danger); border-color: var(--danger); color: #fff; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius);
  border: none; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.chip {
  padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--page); color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--hover); color: var(--text); }
.chip.is-on { background: var(--text); border-color: var(--text); color: var(--page); }
.chip--static { cursor: default; }
.chip--static:hover { background: var(--page); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.field { display: block; margin-bottom: 12px; }
.field__label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field__help { display: block; font-size: 11px; color: var(--faint); margin-top: 4px; line-height: 1.45; }

.input {
  width: 100%; padding: 5px 8px; border-radius: var(--radius);
  border: 1px solid transparent; background: var(--hover);
  color: var(--text); font: inherit; font-size: 14px;
}
.input:focus { background: var(--page); border-color: var(--line); box-shadow: var(--focus); outline: none; }
.input--number { font-variant-numeric: tabular-nums; text-align: right; }
.input--slim { padding: 3px 6px; font-size: 13px; }
.input:disabled { opacity: 0.55; }

.input-group { display: flex; align-items: center; gap: 6px; }
.input-group__unit { font-size: 12px; color: var(--faint); min-width: 34px; }

.checkbox { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; }

.counter { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.counter__label { font-size: 13px; color: var(--muted); }
.counter .input { width: 72px; }
.crew { display: grid; gap: 2px; }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: var(--hover); color: var(--muted);
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.tag--primary { background: var(--accent-soft); color: var(--accent-ink); }
.tag--structural { background: var(--warn-soft); color: var(--warn); }
.tag--manual { background: var(--danger-soft); color: var(--danger); }
.tag--critical { background: var(--danger-soft); color: var(--danger); }

/* ---------- Stats ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  margin-bottom: 18px; }
.stats--tight { margin-bottom: 12px; }

.stat { background: var(--page); padding: 14px 16px; display: flex; flex-direction: column; gap: 3px; }
.stat__label { font-size: 12px; color: var(--muted); }
.stat__value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat__hint { font-size: 12px; color: var(--faint); }
.stat--save .stat__value { color: var(--ok); }
.stat--over .stat__value { color: var(--danger); }

.notice {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-radius: var(--radius); font-size: 13px; margin-bottom: 16px;
}
.notice--warn { background: var(--warn-soft); color: var(--warn); }

.warnings {
  margin: 0 0 18px; padding: 10px 14px 10px 28px; list-style: disc;
  background: var(--warn-soft); border-radius: var(--radius);
  color: var(--warn); font-size: 13px; line-height: 1.6;
}

/* ---------- Cards ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.cards--tight { gap: 10px; }

.card {
  display: block; padding: 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--page);
}
a.card:hover { background: var(--hover); }

.card__head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.card__title { font-size: 15px; font-weight: 600; }
.card__sub { font-size: 12px; color: var(--muted); }
.card__figure { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 8px 0 6px; }
.card__bar { height: 4px; border-radius: 2px; background: var(--hover); overflow: hidden; margin-bottom: 8px; }
.card__barfill { display: block; height: 100%; background: var(--accent); }
.card__facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 10px 0 0; }
.card__fact dt { font-size: 11px; color: var(--faint); }
.card__fact dd { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.card__foot { margin-top: 10px; font-size: 12px; color: var(--faint); }
.card__actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }

/* ---------- Lists and facts ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list__row {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.list--tight .list__row { padding: 5px 0; }
.list__title { display: block; font-size: 14px; }
.list__sub { display: block; font-size: 12px; color: var(--muted); }
.list__actions { display: flex; gap: 4px; }

.facts { margin: 10px 0; display: grid; gap: 4px; }
.facts__row { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; }
.facts__row dt { color: var(--muted); }
.facts__row dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.details > summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 8px 0; }
.details > summary:hover { color: var(--text); }

/* ---------- Tables ---------- */

.table, .tree-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.table th, .tree-table th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--faint);
  padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td, .tree-table td {
  padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top;
}
.is-right { text-align: right; }
td.is-right { font-variant-numeric: tabular-nums; }

.table tbody tr:hover, .tree-table tbody tr:hover { background: var(--hover); }
.table tbody tr.is-clickable { cursor: pointer; }

.tree-table__lead { display: inline-flex; align-items: baseline; gap: 5px; }
.tree-table__twist { display: inline-flex; color: var(--faint); transition: transform 0.12s; }
.tree-table__row.is-openable { cursor: pointer; }
.tree-table__row.is-open > td .tree-table__twist { transform: rotate(90deg); }

.tree-table__row.is-category > td { font-weight: 600; background: var(--sunken); }
.tree-table__row.is-recipe > td,
.tree-table__row.is-note > td { color: var(--muted); font-size: 12.5px; }
.tree-table__row.is-overridden > td:first-child { box-shadow: inset 2px 0 0 var(--danger); }
.tree-table__row.is-critical > td:first-child,
.table tr.is-critical > td:first-child { box-shadow: inset 2px 0 0 var(--critical); }

.rab__code { font-family: var(--mono); font-size: 11.5px; color: var(--faint); margin-right: 7px; }
.rab__name { }
.rab__waste { margin-left: 7px; font-size: 11px; color: var(--faint); }
.rab__origin { font-style: italic; }
.rab__dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; margin-right: 7px;
  background: var(--slice-1); vertical-align: middle; }
.rab__dot[data-kind="labor"] { background: var(--slice-3); }

.delta[data-tone="save"] { color: var(--ok); }
.delta[data-tone="cost"] { color: var(--danger); }

.limit { padding: 1px 6px; border-radius: 3px; background: var(--hover); font-size: 12px; }
.limit[data-tone="save"] { background: var(--ok-soft); color: var(--ok); }

/* ---------- Totals ---------- */

.panel--totals { max-width: 460px; margin-left: auto; }
.totals__row { display: flex; justify-content: space-between; gap: 20px; padding: 5px 0; font-size: 14px; }
.totals__row.is-sub { border-top: 1px solid var(--line); font-weight: 500; }
.totals__row.is-grand { border-top: 2px solid var(--text); font-size: 17px; font-weight: 600; padding-top: 8px; }
.totals__label { color: var(--muted); }
.totals__row.is-grand .totals__label { color: var(--text); }
.totals__value { font-variant-numeric: tabular-nums; }
.totals__note { margin-top: 10px; text-align: right; }

/* ---------- The figure: a number you can ask about ---------- */

.figure {
  border: none; background: none; padding: 0; font: inherit; color: inherit;
  font-variant-numeric: tabular-nums; cursor: pointer;
  border-bottom: 1px dotted var(--faint);
}
.figure:hover { color: var(--accent); border-bottom-color: var(--accent); }
.figure.is-strong { font-weight: 600; }

/* ---------- Trace panel ---------- */

.trace__top { margin-bottom: 16px; }
.trace__topvalue { display: block; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trace__toplabel { font-size: 13px; color: var(--muted); }

.trace__node { border-left: 1px solid var(--line); padding-left: 10px; margin-left: 3px; }
.trace__node.is-manual { border-left-color: var(--danger); }

.trace__head { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; border-radius: 4px; }
.trace__head.is-clickable { cursor: pointer; }
.trace__head.is-clickable:hover { background: var(--hover); }
.trace__head > svg { flex: none; color: var(--faint); transition: transform 0.12s; align-self: center; }
.trace__node.is-closed > .trace__head > svg { transform: rotate(-90deg); }

.trace__bullet { width: 5px; height: 5px; border-radius: 50%; background: var(--faint); flex: none; align-self: center; }
.trace__label { flex: 1; font-size: 13.5px; }
.trace__value { font-variant-numeric: tabular-nums; font-size: 13.5px; font-weight: 500; }

.trace__detail { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 0 5px 11px; }
.trace__expr { font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: var(--hover);
  padding: 1px 5px; border-radius: 3px; }
.trace__op { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
.trace__op[data-op="price"] { color: var(--slice-2); }
.trace__op[data-op="coefficient"] { color: var(--slice-3); }
.trace__op[data-op="manual"] { color: var(--danger); }
.trace__op[data-op="driver"] { color: var(--slice-1); }
.trace__ref { font-size: 11px; color: var(--faint); }
.trace__more { font-size: 11px; color: var(--faint); padding-left: 11px; }
.trace__kids { margin-left: 4px; }
.trace__foot { margin-top: 14px; }

/* ---------- Overlay: drawer and dialog ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 15, 15, 0.32);
  display: flex; justify-content: flex-end;
}

.drawer {
  width: min(460px, 100%); background: var(--page); box-shadow: var(--shadow);
  display: flex; flex-direction: column; height: 100%;
}
.drawer--wide { width: min(720px, 100%); }
.drawer__head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer__title { font-size: 15px; flex: 1; }
.drawer__body { flex: 1; overflow-y: auto; padding: 16px; }

.dialog {
  margin: auto; width: min(440px, calc(100% - 32px)); max-height: 88vh; overflow-y: auto;
  background: var(--page); border-radius: 10px; box-shadow: var(--shadow); padding: 20px;
}
.dialog__title { font-size: 16px; margin-bottom: 8px; }
.dialog__body { font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.dialog__fields { margin-bottom: 16px; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---------- Configurator ---------- */

.components { display: grid; gap: 18px; }
.component__head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; }
.component__name { font-size: 14px; }
.component__note { font-size: 12px; color: var(--faint); }

.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 7px; }

.option {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--page); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.option:hover { background: var(--hover); }
.option.is-chosen { border-color: var(--accent); background: var(--accent-soft); }
.option__name { flex: 1; font-size: 13.5px; min-width: 0; }
.option__tier { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
.option__tier[data-tier="premium"] { color: var(--slice-4); }
.option__tier[data-tier="budget"] { color: var(--slice-2); }
.option__check { color: var(--accent); display: inline-flex; }
.option__impact { flex-basis: 100%; font-size: 11.5px; color: var(--faint); min-height: 15px; }
.option__impact[data-tone="save"] { color: var(--ok); }
.option__impact[data-tone="cost"] { color: var(--danger); }

.params__section { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 10px; }
.params__section > summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.03em; padding: 6px 0; }
.params__group { padding-top: 6px; }

/* ---------- Charts ---------- */

.bars { display: grid; gap: 5px; }
.bars__row { display: grid; grid-template-columns: 150px minmax(60px, 1fr) 96px 42px; gap: 10px; align-items: center;
  font-size: 13px; }
.bars__row.is-clickable { cursor: pointer; }
.bars__row.is-clickable:hover .bars__label { color: var(--accent); }
.bars__label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars__track { height: 8px; background: var(--hover); border-radius: 4px; overflow: hidden; }
.bars__fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bars__fill[data-tone="over"] { background: var(--danger); }
.bars__value { text-align: right; font-variant-numeric: tabular-nums; }
.bars__share { text-align: right; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

.donut { display: inline-grid; justify-items: center; }
.donut__value { font-size: 15px; font-weight: 600; fill: var(--text); }
.donut__label { font-size: 10px; fill: var(--faint); }
.donut__legend { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 5px; width: 100%; }
.donut__legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.donut__swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.donut__name { flex: 1; color: var(--muted); }
.donut__figure { font-variant-numeric: tabular-nums; }

.histogram__scroll { overflow-x: auto; }
.histogram__legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.histogram__key { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Gantt ---------- */

/* The two halves are laid out from the same constants as the SVG (gantt.js):
   the head spacer is HEAD_HEIGHT, a group row GROUP_HEIGHT, a task row
   ROW_HEIGHT. Every one of those is set inline from there, so a row name and
   its bar cannot drift apart. Nothing here may add padding of its own. */

.gantt { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.gantt__labels { flex: none; border-right: 1px solid var(--line); background: var(--sunken); }
.gantt__head { border-bottom: 1px solid var(--line); }
.gantt__group { display: flex; align-items: center; padding: 0 10px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em; color: var(--faint);
  background: var(--hover); border-bottom: 1px solid var(--line); }
.gantt__task { display: flex; align-items: center; gap: 6px; padding: 0 10px; font-size: 12.5px;
  overflow: hidden; }
.gantt__task.is-odd { background: var(--stripe); }
.gantt__task.is-clickable { cursor: pointer; }
.gantt__task.is-hover { background: var(--hover); }
.gantt__task.is-critical .gantt__name { color: var(--critical); }
.gantt__code { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: none; }
.gantt__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt__scroll { flex: 1; overflow-x: auto; }
.gantt__row { pointer-events: all; cursor: default; }
.gantt__bar { cursor: pointer; }
.gantt__bar:hover rect { opacity: 1; }
.gantt__bar:focus-visible rect { stroke: var(--text); stroke-width: 1.5; outline: none; }

.phases { display: grid; gap: 7px; }
.phases__row { display: grid; grid-template-columns: 140px minmax(0, 1fr) 150px; gap: 12px; align-items: center;
  font-size: 13px; }
.phases__label { color: var(--muted); }
.phases__track { position: relative; height: 12px; background: var(--hover); border-radius: 6px; }
.phases__fill { position: absolute; top: 0; bottom: 0; background: var(--accent); border-radius: 6px; }
.phases__dates { font-size: 12px; color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Compare ---------- */

.compare-grid { display: grid; grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr)); gap: 16px; }
.compare-col { border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.compare-col__name { font-size: 14px; margin-bottom: 6px; }
.compare-col__total { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.compare-col__delta { font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.compare-col__delta[data-tone="save"] { color: var(--ok); }
.compare-col__delta[data-tone="cost"] { color: var(--danger); }

.headline { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start;
  margin-bottom: 16px; }
.headline__change { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 14px;
  padding: 4px 0; border-bottom: 1px solid var(--line); }
.headline__component { font-weight: 600; min-width: 120px; }
.headline__from { color: var(--muted); text-decoration: line-through; }
.headline__arrow { color: var(--faint); }
.headline__figures { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; }

/* ---------- Optimize ---------- */

.optimize-bar { display: flex; align-items: flex-end; gap: 12px; }
.optimize-bar .field { margin-bottom: 0; width: 230px; }
.optimize__component { font-weight: 600; margin-right: 8px; }
.optimize__from { color: var(--muted); text-decoration: line-through; margin-right: 6px; }
.optimize__to { margin-left: 6px; }
.optimize__foot { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between;
  margin-top: 14px; flex-wrap: wrap; }
.optimize__foot .muted { flex: 1; min-width: 320px; max-width: 68ch; }

/* ---------- Materials ---------- */

.material-group { margin-bottom: 20px; }

/* ---------- Plan editor ---------- */

.plan__tools { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 12px; }
.plan__toolgroup { display: flex; align-items: center; gap: 6px; }
.plan__toolgroup .input { width: auto; }

.plan__layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.plan__host { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--sunken); }
.plan__canvas { height: 560px; }
.plan__canvas[data-tool="wall"], .plan__canvas[data-tool="room"] { cursor: crosshair; }
.plan__canvas[data-tool="door"], .plan__canvas[data-tool="window"],
.plan__canvas[data-tool="fixture"] { cursor: copy; }

.plan__svg { width: 100%; height: 100%; display: block; touch-action: none; color: var(--text); }
.plan__grid { color: var(--text); }

.plan__wall { fill: var(--text); fill-opacity: 0.82; stroke: var(--text); stroke-width: 0.012; }
.plan__wall.is-exterior { fill-opacity: 1; }
.plan__wall.is-selected { fill: var(--accent); stroke: var(--accent); }
.plan__opening-gap { fill: var(--sunken); }
.plan__opening-line { stroke: var(--text); }
.plan__opening--door .plan__opening-line { stroke: var(--accent); }
.plan__tag { fill: var(--muted); }
.plan__measure { fill: var(--accent); font-weight: 600; }
.plan__handle { fill: var(--page); stroke: var(--accent); stroke-width: 0.03; }

.plan__room-fill { fill: var(--text); fill-opacity: 0.035; stroke: none; }
.plan__room-fill--km_mandi { fill: var(--slice-1); fill-opacity: 0.1; }
.plan__room.is-selected .plan__room-fill { fill: var(--accent); fill-opacity: 0.14; }
.plan__room-name { fill: var(--text); font-weight: 600; }
.plan__room-area { fill: var(--muted); }

.plan__fixture circle { fill: var(--slice-3); }
.plan__fixture--sanitair circle { fill: var(--slice-1); }
.plan__fixture--panel circle { fill: var(--slice-5); }
.plan__fixture.is-selected circle { fill: var(--accent); stroke: var(--text); stroke-width: 0.03; }
.plan__fixture-label { fill: var(--faint); }

.plan__draft { stroke: var(--accent); stroke-width: 0.06; stroke-dasharray: 0.2 0.12; fill: none; }
.plan__status { font-size: 12px; color: var(--muted); align-self: center; }

/* ---------- 3D View ---------- */

.model3d { min-height: calc(100vh - 130px); }
.model3d__head { align-items: center; }
.model3d__badges { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.model3d__toolbar { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 12px; }
.model3d__layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: start; }
.model3d__stage {
  position: relative; min-height: 560px; height: min(72vh, 760px);
  overflow: hidden; background: var(--sunken); border-radius: 8px;
}
.model3d__canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.model3d__side { display: grid; gap: 12px; align-content: start; }
.model3d__side > .panel { margin-bottom: 0; }
.model3d__facts { margin-bottom: 0; }

.model3d__note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.model3d__note--warn { color: var(--warn); }

/* Layer panel. A row is a checkbox and, on hover, a way to leave only it. */

.layers__presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.layers__group + .layers__group { margin-top: 12px; }
.layers__heading {
  margin: 0 0 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--faint);
}
.layers__row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 4px; border-radius: 5px; color: var(--muted);
}
.layers__row:hover { background: var(--hover); }
.layers__row.is-on { color: var(--text); }
.layers__label {
  display: flex; align-items: center; gap: 8px;
  flex: 1; min-width: 0; font-size: 13px; cursor: pointer;
}
.layers__label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layers__box { accent-color: var(--accent); cursor: pointer; }
.layers__solo {
  flex: none; border: 0; background: none; padding: 2px 4px;
  font: inherit; font-size: 11px; color: var(--faint);
  cursor: pointer; border-radius: 4px; opacity: 0;
}
.layers__row:hover .layers__solo, .layers__solo:focus-visible { opacity: 1; }
.layers__solo:hover { color: var(--accent); background: var(--accent-soft); }

/* Touch has no hover, so the solo button is always there. */
@media (hover: none) {
  .layers__solo { opacity: 1; }
}

/* ---------- Drawings ---------- */

.drawing__frame {
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  padding: 18px; display: flex; justify-content: center;
}

/* A drawing is squarish, so filling the width makes it taller than the screen
   and pushes its own title block below the fold. Fit the height instead and let
   the width follow. */
.drawing__sheet { max-width: 100%; display: flex; }

/* A definite height, not a max: the SVG carries a viewBox and no intrinsic
   size, so `width: auto` against an auto height resolves to nothing at all. */
.drawing__sheet svg { height: min(72vh, 820px); width: auto; max-width: 100%; color: #37352f; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  padding: 8px 14px; border-radius: var(--radius);
  background: #2f2e2b; color: rgba(255, 255, 255, 0.92); font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity 0.16s, transform 0.16s; z-index: 80;
}
.toast.is-up { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="error"] { background: var(--danger); color: #fff; }

.print-head { display: none; }

/* ---------- Narrower ---------- */

@media (max-width: 1100px) {
  .layout-2, .split, .plan__layout, .model3d__layout { grid-template-columns: minmax(0, 1fr); }
  .headline { grid-template-columns: minmax(0, 1fr); }
  .panel--totals { max-width: none; }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.18s;
  }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow); }
  .topbar__drawer { display: inline-flex; }
  .main { padding: 14px; }
  .compare-grid { grid-template-columns: minmax(0, 1fr); }
  .bars__row { grid-template-columns: 110px minmax(40px, 1fr) 84px; }
  .bars__share { display: none; }
  .plan__canvas { height: 420px; }
  .model3d { min-height: 0; }
  .model3d__stage { min-height: 420px; height: 62vh; margin-inline: -14px; border-radius: 0; }
  .model3d__badges { margin-left: 0; }
}
