/*
  Shared primitives and shells for every layer (design/PHILOSOPHY.md). Reads semantic tokens only:
  no colour literal in this file. Layout uses logical properties, so RTL is `dir="rtl"` alone.
*/

/* ---- base -------------------------------------------------------------------------------- */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  font: var(--text-md)/var(--lh-body) var(--font);
  color: var(--text);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent-text);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: var(--lh-head);
}

/* Arabic letters join: tracking (letter-spacing) breaks the joins, so Arabic is never tracked */
:root[dir="rtl"] :is(h1, h2, h3, .value, .navlabel, .eyebrow, b, strong) {
  letter-spacing: 0;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.num {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* left-to-right content inside Arabic (emails, VINs, codes) */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

:root[dir="rtl"] .ltr {
  text-align: right;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

/* ---- icons ------------------------------------------------------------------------------- */
.i {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-sm {
  width: 15px;
  height: 15px;
}

:root[dir="rtl"] .flip {
  transform: scaleX(-1);
}

.back {
  transform: scaleX(-1);
}

:root[dir="rtl"] .back {
  transform: none;
}

/* headings that receive focus after a page swap (for screen readers) don't draw a ring */
[tabindex="-1"]:focus {
  outline: none;
}

/* ---- buttons ----------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
}

.btn:hover {
  background: var(--surface-2);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: var(--bad-ink);
}

.btn.quiet {
  border-color: transparent;
  background: none;
}

.btn.quiet:hover {
  background: var(--surface-2);
}

.btn.lg {
  height: var(--control-h-lg);
  padding: 0 var(--space-5);
  font-size: var(--text-lg);
}

.btn.block {
  width: 100%;
}

.btn[aria-busy="true"] {
  opacity: .7;
  pointer-events: none;
}

.btn:disabled,
.iconbtn:disabled,
.btn[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
  filter: none;
}

.btn[aria-disabled="true"] {
  pointer-events: none;
}

.iconbtn {
  width: var(--control-h);
  height: var(--control-h);
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  color: var(--text-2);
  flex: none;
}

.iconbtn.quiet {
  border-color: transparent;
  background: none;
}

.iconbtn:hover {
  background: var(--surface-2);
}

/* ---- forms ------------------------------------------------------------------------------- */
.field {
  display: grid;
  gap: 6px;
  align-content: start;
}

.field>label,
.label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-2);
}

.field .label-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.field .label-row a {
  margin-inline-start: auto;
  font-size: var(--text-sm);
}

.input,
.select {
  height: var(--control-h);
  width: 100%;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel);
}

.input.lg {
  height: var(--control-h-lg);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input[aria-invalid="true"] {
  border-color: var(--bad);
}

.input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px var(--bad-soft);
}

.input.num {
  text-align: end;
}

.help {
  font-size: var(--text-xs);
  color: var(--muted);
}

.err {
  font-size: var(--text-xs);
  color: var(--bad);
  display: flex;
  gap: 4px;
  align-items: center;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
}

/* an on/off setting (W16): a checkbox drawn as a switch, so it posts "on" with no script */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.switch input {
  appearance: none;
  position: relative;
  flex: none;
  width: 32px;
  height: 18px;
  margin: 0;
  border-radius: var(--radius-full);
  background: var(--border-2);
  cursor: pointer;
  transition: background .15s;
}

.switch input::before {
  content: "";
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-ink);
  box-shadow: var(--shadow-sm);
  transition: translate .15s;
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::before {
  translate: 14px;
}

[dir="rtl"] .switch input:checked::before {
  translate: -14px;
}

.switch input:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.stack {
  display: grid;
  gap: var(--space-4);
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* The offer form: a per-vehicle rate is a plan's alone, so its field hides while Add-on is
   picked. */
form:has([name="kind"][value="addon"]:checked) .for-plans {
  display: none;
}


/* ---- alerts ------------------------------------------------------------------------------ */
.alert {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-sm);
}

.alert .i {
  margin-top: 1px;
}

.alert b {
  color: var(--text);
}

.alert.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.alert.bad b {
  color: var(--bad);
}

.alert.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.alert.warn b {
  color: var(--warn);
}

.alert.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.alert .actions {
  margin-inline-start: auto;
  display: flex;
  gap: var(--space-2);
  flex: none;
}

/* ---- chips, avatars, meters -------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}

.chip.accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.chip.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 600;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}

.meter {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  display: flex;
  gap: 2px;
  overflow: hidden;
}

.meter i {
  display: block;
  background: var(--accent);
}

.meter i+i {
  opacity: .55;
}

.meter.thin {
  height: 4px;
}

.meter.over i {
  background: var(--bad);
}

/* ---- surfaces: cards, panels, tables ------------------------------------------------------ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
}

/* an amount keeps its currency beside it (D-057): "USD" never wraps away from "50,000.00" */
.stats .ltr {
  white-space: nowrap;
}

.stat .label {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 500;
}

.stat .value {
  font-size: var(--text-2xl);
  font-weight: 600;
  margin-top: 6px;
  letter-spacing: -.01em;
}

.stat .value small {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 500;
}

.stat .meter {
  margin-top: var(--space-3);
}

.stat .sub {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-top: var(--space-2);
}

/* given out against what you hold (W51): a native bar, so its width needs no inline style */
progress.given {
  appearance: none;
  display: block;
  width: 100%;
  height: 6px;
  margin-top: var(--space-3);
  border: 0;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  overflow: hidden;
}

progress.given::-webkit-progress-bar {
  background: var(--surface-2);
}

progress.given::-webkit-progress-value {
  background: var(--accent);
}

progress.given::-moz-progress-bar {
  background: var(--accent);
}

/* the bar's two ends, named: given out at the start, left for you at the end */
.given-legend {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: 6px;
  font-size: var(--text-xs);
  color: var(--muted);
}

.stat .dl,
.stat .chips {
  margin-top: var(--space-3);
}

.stat .dl {
  font-size: var(--text-sm);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-wrap: wrap;
}

.panel-head h2 {
  font-size: var(--text-lg);
}

.panel-head .end {
  margin-inline-start: auto;
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

/* a list's search box, in its head beside its filters and its button */
.panel-head .input[type="search"] {
  flex: 1;
  max-width: 320px;
}

.panel-head .select {
  width: auto;
}

.panel-body {
  padding: var(--space-4);
}

.panel-foot {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.panel-foot .end {
  margin-inline-start: auto;
  display: flex;
  gap: var(--space-2);
}

/* A table that turns into labelled stacked rows on phones: every cell carries data-label. */
.tbl {
  width: 100%;
  border-collapse: collapse;
}

.tbl th {
  font-size: var(--text-xs);
  color: var(--muted);
  font-weight: 500;
  text-align: start;
  padding: 10px var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tbl td {
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tbl tr:last-child td {
  border-bottom: 0;
}

.tbl tbody tr:hover {
  background: var(--surface);
}

.tbl .n {
  text-align: end;
}

/* an amount in Arabic: `.ltr` aligns it right, away from its column's end (the left) */
:root[dir="rtl"] .tbl .n.ltr {
  text-align: left;
}

.tbl .act {
  width: 1%;
  white-space: nowrap;
  text-align: end;
}

/* a row's actions side by side: a link, then a form's button */
.tbl .act form {
  display: inline-block;
}

/* a table of fields (the power form): each field as wide as its figures, so a row stays on
   one line (W47), and what a field says under it, close by */
.tbl.fields-table .input {
  width: 100%;
  min-width: 5.5em;
  max-width: 9em;
}

.tbl.fields-table td {
  vertical-align: top;
}

.tbl.fields-table td small {
  margin-top: 4px;
}

/* its headings may wrap and its cells sit closer, so the owner's eight columns fit the panel */
.tbl.fields-table th {
  white-space: normal;
}

.tbl.fields-table :is(th, td) {
  padding-inline: var(--space-3);
}

/* a heading over several columns, then the headings under it */
.tbl th.group {
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.tbl small {
  display: block;
  color: var(--muted);
  font-size: var(--text-xs);
}

/* money coming in */
.tbl .gain {
  color: var(--ok);
}

/* an amount typed into a table cell */
.tbl .input.num {
  width: 130px;
}

/* fields side by side, as many as fit the width */
.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-4);
}

/* checks grouped under one legend, laid out like any field */
fieldset.field {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

/* a legend sits where a label would: no browser padding, the field's own gap below it */
fieldset.field>legend {
  padding: 0;
  margin-bottom: 6px;
}

/* a legend over fields with their own labels (the offer's limits) is a group title, not one
   more label: muted, with room under it, so "Limits" never reads as part of "Staff" */
fieldset.field:has(>.fields)>legend {
  margin-bottom: var(--space-3);
  color: var(--muted);
}

/* fields three to a row (the offer's six limits, never five and one alone); two on a tablet,
   one on a phone (below) */
.fields.thirds {
  grid-template-columns: repeat(3, 1fr);
}

/* a long form in titled parts: a heading (and a hint) over its fields, a line between parts */
.part {
  display: grid;
  gap: var(--space-4);
}

.part+.part {
  border-top: 1px solid var(--border);
  padding-top: var(--space-5);
}

.part-head {
  display: grid;
  gap: 4px;
}

.part-head h3 {
  font-size: var(--text-md);
}

/* a long form's buttons, kept in view at the bottom */
.savebar {
  position: sticky;
  bottom: var(--space-3);
  margin-top: var(--space-5);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  box-shadow: var(--shadow);
}

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.who .t {
  min-width: 0;
}

.who .name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who .meta {
  display: flex;
  gap: 6px;
  margin-top: 2px;
  flex-wrap: wrap;
}

/* a name and its chip on one line, centred together (the catalog: an offer and its kind) */
.name-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
}

.changes {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.changes li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-4);
  border-top: 1px solid var(--border);
}

.changes li:first-child {
  border-top: 0;
}

.changes .who {
  flex: 1;
}

.changes .delta {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  font-variant-numeric: tabular-nums;
  flex: none;
}

.changes .delta s {
  color: var(--muted);
}

.changes .same {
  color: var(--muted);
  font-size: var(--text-sm);
}

.dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-2) var(--space-6);
  margin: 0;
}

.dl dt {
  color: var(--muted);
}

.dl dd {
  margin: 0;
  font-weight: 500;
}

.empty {
  text-align: center;
  padding: var(--space-10) var(--space-4);
  color: var(--muted);
}

.empty .i {
  width: 40px;
  height: 40px;
  stroke-width: 1.4;
  margin-bottom: var(--space-3);
}

/* an empty state's own action, centred under its words */
.empty .actions {
  display: inline-flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.empty h3 {
  color: var(--text);
  font-size: var(--text-lg);
  margin-bottom: var(--space-1);
}

.empty p {
  margin: 0 auto var(--space-4);
  max-width: 380px;
}

.tabs {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 10px;
}

.tabs :is(button, a) {
  border: 0;
  background: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
}

.tabs :is(button[aria-selected="true"], a[aria-current="page"]) {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* A form folded behind a button (<details class="fold">, its <summary> a .btn): the page shows
   the state first and the form when asked; the server opens it when the form comes back refused. */
.fold>summary {
  list-style: none;
}

.fold>summary::-webkit-details-marker {
  display: none;
}

.fold[open]>summary {
  margin-bottom: var(--space-4);
}

/* ---- menus (popover API) and dialogs (<dialog>): native focus and Escape handling ---------- */
.menu {
  margin: 0;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow);
  min-width: 180px;
  color: var(--text);
  inset: auto;
}

.menu :is(button, a) {
  display: flex;
  width: 100%;
  gap: var(--space-2);
  align-items: center;
  padding: 8px 10px;
  border: 0;
  background: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  text-align: start;
  color: inherit;
  text-decoration: none;
}

.menu :is(button, a):hover,
.menu :is(button, a):focus-visible {
  background: var(--surface-2);
}

.menu .danger {
  color: var(--bad);
}

.menu hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-1) 0;
}

dialog.dlg {
  border: 0;
  padding: 0;
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: hidden;
}

dialog.dlg[open]>form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
}

dialog.dlg .dlg-body {
  overflow-y: auto;
  min-height: 0;
}

dialog.dlg.wide {
  width: min(760px, calc(100vw - 32px));
}

dialog.dlg::backdrop {
  background: var(--scrim);
}

.dlg-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) 0;
}

.dlg-head h2 {
  font-size: var(--text-xl);
}

.dlg-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.dlg-head .iconbtn {
  margin-inline-start: auto;
}

.dlg-body {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
}

.dlg-foot {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: var(--text-lg);
  text-decoration: none;
  color: var(--text);
}

.wordmark .mark {
  width: 30px;
  height: 30px;
  font-size: var(--text-sm);
}

.wordmark .mark.co-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: var(--text-lg);
}

.powered {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: var(--text-xs);
  color: var(--muted);
}

.powered .mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  font-size: 9px;
  background: var(--surface-2);
  color: var(--text-2);
}

/* ---- overview pieces: KPI cards, activity, module tiles ------------------------------------ */
.kpi {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
}

.kpi:hover {
  border-color: var(--border-2);
}

.kpi .bubble {
  position: absolute;
  inset-inline-end: -18px;
  top: -18px;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--accent-text);
}

.kpi .bubble .i {
  width: 22px;
  height: 22px;
  transform: translate(-8px, 8px);
}

:root[dir="rtl"] .kpi .bubble .i {
  transform: translate(8px, 8px);
}

.kpi.ok .bubble {
  background: var(--ok-soft);
  color: var(--ok);
}

.kpi.warn .bubble {
  background: var(--warn-soft);
  color: var(--warn);
}

.kpi .label {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 500;
  padding-inline-end: 52px;
}

.kpi .value {
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: var(--lh-tight);
  margin-top: var(--space-2);
}

.kpi .sub {
  font-size: var(--text-sm);
  color: var(--muted);
}

.kpi .sub b {
  color: var(--text-2);
  font-weight: 500;
}

/* a long value, like an amount with its currency */
.kpi .value.long {
  font-size: var(--text-2xl);
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.feed li {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}

.feed li:first-child {
  border-top: 0;
}

.feed .ic {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--surface-2);
  color: var(--text-2);
}

.feed .ic .i {
  width: 16px;
  height: 16px;
}

.feed .t {
  min-width: 0;
  font-size: var(--text-sm);
}

.feed .t small {
  display: block;
  color: var(--muted);
  font-size: var(--text-xs);
  margin-top: 2px;
}

.feed li>form {
  margin-inline-start: auto;
  align-self: center;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
}

.tile {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
}

.tile:hover {
  border-color: var(--border-2);
}

.tile .ic {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.tile.off .ic {
  background: var(--surface-2);
  color: var(--muted);
}

.tile b {
  display: block;
}

.tile small {
  color: var(--muted);
  font-size: var(--text-xs);
}

.head-ic {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.page-head.with-ic {
  align-items: center;
}

.page-head.with-ic>div:first-child {
  display: flex;
  gap: var(--space-4);
  align-items: center;
}

/* ---- built-app pieces: status pipeline, timeline, gallery, money summary ------------------- */
.pipeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-2);
}

.pipeline a {
  display: grid;
  gap: 4px;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
}

.pipeline a[aria-current] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pipeline small {
  color: var(--muted);
  font-size: var(--text-xs);
}

.pipeline b {
  font-size: var(--text-xl);
}

.timeline {
  list-style: none;
  margin: 0;
  padding: var(--space-5) var(--space-4);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
}

.timeline li {
  position: relative;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--muted);
}

.timeline li::before {
  content: "";
  position: absolute;
  top: 13px;
  inset-inline-start: -50%;
  width: 100%;
  height: 2px;
  background: var(--border-2);
  z-index: 0;
}

.timeline li:first-child::before {
  display: none;
}

.timeline li.done::before,
.timeline li.now::before {
  background: var(--accent);
}

.timeline .dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 2px solid var(--border-2);
  position: relative;
  z-index: 1;
  color: var(--muted);
}

.timeline .dot .i {
  width: 14px;
  height: 14px;
}

.timeline li.done .dot {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.timeline li.now .dot {
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.timeline li b {
  color: var(--text);
  font-weight: 500;
  font-size: var(--text-sm);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-2);
}

.gallery .ph {
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--muted);
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}

.gallery .ph .i {
  width: 28px;
  height: 28px;
  stroke-width: 1.3;
}

.money {
  display: grid;
  gap: var(--space-2);
}

.money div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}

.money .total {
  border-top: 1px solid var(--border);
  padding-top: var(--space-2);
  font-weight: 600;
}

.vin {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: .02em;
}

.thumb {
  width: 56px;
  height: 42px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex: none;
  color: var(--muted);
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}

.locked {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  color: var(--muted);
  font-size: var(--text-xs);
}

/* ---- toasts, palette, notifications ------------------------------------------------------- */
.toasts {
  position: fixed;
  inset-block-end: var(--space-5);
  inset-inline-start: 50%;
  translate: -50% 0;
  z-index: 200;
  display: grid;
  gap: var(--space-2);
}

:root[dir="rtl"] .toasts {
  translate: 50% 0;
}

.toast {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: 10px var(--space-4);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  animation: toast-in .2s ease-out;
}

.toast .i {
  color: var(--ok);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.palette {
  width: min(560px, calc(100vw - 32px));
}

.palette .input {
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  height: 52px;
  font-size: var(--text-lg);
  padding: 0 var(--space-5);
}

.palette .input:focus {
  box-shadow: none;
}

.palette ul {
  list-style: none;
  margin: 0;
  padding: var(--space-2);
  max-height: 360px;
  overflow-y: auto;
}

.palette li a {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}

.palette li a:hover,
.palette li a:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.palette li small {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: var(--text-xs);
}

.notes-pop {
  width: 340px;
  padding: 0;
}

.notes-pop header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* ---- system pages (404, 403, plan ended, error, offline) ----------------------------------- */
.system {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.system .code {
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.04em;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 30%, transparent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.system h1 {
  font-size: var(--text-2xl);
  margin-top: var(--space-4);
}

.system p {
  color: var(--muted);
  max-width: 440px;
  margin: var(--space-2) auto var(--space-6);
}

.system .actions {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  flex-wrap: wrap;
}

.system .ring {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin: 0 auto;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.system .ring .i {
  width: 36px;
  height: 36px;
  stroke-width: 1.5;
}

.system .ring.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.system .ring.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

/* ---- the studio (staff only, desktop first) ----------------------------------------------- */
.studio {
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  height: 100dvh;
  background: var(--surface-2);
}

.studio-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.studio-bar .crumb {
  display: flex;
  gap: 6px;
  align-items: center;
  font-weight: 600;
}

.studio-bar .end {
  margin-inline-start: auto;
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.studio-body {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 300px;
  min-height: 0;
}

.studio-panel {
  background: var(--panel);
  overflow-y: auto;
  border-inline-end: 1px solid var(--border);
}

.studio-panel.right {
  border-inline-end: 0;
  border-inline-start: 1px solid var(--border);
}

.studio-panel h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: var(--space-4) var(--space-4) var(--space-2);
}

:root[dir="rtl"] .studio-panel h3 {
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--text-xs);
}

.outline {
  list-style: none;
  margin: 0;
  padding: 0 var(--space-2) var(--space-2);
}

.outline a {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: 6px var(--space-2);
  border-radius: var(--radius-xs);
  color: var(--text-2);
  text-decoration: none;
  font-size: var(--text-sm);
}

.outline a:hover {
  background: var(--surface-2);
}

.outline a[aria-current] {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.outline .i {
  width: 15px;
  height: 15px;
}

.outline ul {
  list-style: none;
  padding-inline-start: var(--space-5);
  margin: 0;
}

.canvas {
  overflow: auto;
  padding: var(--space-6);
  display: grid;
  justify-items: center;
  align-content: start;
  gap: var(--space-3);
  background-image: radial-gradient(var(--border-2) 1px, transparent 1px);
  background-size: 16px 16px;
}

.canvas-tools {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.frame {
  width: 100%;
  max-width: 980px;
  background: var(--bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.frame.phone {
  max-width: 390px;
}

.frame .frame-bar {
  height: 28px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 0 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

.frame .frame-bar i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-2);
}

.frame .frame-bar span {
  margin-inline-start: var(--space-2);
  font-family: var(--font-mono);
}

.block {
  position: relative;
  border-radius: var(--radius-sm);
  outline: 1px dashed transparent;
  outline-offset: 4px;
  cursor: pointer;
}

.block:hover {
  outline-color: var(--border-2);
}

.block.selected {
  outline: 2px solid var(--accent);
}

.block.selected::before {
  content: attr(data-block);
  position: absolute;
  top: -26px;
  inset-inline-start: -4px;
  font-size: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 2px 8px;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
}

.prop {
  display: grid;
  gap: 6px;
  padding: var(--space-2) var(--space-4);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg button {
  border: 0;
  background: var(--panel);
  padding: 5px 10px;
  font-size: var(--text-xs);
  cursor: pointer;
}

.seg button+button {
  border-inline-start: 1px solid var(--border-2);
}

.seg button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.swatches button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border-2);
  cursor: pointer;
}

.swatches button[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent);
}

.studio-note {
  margin: var(--space-3) var(--space-4);
}

/* ---- phones ------------------------------------------------------------------------------ */
@media (max-width: 820px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  /* secondary figures (ceilings, flags) become one compact line each */
  .stat.minor {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    flex-wrap: wrap;
  }

  .stat.minor .value {
    font-size: var(--text-lg);
    margin: 0 0 0 auto;
  }

  :root[dir="rtl"] .stat.minor .value {
    margin: 0 auto 0 0;
  }

  .stat.minor .sub {
    flex-basis: 100%;
    margin: 0;
  }

  .row2 {
    grid-template-columns: 1fr;
  }

  /* stacked table: header hidden, each cell labelled; nothing is dropped */
  .tbl.stackable thead {
    display: none;
  }

  .tbl.stackable,
  .tbl.stackable tbody,
  .tbl.stackable tr,
  .tbl.stackable td {
    display: block;
  }

  .tbl.stackable tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: var(--space-3);
    row-gap: 6px;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
  }

  .tbl.stackable tr:last-child {
    border-bottom: 0;
  }

  .tbl.stackable td {
    padding: 0;
    border: 0;
    text-align: start;
  }

  .tbl.stackable td.first {
    grid-column: 1 / -1;
  }

  /* the row's actions: its last line, at the end, never over the name */
  .tbl.stackable td.act {
    grid-column: 1 / -1;
    width: auto;
    text-align: end;
  }


  .tbl.stackable td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: var(--muted);
  }

  .tbl.stackable td.wide {
    grid-column: 1 / -1;
  }

  .tbl.stackable .input.num {
    width: 100%;
    max-width: none;
  }


  .timeline {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    gap: var(--space-3);
    justify-items: start;
  }

  .timeline li {
    grid-template-columns: 28px 1fr;
    justify-items: start;
    text-align: start;
    column-gap: var(--space-3);
    row-gap: 0;
  }

  .timeline li .dot {
    grid-row: span 2;
  }

  .timeline li::before {
    display: none;
  }

  .studio-body {
    grid-template-columns: 1fr;
  }

  .studio-panel {
    display: none;
  }

  .system .code {
    font-size: 72px;
  }

  .fields.thirds {
    grid-template-columns: repeat(2, 1fr);
  }

}

@media (max-width: 480px) {

  /* a card holding an amount takes the whole row, so the amount fits on its one line */
  .stats> :has(> .value.ltr) {
    grid-column: 1 / -1;
  }

  /* a row of related figures (the tree's): one per row, all the same width */
  .stats.narrow-stack {
    grid-template-columns: 1fr;
  }


  .tbl.stackable tr {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .fields.thirds {
    grid-template-columns: 1fr;
  }

}