/* ================= RTB frame — base idioms =================
   Shared building blocks for every RTB screen (RTB_FRAME_V2_PLAN.md §3).
   Rules: tokens only (no literal colors except documented exceptions),
   44px touch targets, one primary action per screen, rows for repeated
   items, sheets for forms and detail actions. Screen files add only what
   is specific to that screen. */

/* ---- page scaffolding ---- */
.rtb-page { padding: 0 0 var(--space-6); }
.rtb-page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-4) var(--space-2); }
.rtb-page-head-text { min-width: 0; }
.rtb-eyebrow { font-size: var(--text-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--app-text-muted); }
.rtb-page-title { margin: 0; padding: var(--space-4) var(--space-4) var(--space-2); font-size: var(--text-xl); font-weight: 700; color: var(--app-navy); }
.rtb-page-head .rtb-page-title { padding: 0; }
.rtb-page-sub { margin-top: 2px; font-size: var(--text-sm); color: var(--app-text-muted); }
.rtb-section-title { padding: var(--space-5) var(--space-4) var(--space-2); font-size: var(--text-xs); font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--app-text-muted); }
.rtb-section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-5) var(--space-4) var(--space-2); }
.rtb-section-head .rtb-section-title { padding: 0; }
.rtb-hint { padding: var(--space-3) var(--space-4) var(--space-5); font-size: var(--text-xs); line-height: 1.45; color: var(--app-text-muted); text-align: center; }
.rtb-back { display: inline-flex; align-items: center; gap: 2px; min-height: 32px; font-size: var(--text-sm); font-weight: 600; color: var(--app-text-muted); text-decoration: none; }
.rtb-back svg { width: 16px; height: 16px; }

/* Desktop web: the same screens, centered with a max width. */
@media (min-width: 1024px) {
  /* !important because screen rules (e.g. .rtb-seg { margin: 12px }) would
     otherwise win the cascade and pin their block to the left edge. */
  .main-content > * { max-width: var(--content-max); margin-left: auto !important; margin-right: auto !important; }
}

/* ---- icons (inline SVG from RTBFrame.icon()) ---- */
.rtb-ic { display: inline-block; width: 18px; height: 18px; flex: none; vertical-align: -3px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.rtb-ic-sm { width: 14px; height: 14px; }
.rtb-ic-lg { width: 22px; height: 22px; }

/* ---- lists and rows ---- */
.rtb-list { display: grid; gap: var(--space-2); margin: var(--space-2) var(--space-3); }
.rtb-list-flush { gap: 0; margin: 0; border-top: 1px solid var(--app-border); }
.rtb-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-3) var(--space-4); color: inherit; text-align: left; text-decoration: none; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius-md); transition: background var(--motion-fast); }
.rtb-row.no-lead { grid-template-columns: minmax(0, 1fr) auto; }
.rtb-list-flush .rtb-row { border-width: 0 0 1px; border-radius: 0; }
button.rtb-row { width: 100%; font: inherit; cursor: pointer; }
.rtb-row:active, a.rtb-row:hover, button.rtb-row:hover { background: var(--app-surface-2); }
.rtb-row-main { min-width: 0; }
.rtb-row-main b { display: block; font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--app-ink); overflow-wrap: anywhere; }
.rtb-row-main small { display: block; margin-top: 2px; font-size: var(--text-xs); line-height: 1.35; color: var(--app-text-muted); overflow-wrap: anywhere; }
.rtb-row-trail { display: flex; align-items: center; gap: var(--space-2); color: var(--app-text-placeholder); }
.rtb-row-trail .rtb-ic { width: 18px; height: 18px; }
.rtb-row.is-done .rtb-row-main b { color: var(--app-text-muted); text-decoration: line-through; }

/* status glyph: a 26px circle that carries state by color AND icon */
.rtb-glyph { display: grid; place-items: center; width: 26px; height: 26px; flex: none; border-radius: 50%; color: var(--app-text-muted); background: var(--app-surface-3); border: 1.5px solid var(--app-border-strong); }
.rtb-glyph .rtb-ic { width: 14px; height: 14px; stroke-width: 2.25; }
.rtb-glyph-ok { color: #fff; background: var(--app-ok); border-color: var(--app-ok); }
.rtb-glyph-warn { color: var(--app-warn); background: var(--app-warn-bg); border-color: var(--app-warn); }
.rtb-glyph-danger { color: var(--app-danger); background: var(--app-danger-bg); border-color: var(--app-danger); }
.rtb-glyph-info { color: var(--app-info); background: var(--app-info-bg); border-color: var(--app-info); }
.rtb-glyph-muted { color: var(--app-text-placeholder); background: var(--app-surface-2); border-color: var(--app-border); }
button.rtb-glyph { padding: 0; cursor: pointer; }
button.rtb-glyph::after { content: ''; position: absolute; inset: -9px; } /* 44px hit area */
.rtb-glyph-wrap { position: relative; display: grid; place-items: center; width: 44px; height: 44px; margin: -9px; }

/* ---- pills ---- */
.rtb-status, .rtb-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; font-size: 11.5px; font-weight: 650; line-height: 1.3; white-space: nowrap; border: 0; border-radius: var(--radius-pill); color: var(--app-text-muted); background: var(--app-surface-3); }
.rtb-status-not-started, .rtb-pill-muted { color: var(--app-text-muted); background: var(--app-surface-3); }
.rtb-status-in-progress, .rtb-pill-warn { color: var(--app-warn); background: var(--app-warn-bg); }
.rtb-status-complete, .rtb-pill-ok { color: var(--app-ok); background: var(--app-ok-bg); }
.rtb-status-waiting, .rtb-pill-info { color: var(--app-info); background: var(--app-info-bg); }
.rtb-status-blocked, .rtb-pill-danger { color: var(--app-danger); background: var(--app-danger-bg); }
.rtb-status-not-applicable { color: var(--app-text-muted); background: var(--app-surface-3); }
.rtb-phase-chip, .rtb-pill-accent { color: var(--app-navy); background: var(--app-accent-soft); }
.rtb-pill-maroon { color: var(--app-maroon); background: color-mix(in srgb, var(--app-maroon) 10%, white); }

/* ---- cards (summaries only) ---- */
.rtb-card { display: block; margin: var(--space-2) var(--space-3); padding: var(--space-4); color: inherit; text-decoration: none; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius-md); }
a.rtb-card:active, a.rtb-card:hover { background: var(--app-surface-2); }
.rtb-card-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.rtb-card-name { font-size: var(--text-md); font-weight: 650; color: var(--app-navy); overflow-wrap: anywhere; }
.rtb-card-sub { margin-top: 4px; font-size: 12.5px; color: var(--app-text-muted); }
.rtb-card-attn { display: flex; align-items: center; gap: 6px; margin-top: var(--space-2); font-size: var(--text-xs); font-weight: 600; color: var(--app-danger); }
.rtb-summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: var(--space-3) var(--space-3) var(--space-2); padding: var(--space-4); background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius-md); }
.rtb-summary b, .rtb-summary span { display: block; }
.rtb-summary b { font-size: var(--text-md); color: var(--app-navy); }
.rtb-summary span { margin-top: 3px; font-size: 12.5px; color: var(--app-text-muted); }
.rtb-summary-actions { display: flex; flex: none; align-items: center; gap: var(--space-2); }

/* ---- banners ---- */
.rtb-banner { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); margin: var(--space-3) var(--space-3) var(--space-2); padding: var(--space-3) var(--space-4); border: 1px solid; border-radius: var(--radius-md); }
.rtb-banner b { display: block; font-size: 15px; }
.rtb-banner span { display: block; margin-top: 2px; font-size: 12.5px; }
.rtb-banner-ok { color: var(--app-ok); background: var(--app-ok-bg); border-color: color-mix(in srgb, var(--app-ok) 30%, white); }
.rtb-banner-warn { color: var(--app-warn); background: var(--app-warn-bg); border-color: color-mix(in srgb, var(--app-warn) 30%, white); }
.rtb-banner-danger { color: var(--app-danger); background: var(--app-danger-bg); border-color: color-mix(in srgb, var(--app-danger) 30%, white); }
.rtb-banner-stack { grid-template-columns: auto minmax(0, 1fr); align-items: start; margin-left: 0; margin-right: 0; }
.rtb-banner-stack p { margin: 0 0 4px; font-size: 13px; line-height: 1.4; }
.rtb-banner-stack p:last-child { margin-bottom: 0; }
.rtb-banner-info { color: var(--app-info); background: var(--app-info-bg); border-color: color-mix(in srgb, var(--app-info) 30%, white); }

/* ---- buttons ---- */
.rtb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; font-size: var(--text-sm); font-weight: 600; color: var(--app-text-primary); background: var(--app-surface); border: 1px solid var(--app-border-strong); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--motion-fast), opacity var(--motion-fast); }
.rtb-btn:hover { background: var(--app-surface-2); }
.rtb-btn:active { opacity: .85; }
.rtb-btn[disabled] { opacity: .45; cursor: default; }
.rtb-btn-primary { color: #fff; background: var(--app-accent); border-color: var(--app-accent); }
.rtb-btn-primary:hover { background: var(--app-accent); opacity: .92; }
.rtb-btn-ghost { background: transparent; border-color: transparent; color: var(--app-accent); }
.rtb-btn-ghost:hover { background: var(--app-accent-soft); }
.rtb-btn-danger { color: var(--app-danger); background: transparent; border-color: transparent; }
.rtb-btn-danger:hover { background: var(--app-danger-bg); }
.rtb-btn-sm { min-height: 32px; padding: 5px 10px; font-size: var(--text-xs); }
.rtb-btn-block { display: flex; width: 100%; }
.rtb-btn-icon { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
.rtb-btn-icon.rtb-btn-primary { box-shadow: var(--shadow-2); }
.rtb-btn-icon .rtb-ic { width: 20px; height: 20px; }
.rtb-btn:focus-visible, .rtb-row:focus-visible, .rtb-seg-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--app-accent) 35%, white); outline-offset: 2px; }
.rtb-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--app-accent); cursor: pointer; text-decoration: none; }

/* ---- segmented control ---- */
.rtb-seg { display: flex; gap: 2px; margin: var(--space-3) var(--space-3) var(--space-1); padding: 3px; background: var(--app-surface-3); border: 0; border-radius: var(--radius-md); overflow: hidden; }
.rtb-seg-btn { flex: 1; min-height: 38px; padding: 8px 4px; font-size: var(--text-sm); font-weight: 600; color: var(--app-text-muted); background: transparent; border: 0; border-radius: 10px; cursor: pointer; transition: background var(--motion-fast), color var(--motion-fast); }
.rtb-seg-btn.active { color: var(--app-navy); background: var(--app-surface); box-shadow: var(--shadow-1); }
.rtb-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.rtb-chip { min-height: 36px; padding: 6px 14px; font-size: var(--text-sm); font-weight: 600; color: var(--app-text-primary); background: var(--app-surface); border: 1px solid var(--app-border-strong); border-radius: var(--radius-pill); cursor: pointer; }
.rtb-chip.active { color: #fff; background: var(--app-navy); border-color: var(--app-navy); }
.rtb-chips-scroll { display: flex; gap: var(--space-2); padding: var(--space-2) var(--space-3); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.rtb-chips-scroll::-webkit-scrollbar { display: none; }
.rtb-chips-scroll .rtb-chip { flex: none; }

/* ---- forms ---- */
.rtb-field { display: grid; gap: 6px; margin-bottom: var(--space-4); }
.rtb-field > span, .rtb-field > label { font-size: var(--text-xs); font-weight: 650; color: var(--app-text-muted); }
.rtb-input, .rtb-select, .rtb-textarea, .rtb-field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .rtb-field select, .rtb-field textarea { width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; font-size: var(--text-md); color: var(--app-ink); background: var(--app-surface); border: 1px solid var(--app-border-strong); border-radius: var(--radius-sm); outline: none; -webkit-appearance: none; }
.rtb-textarea, .rtb-field textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
.rtb-input:focus, .rtb-select:focus, .rtb-textarea:focus, .rtb-field input:focus, .rtb-field select:focus, .rtb-field textarea:focus { border-color: var(--app-accent); box-shadow: 0 0 0 3px var(--app-accent-soft); }
.rtb-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.rtb-field-help { font-size: var(--text-xs); color: var(--app-text-muted); }
.rtb-field-error { font-size: var(--text-xs); font-weight: 600; color: var(--app-danger); }
.rtb-file { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 8px 12px; border: 1px dashed var(--app-border-strong); border-radius: var(--radius-sm); background: var(--app-surface-2); }
.rtb-file input[type="file"] { min-width: 0; flex: 1; font-size: var(--text-sm); }
.rtb-inline-form { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) var(--space-3); padding: var(--space-3); background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius-md); }
.rtb-inline-form input[type="text"] { min-height: 44px; padding: 10px 12px; font-size: var(--text-md); border: 1px solid var(--app-border-strong); border-radius: var(--radius-sm); }
.rtb-form-row { display: flex; align-items: center; gap: var(--space-2); }
@media (max-width: 560px) { .rtb-field-row { grid-template-columns: 1fr; } }

/* ---- bottom sheet (forms, step detail, confirmations) ---- */
.rtb-sheet-wrap { position: fixed; inset: 0 0 auto; height: var(--app-visible-height, 100dvh); padding-top: env(safe-area-inset-top); z-index: 1200; display: flex; align-items: flex-end; justify-content: center; }
.rtb-sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.rtb-sheet { position: relative; display: flex; flex-direction: column; width: 100%; max-width: 720px; max-height: 92%; background: var(--app-surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-sheet); overflow: hidden; animation: rtb-sheet-in var(--motion-base) ease-out; }
@keyframes rtb-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.rtb-sheet-grip { width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--app-border-strong); }
.rtb-sheet-head { display: flex; flex: none; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--app-border); }
.rtb-sheet-head b { display: block; font-size: var(--text-md); color: var(--app-navy); }
.rtb-sheet-head small { display: block; margin-top: 1px; font-size: var(--text-xs); color: var(--app-text-muted); }
.rtb-sheet-close { width: 40px; height: 40px; padding: 0; color: var(--app-text-muted); background: var(--app-surface-3); border: 0; border-radius: 50%; cursor: pointer; }
.rtb-sheet-body { flex: 1; min-height: 0; padding: var(--space-4); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.rtb-sheet-body:last-child { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }
.rtb-sheet-foot { display: flex; flex: none; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom)); background: var(--app-surface); border-top: 1px solid var(--app-border); }
.rtb-sheet-foot .rtb-btn-danger { margin-right: auto; }
@media (min-width: 720px) { .rtb-sheet-wrap { align-items: center; } .rtb-sheet { border-radius: var(--radius-lg); max-height: 86%; } }

/* ---- states ---- */
.rtb-empty { display: grid; justify-items: center; gap: var(--space-3); margin: var(--space-6) var(--space-4); padding: var(--space-6) var(--space-4); text-align: center; color: var(--app-text-muted); background: var(--app-surface-2); border: 1px dashed var(--app-border-strong); border-radius: var(--radius-md); }
.rtb-empty b { font-size: 15px; color: var(--app-text-primary); }
.rtb-empty p { margin: 0; font-size: var(--text-sm); line-height: 1.45; }
.rtb-error { margin: var(--space-3); padding: var(--space-3) var(--space-4); color: var(--app-danger); background: var(--app-danger-bg); border-radius: var(--radius-md); font-size: var(--text-sm); }
.rtb-skeleton { display: grid; gap: var(--space-2); margin: var(--space-2) var(--space-3); }
.rtb-skeleton > div { height: 56px; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--app-surface-3) 25%, var(--app-surface-2) 50%, var(--app-surface-3) 75%); background-size: 200% 100%; animation: rtb-shimmer 1.2s linear infinite; }
@keyframes rtb-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.rtb-loading-line { padding: var(--space-3) var(--space-4); font-size: var(--text-xs); color: var(--app-text-muted); }

/* ---- details/disclosure ---- */
details.rtb-disclosure { margin: var(--space-2) var(--space-3); background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius-md); }
details.rtb-disclosure > summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 48px; padding: var(--space-3) var(--space-4); font-size: var(--text-sm); font-weight: 600; color: var(--app-navy); list-style: none; cursor: pointer; }
details.rtb-disclosure > summary::-webkit-details-marker { display: none; }
details.rtb-disclosure > summary .rtb-ic { color: var(--app-text-placeholder); transition: transform var(--motion-fast); }
details[open].rtb-disclosure > summary .rtb-ic { transform: rotate(90deg); }
details.rtb-disclosure > .rtb-disclosure-body { padding: 0 var(--space-4) var(--space-4); }

/* ---- legacy helpers still referenced by screens (tokenized) ---- */
.rtb-scaffold-card { margin: var(--space-3); padding: var(--space-4); font-size: 13.5px; line-height: 1.5; color: var(--app-text-primary); background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--radius-md); }
.rtb-scaffold-head { margin-bottom: 4px; font-size: 15px; font-weight: 650; color: var(--app-navy); }
.rtb-scaffold-status { display: inline-block; margin-top: var(--space-2); font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--app-maroon); }
.rtb-owner { padding: 3px 10px; font-size: 11.5px; font-weight: 700; border: 0; border-radius: var(--radius-pill); }
.rtb-owner-eli { color: var(--app-navy); background: var(--app-accent-soft); }
.rtb-owner-todd { color: var(--app-maroon); background: color-mix(in srgb, var(--app-maroon) 12%, white); }
.rtb-due { font-size: var(--text-xs); color: var(--app-text-muted); }
.rtb-due.overdue { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; color: var(--app-danger); }

/* Shared accessibility and form sizing. The glyph hit area stays local to its wrapper. */
.rtb-btn, .rtb-btn-sm, .rtb-seg-btn, .rtb-chip, .rtb-back, .rtb-sheet-close, button.rtb-owner { min-height: 44px; }
.rtb-sheet-close { width: 44px; }
.rtb-glyph { position: relative; }
.rtb-glyph-wrap { position: relative; }
.rtb-row-main { text-decoration: none; }
.rtb-sheet-body p { font-size: var(--text-sm); line-height: 1.5; }
.rtb-sheet-body input, .rtb-sheet-body select, .rtb-sheet-body textarea { max-width: 100%; }
.rtb-sheet-body form[hidden], .rtb-inline-form[hidden] { display: none; }
.rtb-btn[hidden], .rtb-row[hidden], .rtb-chip[hidden] { display: none; }
.rtb-phase-chip { display: inline-flex; padding: var(--space-1) var(--space-2); border-radius: var(--radius-pill); font-size: var(--text-xs); white-space: nowrap; }
.rtb-owner-toggle { display: flex; gap: var(--space-2); }
.rtb-owner-toggle button { min-height: 44px; padding: var(--space-2) var(--space-3); border: 1px solid var(--app-border); border-radius: var(--radius-pill); background: var(--app-surface); color: var(--app-text-primary); }
.rtb-owner-toggle button.active { background: var(--app-navy); color: var(--app-surface); }
.agent-setup { padding: var(--space-4); }
.rtb-ep-warning-dismiss, .rtb-intel-confirm, .rtb-intel-edit, .rtb-sw-guide-options button { min-height: 44px; }
.rtb-row-trail { min-width: 0; }
.agent-ledger-row.rtb-row .rtb-row-trail { flex-wrap: wrap; }
.rtb-sw-check, .rtb-sw-suggestion, .rtb-pp-item { min-height: 44px; }
.rtb-sheet-body input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), .rtb-sheet-body select, .rtb-mail-search select, .rtb-mail-assignment select, .rtb-ep-map select { min-height: 44px; }
.rtb-row-detail a, .rtb-intel-sources a { display: inline-flex; align-items: center; min-height: 44px; }

/* Forms rendered inside a sheet: the sheet is the container, so inline-form
   cards drop their own border, background and outer margin. */
.rtb-sheet-body .rtb-inline-form, .rtb-sheet-body .rtb-schedule-quick-add { margin: 0; padding: 0; background: transparent; border: 0; border-radius: 0; }
.rtb-sheet-body .rtb-field:last-child { margin-bottom: 0; }
.rtb-sheet-body .rtb-section-title { padding-left: 0; padding-right: 0; }
.rtb-sheet-body .rtb-list { margin-left: 0; margin-right: 0; }
.rtb-sheet-body .rtb-empty { margin-left: 0; margin-right: 0; }
.rtb-sheet-body details.rtb-disclosure { margin-left: 0; margin-right: 0; }

/* The keyboard replaces the home-indicator area; avoid a second blank inset. */
.keyboard-open .rtb-sheet-foot { padding-bottom: var(--space-3); }
.keyboard-open .rtb-sheet-body:last-child { padding-bottom: var(--space-4); }
