/* ==========================================================================
   RingBack design system
   Direction: dark-glass-clean-layout (quiet-hierarchy half). See DESIGN.md.
   Rules this file obeys, in order:
     1. No hex literal in a component rule. Two documented exceptions at the
        bottom (mobile tab bar + More drawer are deliberately always-dark).
     2. Nothing renders below --t-xs. Prose never below --t-base.
     3. A surface gets a border OR a shadow, never both as decoration.
     4. Every transition ships its reduced-motion path in the same file.
   ========================================================================== */

@import url("tokens/fonts.css");
@import url("tokens/colors.css");
@import url("tokens/typography.css");
@import url("tokens/scale.css");
@import url("tokens/effects.css");

/* --------------------------------------------------------------------------
   1. Reset + base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Headings: tighter leading as size grows. Style with classes, never by picking
   a heading tag for its size — a skipped level breaks the document outline. */
h1, h2, h3, h4 { margin: 0 0 var(--s-3); line-height: var(--lh-tight); font-weight: 700; }
h1 { font-size: var(--t-2xl); letter-spacing: -0.02em; }
h2 { font-size: var(--t-xl); letter-spacing: -0.01em; }
h3 { font-size: var(--t-lg); }
h4 { font-size: var(--t-base); }

p { margin: 0 0 var(--s-4); max-width: 72ch; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

small, .rb-fine { font-size: var(--t-sm); color: var(--muted); }

code, kbd, samp { font-family: var(--font-mono); font-size: 0.94em; }

/* Numerals, money, phone numbers, IDs. Tabular so columns of figures line up. */
.rb-num { font-family: var(--font-mono-num); font-variant-numeric: tabular-nums; }

/* Short uppercase labels only. Never a sentence, never running text. */
.rb-label {
  font-size: var(--t-xs); font-weight: 700; line-height: var(--lh-snug);
  letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--muted);
}

hr, .rb-rule { border: 0; border-top: 1px solid var(--border-soft); margin: var(--s-6) 0; }

/* One focus treatment for everything interactive, in the site accent. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--focus-ring) solid var(--accent);
  outline-offset: var(--focus-offset);
  border-radius: var(--r-sm);
}

::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); color: var(--text); }

/* Keyboard users jump the rail. Hidden until focused. */
.rb-skip {
  position: absolute; left: var(--s-3); top: -100px; z-index: var(--z-toast);
  background: var(--surface); color: var(--text); border: 1px solid var(--accent);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md); font-weight: 600;
  text-decoration: none; transition: top var(--dur-2) var(--ease-out);
}
.rb-skip:focus { top: var(--s-3); }

/* --------------------------------------------------------------------------
   2. App shell — rail + topbar + content, >=1025px
   Below 1025px the rail collapses to the bottom-tab bar (house rule 3).
   -------------------------------------------------------------------------- */

.rb-app { flex: 1; display: flex; min-height: 0; width: 100%; }

/* --- Left rail --- */
.rb-rail {
  flex: 0 0 var(--rail-w); width: var(--rail-w);
  position: sticky; top: 0; align-self: flex-start;
  height: 100dvh; z-index: var(--z-rail);
  display: flex; flex-direction: column;
  background: var(--stage);
  border-right: 1px solid var(--border-soft);
  padding: var(--s-4) var(--s-3) var(--s-3);
  overflow-y: auto; overscroll-behavior: contain;
}

/* Standalone module documents own their own <body> and can't be wrapped in .rb-app
   without editing every module's _footer.html, so their rail is fixed and the body
   is padded to clear it. Same markup, same classes, same result on screen. */
.rb-rail-fixed { position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh; }
/* A module document has no .rb-shell to pad its content, so the body carries the
   page gutter itself. The rail is fixed and ignores this padding. */
body:has(> .rb-rail-fixed) { padding: var(--s-4); }
@media (min-width: 1025px) {
  body:has(> .rb-rail-fixed) { padding: var(--s-6); padding-left: calc(var(--rail-w) + var(--s-6)); }
}
/* Pages that ship their own full-width bar handle their own inset. */
body:has(> .rb-rail-fixed) > header:first-of-type { margin: calc(var(--s-4) * -1) calc(var(--s-4) * -1) var(--s-5); }
@media (min-width: 1025px) {
  body:has(> .rb-rail-fixed) > header:first-of-type { margin: calc(var(--s-6) * -1) calc(var(--s-6) * -1) var(--s-6); }
}

.rb-rail-brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-3) var(--s-5);
  color: var(--text); text-decoration: none;
  font-size: var(--t-lg); font-weight: 700; letter-spacing: -0.01em;
}
.rb-rail-brand img { width: 26px; height: 26px; border-radius: var(--r-sm); flex: none; }

/* Grouped nav. The group label is what makes 11 links legible as 3 ideas. */
.rb-rail-group { margin-bottom: var(--s-5); }
.rb-rail-group > .rb-label { padding: 0 var(--s-3); margin-bottom: var(--s-2); color: var(--faint); }

.rb-rail-link {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-3); margin-bottom: 2px;
  border-radius: var(--r-md);
  color: var(--text-2); text-decoration: none;
  font-size: var(--t-base); font-weight: 500; line-height: 1.4;
  transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.rb-rail-link:hover { background: var(--glass); color: var(--text); }
.rb-rail-link.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent); font-weight: 600;
}
.rb-rail-ico { width: 1.25rem; text-align: center; flex: none; font-size: 1rem; }

/* Count of things needing attention, right-aligned in the link. */
.rb-rail-count {
  margin-left: auto; font-family: var(--font-mono-num); font-size: var(--t-xs);
  font-weight: 700; padding: 1px var(--s-2); border-radius: var(--r-pill);
  background: var(--danger-bg); color: var(--danger);
}

.rb-rail-foot { margin-top: auto; padding-top: var(--s-4); border-top: 1px solid var(--border-soft); }

/* --- Content column --- */
.rb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Sticky topbar. --navbg carries the alpha the token layer always intended. */
.rb-topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-3) var(--s-6);
  background: var(--navbg);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.rb-topbar-title { font-size: var(--t-lg); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.rb-topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-3); }
/* The token badge mounts to <body> and lands inside the topbar via fixed
   positioning, so the actions row has to give up the space it occupies. */
body[data-badge] .rb-topbar-actions { padding-right: 132px; }

.rb-shell { flex: 1; width: 100%; max-width: var(--shell-max); margin: 0 auto; padding: var(--s-6); }

/* Wide pages (boards, tables) opt out of the reading-width cap. */
.rb-shell.rb-wide { max-width: none; }

/* --------------------------------------------------------------------------
   3. Page header — title, one-line context, primary action
   -------------------------------------------------------------------------- */

.rb-page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6);
}
.rb-page-head h1 { margin: 0; }
.rb-page-sub { margin: var(--s-2) 0 0; color: var(--muted); font-size: var(--t-base); max-width: 62ch; }
.rb-page-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* Section heading inside a page. More space above than below, always. */
.rb-section { margin-top: var(--s-8); }
.rb-section:first-child { margin-top: 0; }
.rb-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-3);
}
.rb-section-head h2 { margin: 0; font-size: var(--t-lg); }
.rb-section-head a { font-size: var(--t-sm); font-weight: 600; text-decoration: none; }
.rb-section-head a:hover { text-decoration: underline; }

/* Tabs — switching between sibling views of the same thing (Invoices / POs). */
.rb-tabs { display: flex; gap: var(--s-1); flex-wrap: wrap; }
.rb-tabs a {
  padding: var(--s-2) var(--s-3); border-radius: var(--r-md);
  color: var(--muted); text-decoration: none;
  font-size: var(--t-sm); font-weight: 600; line-height: 1.4;
  transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.rb-tabs a:hover { background: var(--glass); color: var(--text); }
.rb-tabs a.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   4. Cards
   Border OR shadow, never both as decoration. Default card is bordered and
   flat; only an interactive card lifts, and only on hover.
   -------------------------------------------------------------------------- */

.rb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-5);
}
.rb-card:last-child { margin-bottom: 0; }
.rb-card > :last-child { margin-bottom: 0; }

.rb-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-3);
}
.rb-card-head h2, .rb-card-head h3 { margin: 0; font-size: var(--t-lg); }
.rb-card-sub { color: var(--muted); font-size: var(--t-sm); margin: calc(var(--s-1) * -1) 0 var(--s-4); }

/* Linked card: the whole tile is the target, so it needs all eight states. */
a.rb-card, .rb-card-link {
  display: block; text-decoration: none; color: inherit;
  transition: border-color var(--dur-1) var(--ease-out),
              background var(--dur-1) var(--ease-out),
              transform var(--dur-1) var(--ease-out);
}
a.rb-card:hover, .rb-card-link:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--surface-2);
  transform: translateY(-1px);
}
a.rb-card:active, .rb-card-link:active { transform: translateY(0); }

.rb-card-accent { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.rb-card-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.rb-card-quiet { background: var(--glass); }

/* --------------------------------------------------------------------------
   5. Buttons — all eight states, four intents, three sizes
   -------------------------------------------------------------------------- */

/* Selector is `.rb-btn` alone, deliberately. Listing `button.rb-btn, a.rb-btn`
   here gives the base rule specificity (0,1,1) on a <button>/<a>, which beats
   `.rb-btn-ghost` at (0,1,0) — every variant silently rendered as primary. */
.rb-btn {
  --btn-bg: var(--accent-solid);
  --btn-fg: var(--on-accent);
  --btn-bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: var(--s-2) var(--s-4);
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  font-family: inherit; font-size: var(--t-sm); font-weight: 600; line-height: 1.2;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: filter var(--dur-1) var(--ease-out),
              background var(--dur-1) var(--ease-out),
              transform var(--dur-1) var(--ease-out);
}
.rb-btn:hover { filter: brightness(1.1); text-decoration: none; }
.rb-btn:active { transform: translateY(1px); filter: brightness(0.95); }
.rb-btn[disabled], .rb-btn[aria-disabled="true"] {
  opacity: 0.45; cursor: not-allowed; pointer-events: none;
}
.rb-btn[aria-busy="true"] { cursor: progress; opacity: 0.75; }

.rb-btn-secondary { --btn-bg: var(--surface-2); --btn-fg: var(--text); --btn-bd: var(--border); }
.rb-btn-secondary:hover { --btn-bg: var(--surface-3); filter: none; }

.rb-btn-ghost { --btn-bg: transparent; --btn-fg: var(--text-2); --btn-bd: transparent; }
.rb-btn-ghost:hover { --btn-bg: var(--glass); --btn-fg: var(--text); filter: none; }

.rb-btn-danger { --btn-bg: var(--danger-bg); --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 40%, transparent); }
.rb-btn-danger:hover { --btn-bg: color-mix(in srgb, var(--danger) 22%, transparent); filter: none; }

.rb-btn-sm { min-height: 32px; padding: var(--s-1) var(--s-3); font-size: var(--t-xs); }
/* 48px so it clears the 44px touch target with room for gloves. */
.rb-btn-lg { min-height: 48px; padding: var(--s-3) var(--s-6); font-size: var(--t-base); }

/* Bare <button> with no class still has to look deliberate rather than default-UA. */
button:not([class]) {
  min-height: 40px; padding: var(--s-2) var(--s-4);
  background: var(--accent-solid); color: var(--on-accent);
  border: none; border-radius: var(--r-md);
  font-family: inherit; font-size: var(--t-sm); font-weight: 600; cursor: pointer;
  transition: filter var(--dur-1) var(--ease-out);
}
button:not([class]):hover { filter: brightness(1.1); }

/* --------------------------------------------------------------------------
   6. Forms
   Visible labels always (a placeholder is not a label). Errors sit below the
   field and are wired with aria-describedby at the template level.
   -------------------------------------------------------------------------- */

.rb-field { display: block; margin-bottom: var(--s-4); }
.rb-field > span, .rb-field-label {
  display: block; margin-bottom: var(--s-2);
  font-size: var(--t-sm); font-weight: 600; color: var(--text-2);
}

.rb-field input, .rb-field select, .rb-field textarea,
.rb-input, input[type="text"], input[type="email"], input[type="tel"],
input[type="password"], input[type="number"], input[type="date"],
input[type="time"], input[type="search"], input[type="url"], select, textarea {
  width: 100%; min-height: 44px;
  padding: var(--s-2) var(--s-3);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-family: inherit; font-size: var(--t-base); line-height: 1.4;
  transition: border-color var(--dur-1) var(--ease-out), background var(--dur-1) var(--ease-out);
}
textarea { min-height: 96px; resize: vertical; }
select { cursor: pointer; }

:is(.rb-field input, .rb-field select, .rb-field textarea, .rb-input, input, select, textarea):hover:not(:disabled) {
  border-color: var(--border);
  background: var(--surface-3);
}
:is(input, select, textarea)::placeholder { color: var(--faint); opacity: 1; }
:is(input, select, textarea):disabled { opacity: 0.5; cursor: not-allowed; }

.rb-help { display: block; margin-top: var(--s-2); font-size: var(--t-sm); color: var(--muted); }
.rb-error { display: block; margin-top: var(--s-2); font-size: var(--t-sm); color: var(--danger); font-weight: 600; }
.rb-field-invalid input, .rb-field-invalid select, .rb-field-invalid textarea,
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

/* Checkbox / radio rows get a real hit area, not a 13px native box alone. */
.rb-check {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-2) 0; font-size: var(--t-base); cursor: pointer;
}
.rb-check input { width: 20px; height: 20px; min-height: 0; flex: none; margin-top: 2px; accent-color: var(--accent); }

/* A group heading inside a long form. More space above than below, always. */
.rb-subhead { font-size: var(--t-base); margin: var(--s-6) 0 var(--s-3); }
.rb-subhead:first-of-type { margin-top: var(--s-4); }

.rb-form-actions {
  display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap;
  margin-top: var(--s-5); padding-top: var(--s-4); border-top: 1px solid var(--border-soft);
}

/* A form card keeps a comfortable reading measure rather than stretching to the shell. */
.rb-form-card { max-width: 640px; }

/* Field pairs side by side on wide screens, stacked on narrow. */
.rb-field-row { display: grid; gap: 0 var(--s-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* --------------------------------------------------------------------------
   7. Tables — one border direction only, never both
   -------------------------------------------------------------------------- */

.rb-table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); }
.rb-table { width: 100%; border-collapse: collapse; font-size: var(--t-base); }
.rb-table th {
  text-align: left; padding: var(--s-3) var(--s-4);
  background: var(--surface-2); color: var(--muted);
  font-size: var(--t-xs); font-weight: 700;
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  white-space: nowrap;
}
.rb-table td { padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border-soft); vertical-align: middle; }
.rb-table tbody tr { transition: background var(--dur-1) var(--ease-out); }
.rb-table tbody tr:hover { background: var(--glass); }
.rb-table a { color: var(--text); text-decoration: none; font-weight: 600; }
.rb-table a:hover { color: var(--accent); }
.rb-table .rb-right, .rb-table th.rb-right { text-align: right; }

/* --------------------------------------------------------------------------
   8. Badges — >= --t-xs, readable tint, no glow
   -------------------------------------------------------------------------- */

.rb-badge {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 3px var(--s-2); border-radius: var(--r-pill);
  font-size: var(--t-xs); font-weight: 700; line-height: 1.4;
  letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap;
  background: var(--muted-bg); color: var(--text-2);
}
.rb-badge-success, .rb-badge.closed_booked, .rb-badge.paid, .rb-badge.completed { background: var(--success-bg); color: var(--success); }
.rb-badge-warning, .rb-badge.ai_paused, .rb-badge.pending { background: var(--warning-bg); color: var(--warning); }
.rb-badge-danger,  .rb-badge.flagged, .rb-badge.overdue, .rb-badge.void { background: var(--danger-bg); color: var(--danger); }
.rb-badge-info,    .rb-badge.open, .rb-badge.sent { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.rb-badge-neutral, .rb-badge.closed_no_reply, .rb-badge.draft { background: var(--muted-bg); color: var(--muted); }

/* --------------------------------------------------------------------------
   9. Empty states — a heading, one sentence, and the action that fixes it.
   "Nothing here" alone reads as broken.
   -------------------------------------------------------------------------- */

.rb-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--s-10) var(--s-6);
  border: 1px dashed var(--border); border-radius: var(--r-lg);
  background: var(--glass);
}
.rb-empty-ico { font-size: 1.75rem; line-height: 1; margin-bottom: var(--s-3); opacity: 0.65; }
.rb-empty h3 { margin: 0 0 var(--s-2); font-size: var(--t-lg); }
.rb-empty p { margin: 0 0 var(--s-4); color: var(--muted); font-size: var(--t-base); max-width: 46ch; }
.rb-empty > :last-child { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   10. Stat tiles + data marks
   -------------------------------------------------------------------------- */

.rb-stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-3); }

.rb-stat {
  background: var(--glass); border: 1px solid var(--border-soft);
  border-radius: var(--r-md); padding: var(--s-4);
}
.rb-stat-value {
  font-family: var(--font-mono-num); font-variant-numeric: tabular-nums;
  font-size: var(--t-3xl); font-weight: 600; line-height: 1.1; letter-spacing: -0.02em;
}
.rb-stat-value.tone-info { color: var(--info); }
.rb-stat-value.tone-success { color: var(--success); }
.rb-stat-value.tone-warning { color: var(--warning); }
.rb-stat-value.tone-danger { color: var(--danger); }
.rb-stat-value.tone-accent { color: var(--accent); }
/* A zero is real data, not an error — mute it instead of shouting it in colour. */
.rb-stat-value.is-zero { color: var(--faint); }
.rb-stat-label { margin-top: var(--s-2); font-size: var(--t-sm); color: var(--muted); }
.rb-stat-foot { margin-top: var(--s-2); font-size: var(--t-sm); color: var(--faint); }

/* Sparkline. Sized here; the SVG carries its own stroke. Hidden when the series
   is flat, because a flat line across a card reads as a divider or a glitch. */
.rb-sparkline { width: 100%; margin-top: var(--s-2); }
.rb-sparkline svg { display: block; width: 100%; height: 28px; overflow: visible; }

/* Progress: thin bar, faint track, real value beside the label. */
.rb-progress + .rb-progress { margin-top: var(--s-4); }
.rb-progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); margin-bottom: var(--s-2); }
.rb-progress-label { font-size: var(--t-sm); font-weight: 600; color: var(--text-2); }
.rb-progress-value { font-family: var(--font-mono-num); font-variant-numeric: tabular-nums; font-size: var(--t-sm); font-weight: 600; color: var(--muted); }
.rb-progress-track { height: 6px; border-radius: var(--r-pill); background: var(--muted-bg); overflow: hidden; }
.rb-progress-fill { height: 100%; border-radius: var(--r-pill); background: var(--accent); transition: width var(--dur-3) var(--ease-out); }
.rb-progress-fill.tone-success { background: var(--success); }
.rb-progress-fill.tone-warning { background: var(--warning); }
.rb-progress-fill.tone-danger { background: var(--danger); }
.rb-progress-fill.tone-info { background: var(--info); }

/* On a phone the three stat tiles stack one per row and push everything below
   the fold. Turning each into a single line (figure left, label right) keeps all
   three visible without shrinking the number, which is the part being read. */
@media (max-width: 560px) {
  .rb-stat { display: flex; align-items: baseline; gap: var(--s-3); padding: var(--s-3) var(--s-4); }
  .rb-stat-value { font-size: var(--t-2xl); }
  .rb-stat-label { margin-top: 0; margin-left: auto; text-align: right; }
  .rb-sparkline { display: none; }
  .rb-topbar-actions .rb-btn { min-height: 32px; padding: var(--s-1) var(--s-3); font-size: var(--t-xs); }
  body[data-badge] .rb-topbar-actions { padding-right: 120px; }
}

/* --------------------------------------------------------------------------
   11. List rows — the shape most RingBack pages actually need
   -------------------------------------------------------------------------- */

.rb-rows { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.rb-row {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border-soft);
  color: inherit; text-decoration: none;
  transition: background var(--dur-1) var(--ease-out);
}
.rb-row:first-child { border-top: 0; }
a.rb-row:hover { background: var(--surface-2); }
.rb-row-main { flex: 1; min-width: 0; }
/* These are <span>s in the templates so a whole row can be one <a>; they have to
   be blockified or the title and its metadata run together on one line. */
.rb-row-title { display: block; font-size: var(--t-lg); font-weight: 600; line-height: 1.3; }
.rb-row-meta { display: block; font-size: var(--t-sm); color: var(--muted); margin-top: 2px; }
.rb-row-side { flex: none; display: flex; align-items: center; gap: var(--s-3); }

/* --------------------------------------------------------------------------
   12. Messages (conversation thread)
   -------------------------------------------------------------------------- */

.rb-msg {
  padding: var(--s-3) var(--s-4); border-radius: var(--r-lg);
  margin: var(--s-2) 0; max-width: min(80%, 60ch);
  font-size: var(--t-base); line-height: 1.5;
}
.rb-msg.inbound { background: var(--surface-2); border: 1px solid var(--border-soft); border-bottom-left-radius: var(--r-sm); }
.rb-msg.outbound { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); margin-left: auto; border-bottom-right-radius: var(--r-sm); }
.rb-msg-meta { font-size: var(--t-sm); color: var(--muted); margin-top: var(--s-1); }

.rb-ai-toggle {
  border-radius: var(--r-pill); padding: var(--s-1) var(--s-3);
  font-size: var(--t-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  border: 1px solid transparent; cursor: pointer; min-height: 32px;
  transition: filter var(--dur-1) var(--ease-out);
}
.rb-ai-toggle.handling { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.rb-ai-toggle.paused { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }

/* Conversation thread: the message list plus the reply dock beneath it. */
.rb-thread {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s-4); margin-bottom: var(--s-5);
}
.rb-thread .rb-empty { border: 0; background: none; padding: var(--s-8) var(--s-4); }

.rb-reply-form { display: flex; align-items: flex-end; gap: var(--s-3); }
.rb-reply-field { flex: 1; margin-bottom: 0; }
.rb-reply-status { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-4); }
.rb-reply-status .rb-fine { flex: 1; min-width: 220px; }
@media (max-width: 560px) {
  .rb-reply-form { flex-direction: column; align-items: stretch; }
}

/* --------------------------------------------------------------------------
   13. Banners
   -------------------------------------------------------------------------- */

.rb-banner {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-3) var(--s-6);
  font-size: var(--t-sm); font-weight: 600;
  border-bottom: 1px solid transparent;
}
.rb-degraded, .rb-banner-warning {
  background: var(--warning-bg); color: var(--warning);
  border-bottom-color: color-mix(in srgb, var(--warning) 35%, transparent);
  justify-content: center; text-align: center;
}

/* --------------------------------------------------------------------------
   14. Layout utilities — the only three that earn a class
   -------------------------------------------------------------------------- */

.rb-stack   { display: flex; flex-direction: column; gap: var(--s-4); }
.rb-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.rb-grid    { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.rb-spread  { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   15. Brand credit footer (house rule 1)
   -------------------------------------------------------------------------- */

.rb-credit {
  text-align: center;
  font-size: var(--t-sm);
  padding: var(--s-4) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft);
}
/* --muted, not --faint: the credit is meant to be quiet, but --faint lands at
   3.36:1 on the page ground and fine print has to clear 4.5:1. --muted is 5.7:1
   and still reads as a subtle credit rather than a banner. */
.rb-credit a { color: var(--muted); text-decoration: none; transition: color var(--dur-1) var(--ease-out); }
.rb-credit a:hover { color: var(--text-2); }

/* ==========================================================================
   16. <=1024px — rail collapses to the bottom-tab bar (house rule 3)

   NOTE: the tab bar and the More drawer are DELIBERATELY always-dark
   regardless of [data-theme]. Their hex literals below are the two documented
   exceptions to "no hex in a component rule" — they are not tokens waiting to
   be substituted, and replacing them with var(--surface) would break the
   pattern this nav is required to mirror. The ACCENT, however, is always the
   host site's own var(--accent) — never a borrowed purple.
   ========================================================================== */

.rb-mobile-nav { display: none; }
.rb-more { display: none; }

@media (max-width: 1024px) {
  .rb-rail { display: none; }
  .rb-topbar { padding-left: var(--s-4); padding-right: var(--s-4); }
  .rb-shell { padding: var(--s-4); }
  .rb-credit { padding-bottom: var(--s-4); }
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

  .rb-mobile-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: var(--z-tabbar);
    background: #0a0c14; border-top: 1px solid #1e2535;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .rb-mobile-nav a, .rb-mobile-nav .rb-more-toggle {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; background: none; border: none; padding: 0; cursor: pointer;
    color: var(--muted); text-decoration: none; font-family: inherit;
    font-size: 0.58rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    transition: color var(--dur-1) var(--ease-out);
  }
  .rb-mobile-nav a .rb-ico, .rb-mobile-nav .rb-more-toggle .rb-ico { font-size: 1.15rem; }
  .rb-mobile-nav a:hover, .rb-mobile-nav .rb-more-toggle:hover {
    color: var(--accent);
  }
  .rb-mobile-nav a.active { color: var(--accent); }

  .rb-more.open { display: block; position: fixed; inset: 0; z-index: var(--z-drawer); }
  .rb-more-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
  .rb-more-drawer {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: #0d0f18; border-top: 1px solid #1e2535;
    border-radius: 18px 18px 0 0;
    padding: var(--s-3) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom));
    animation: rbSheetUp var(--dur-3) var(--ease-out);
  }
  .rb-more-handle { width: 38px; height: 4px; border-radius: var(--r-pill); background: #2d3748; margin: var(--s-1) auto var(--s-4); }
  .rb-more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
  .rb-more-tile {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    min-height: 76px;
    background: #141720; border: 1px solid #1e2535; border-radius: var(--r-md);
    padding: var(--s-4) var(--s-2);
    color: var(--text-2); text-decoration: none; font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em; text-align: center;
    transition: background var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out);
  }
  .rb-more-tile .rb-more-ico { font-size: 1.4rem; color: var(--accent); }
  .rb-more-tile:hover { background: #1a1e28; }
  .rb-more-tile.active {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    color: var(--accent);
  }
  .rb-more-logout { grid-column: 1 / -1; margin: var(--s-1) 0 0; }
  .rb-more-logout button {
    width: 100%; min-height: 48px;
    background: rgba(245,101,101,0.12); border: 1px solid rgba(245,101,101,0.35);
    color: #f56565; border-radius: var(--r-md); padding: var(--s-3);
    font-family: inherit; font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer;
  }
}

@keyframes rbSheetUp { from { transform: translateY(100%); } to { transform: none; } }

/* --------------------------------------------------------------------------
   17. Reduced motion — shipped with the motion, not as a follow-up
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  a.rb-card:hover, .rb-card-link:hover, .rb-btn:active { transform: none; }
}

/* --------------------------------------------------------------------------
   18. Flow outline  (the read-only view of a published call flow)
   -------------------------------------------------------------------------- */

.fl-lead { font-size: var(--t-lg); line-height: 1.6; color: var(--muted); max-width: 60ch; }
.fl-steps { list-style: none; margin: var(--s-5) 0 0; padding: 0; display: grid; gap: var(--s-3); }
/* .rb-card already carries the surface, border and radius. A step adds only its
   own interior rhythm -- a second border or a shadow here would break rule 3. */
.fl-step { display: grid; gap: var(--s-2); }
.fl-step-kind {
  font-size: var(--t-xs); letter-spacing: 0.06em; text-transform: uppercase;
  font-weight: 700; color: var(--accent);
}
.fl-step-copy { font-size: var(--t-base); line-height: 1.6; color: var(--text); margin: 0; }
.fl-step-id { font-family: var(--font-mono-num); font-size: var(--t-sm); color: var(--muted); }

/* --------------------------------------------------------------------------
   19. Print — invoices, quotes and work orders get printed on real paper
   -------------------------------------------------------------------------- */

@media print {
  .rb-rail, .rb-topbar, .rb-mobile-nav, .rb-more, .rb-page-actions, .tok-badge { display: none !important; }
  body { background: #fff; color: #000; padding-bottom: 0; }
  .rb-card, .rb-rows, .rb-table-wrap { border-color: #ccc; break-inside: avoid; }
  .rb-shell { max-width: none; padding: 0; }
}
