/* Design system. Edit these tokens and the whole app follows —
   change --accent once rather than hunting hex codes through the markup. */
:root {
  --bg: #0a0a0f;
  --fg: #ffffff;
  --mute: #9ca3af;
  --card: #13131a;
  --border: #27272f;
  --accent: #a78bfa;
  --danger: #f87171;
  --ok: #22c55e;
  --on-accent: #0a0a0f; /* text and icons drawn on --accent */
  --radius: 14px;
  /* Real height of the tab bar, used to pad the scroll area so the last row
     is never trapped underneath it. */
  --tabbar: calc(58px + env(safe-area-inset-bottom));
}

/* A light look: set <html data-theme="light"> (or "dark" back) and change these
   alongside :root. Every colour below is a token, so nothing else needs touching. */
[data-theme=light] {
  --bg: #f8f7ff;
  --fg: #201e43;
  --mute: #686580;
  --card: #ffffff;
  --border: #e4e1f0;
  --accent: #312e81;
  --pink: #f472b6;
  --yellow: #facc15;
  --danger: #a52b55;
  --ok: #18724a;
  --on-accent: #ffffff;
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  min-height: 100vh;
  min-height: 100dvh; /* dvh survives the mobile URL bar collapsing */
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* No pull-to-refresh bounce past the ends: the giveaway that a PWA is a
     web page wearing a costume. */
  overscroll-behavior-y: none;
}

/* ── Right-to-left ───────────────────────────────────────────────────
   Set <html lang="ar" dir="rtl"> and this file flips by itself: spacing and
   alignment use logical properties (margin-inline, padding-inline, inset-inline,
   text-align: start). The exception is the safe-area padding on the bars below:
   a notch or home indicator is on a physical side, so those stay left/right. */

/* ── App bar ─────────────────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(env(safe-area-inset-top) + .875rem) calc(1.25rem + env(safe-area-inset-right)) .875rem calc(1.25rem + env(safe-area-inset-left));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar h1 { font-size: 1.125rem; font-weight: 650; letter-spacing: -.02em; word-break: break-word; }
.status { display: inline-flex; align-items: center; gap: .375rem; margin-inline-start: auto; flex: none; padding: .25rem .625rem; background: var(--card); border: 1px solid var(--border); border-radius: 999px; font-size: .6875rem; color: var(--mute); }
.status .dot { width: 6px; height: 6px; background: #22c55e; border-radius: 50%; box-shadow: 0 0 8px #22c55e; }

/* ── Screens ─────────────────────────────────────────────────────── */
main { padding: 1rem calc(1.25rem + env(safe-area-inset-right)) calc(var(--tabbar) + 1.5rem) calc(1.25rem + env(safe-area-inset-left)); }
.screen { display: none; }
.screen.active { display: block; animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card { padding: 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-block-end: .875rem; }
.card h2 { font-size: 1rem; font-weight: 600; letter-spacing: -.01em; margin-block-end: .375rem; }
.card p { font-size: .875rem; color: var(--mute); line-height: 1.55; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; margin-block-start: .875rem; padding-inline: 1.25rem; background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px; font-size: .9375rem; font-weight: 600; font-family: inherit; cursor: pointer; }
.btn:active { transform: scale(.98); }

.list { list-style: none; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .875rem 1.25rem; font-size: .875rem; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .meta { color: var(--mute); font-size: .75rem; flex: none; }

footer { margin-block-start: 1.5rem; text-align: center; font-size: .75rem; color: var(--mute); }
footer a { color: var(--mute); }

/* ── Bottom tab bar ──────────────────────────────────────────────── */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 58px; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--mute); font-family: inherit; font-size: .625rem; font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }

/* ── Forms and states ────────────────────────────────────────────────
   Unused until the app needs them: no markup here uses them, they carry no copy,
   and every colour is a token. 16px text stops iOS zooming the page when a field
   is focused; 44px is a comfortable tap. */
label { display: block; font-size: .875rem; font-weight: 500; margin-block-end: .375rem; }
.form-group { display: flex; flex-direction: column; margin-block-end: 1rem; }
input, select, textarea { width: 100%; min-height: 44px; padding: .625rem .875rem; background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; font: inherit; font-size: 1rem; text-align: start; }
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input::placeholder, textarea::placeholder { color: var(--mute); }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
[hidden] { display: none !important; }
.btn:disabled, .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.loading { display: flex; align-items: center; gap: .625rem; color: var(--mute); font-size: .875rem; }
.loading::before { content: ""; width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { padding: .75rem 1rem; background: rgba(248, 113, 113, .1); background: color-mix(in srgb, var(--danger) 12%, var(--bg)); border: 1px solid var(--danger); border-radius: 10px; color: var(--fg); font-size: .875rem; }
.empty { padding: 2rem 1rem; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--mute); font-size: .9375rem; }

/* ── Components ──────────────────────────────────────────────────────
   Small, on the tokens, RTL-safe. Use them as they are; change the tokens, not
   these. Behaviour lives in app.js: api(), toast(), sheet(). */

/* row: one line of a list. Put rows in a .list (or any card). */
.row { display: flex; align-items: center; gap: .75rem; min-height: 56px; padding: .625rem 1.25rem; border-block-end: 1px solid var(--border); }
.row:last-child { border-block-end: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: .9375rem; overflow-wrap: anywhere; }
.row-sub { font-size: .75rem; color: var(--mute); }
.row .btn { margin: 0; min-height: 44px; }
.list-actions { display: flex; gap: .75rem; margin-block-start: .875rem; }
.list-actions .btn { flex: 1; margin: 0; }
.btn.secondary { background: var(--card); color: var(--fg); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: var(--on-accent); }
.btn.block { display: flex; width: 100%; }

/* field: a label, a control and a hint under it; .invalid turns the hint red. */
.field { display: flex; flex-direction: column; gap: .375rem; margin-block-end: 1rem; }
.field label { margin: 0; }
.field .hint { font-size: .75rem; color: var(--mute); }
.field.invalid .hint { color: var(--danger); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }

/* sheet: a panel that slides up over the page (sheet() in app.js builds it). */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .5); animation: fade .15s ease-out; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 41; max-height: 85vh; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain; padding: 1.25rem calc(1.25rem + env(safe-area-inset-right)) calc(1.25rem + env(safe-area-inset-bottom)) calc(1.25rem + env(safe-area-inset-left)); background: var(--card); color: var(--fg); border-block-start: 1px solid var(--border); border-radius: calc(var(--radius) + 6px) calc(var(--radius) + 6px) 0 0; animation: slide .2s ease-out; }
.sheet h2 { font-size: 1.0625rem; font-weight: 600; margin-block-end: .5rem; }
.sheet p { color: var(--mute); font-size: .9375rem; }
.sheet-actions { display: flex; gap: .75rem; margin-block-start: 1.25rem; }
.sheet-actions .btn { flex: 1; margin: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(100%); } }

/* segmented: pick one of a few options (tablist semantics, aria-selected). */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; margin-block-end: 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.segmented button { min-height: 40px; padding-inline: .75rem; border: 0; border-radius: 9px; background: none; color: var(--mute); font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--card); color: var(--fg); box-shadow: 0 0 0 1px var(--border); }

/* toast: a short message over the tab bar (toast() in app.js). */
.toast { position: fixed; inset-inline: 0; inset-block-end: calc(var(--tabbar) + .75rem); z-index: 50; width: fit-content; max-width: calc(100% - 2.5rem); margin-inline: auto; padding: .625rem 1rem; background: var(--fg); color: var(--bg); border-radius: 999px; font-size: .875rem; text-align: center; animation: rise .18s ease-out; }
.toast.error { background: var(--danger); color: var(--on-accent); }

/* empty state: .empty already exists; these add a heading, an icon slot and an action. */
.empty strong { display: block; margin-block-end: .25rem; color: var(--fg); font-weight: 600; }
.empty .btn { margin-block-start: 1rem; }

/* badge: a small status pill. */
.badge { display: inline-flex; align-items: center; padding: .125rem .5rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--mute); font-size: .6875rem; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.accent { color: var(--accent); border-color: var(--accent); }
.badge.danger { color: var(--danger); border-color: var(--danger); }

/* avatar: a round picture or initials. */
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 40px; height: 40px; overflow: hidden; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: .9375rem; font-weight: 600; text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.large { width: 72px; height: 72px; font-size: 1.5rem; }

.link { color: var(--accent); }

/* Quote Rescue */
.appbar { background: var(--bg); border:0; padding-block: .8rem; }
.brand-mark { width:42px; height:42px; display:grid; place-items:center; border-radius:14px; background:var(--accent); color:var(--yellow); font-size:1.5rem; font-weight:900; transform:rotate(-5deg); }
.appbar h1 { font-weight:850; line-height:1.1; }
.brand-sub { font-size:.58rem; font-weight:800; letter-spacing:.12em; color:var(--mute); }
.back { margin-inline-start:auto; background:transparent; color:var(--accent); border:0; font:inherit; font-weight:750; min-height:44px; }
.sample-banner { position:sticky; top:0; z-index:60; display:flex; align-items:center; gap:.6rem; background:var(--yellow); color:#312e81; padding:.4rem 1.25rem; font-size:.78rem; }
.sample-banner button { margin-inline-start:auto; background:none; border:0; min-height:36px; color:inherit; font-weight:800; }
main { max-width:650px; margin:auto; padding-top:.6rem; }
.hero { margin:.4rem 0 1.1rem; }.eyebrow { color:var(--accent); font-size:.68rem; font-weight:850; letter-spacing:.12em; text-transform:uppercase; }.hero h2 { font-size:1.9rem; line-height:1.12; letter-spacing:-.05em; margin:.3rem 0; }.hero p,.muted { color:var(--mute); font-size:.88rem; }
.lane { width:100%; display:flex; align-items:center; text-align:start; justify-content:space-between; gap:1rem; border:1px solid var(--border); border-radius:20px; padding:1rem 1.1rem; background:var(--card); color:var(--fg); min-height:105px; margin-bottom:.65rem; font:inherit; cursor:pointer; box-shadow:0 5px 18px #312e8108; }.lane.follow { background:var(--accent); color:white; }.lane.review { background:#fff4fa; border-color:#f9cde4; }.lane.closed { background:#f1f0f6; }.lane strong { display:block; font-size:1rem; font-weight:850; }.lane small { display:block; font-size:.76rem; opacity:.75; }.lane b { font-size:2.4rem; letter-spacing:-.06em; line-height:1; }
.action-row,.quote-row { width:100%; border:0; background:transparent; color:var(--fg); text-align:start; display:flex; align-items:center; justify-content:space-between; gap:1rem; min-height:58px; padding:.8rem 0; border-bottom:1px solid var(--border); font:inherit; cursor:pointer; }.action-row strong,.quote-row strong { display:block; }.quote-row small { display:block; color:var(--mute); }.chev { color:var(--accent); font-size:1.4rem; }.value { font-size:1.75rem; color:var(--accent); font-weight:850; letter-spacing:-.04em; }.quote-title { font-size:1.7rem; letter-spacing:-.04em; }.promise { border-inline-start:4px solid var(--pink); padding:.9rem; background:#fff3f9; border-radius:0 12px 12px 0; white-space:pre-wrap; overflow-wrap:anywhere; }.section-label { text-transform:uppercase; letter-spacing:.1em; font-size:.68rem; font-weight:850; color:var(--mute); margin:1.1rem 0 .45rem; }.card { border-radius:20px; }.card p { white-space:pre-wrap; overflow-wrap:anywhere; }.sheet { max-height:75dvh; }.sample-banner ~ main + .tabbar {} .sheet textarea { min-height:140px; }.sheet .action-row { min-height:52px; }.sheet-backdrop { z-index:40; }.sheet { z-index:41; }.tabbar { background:var(--card); }.tab.active { color:var(--accent); font-weight:800; }.tag { background:var(--yellow); border-radius:999px; color:var(--accent); font-size:.65rem; font-weight:850; padding:.25rem .6rem; }.history-line { padding:.5rem 0; border-bottom:1px solid var(--border); font-size:.85rem; }.total-link { border:0; background:transparent; text-align:start; font:inherit; width:100%; cursor:pointer; }.button-stack .btn { width:100%; }.preview { white-space:pre-wrap; overflow-wrap:anywhere; max-height:50vh; overflow:auto; background:var(--bg); padding:1rem; border-radius:12px; font-size:.8rem; }.warning { color:var(--danger); font-weight:700; }.field { margin-top:.8rem; } details summary { cursor:pointer; min-height:44px; padding:.6rem 0; font-weight:700; } .btn { cursor:pointer; } .footnote { color:var(--mute); font-size:.75rem; margin-top:.5rem; }
/* Mobile polish: thumb-sized controls, calmer hierarchy and safe-area aware sheets. */
:root { --tabbar: calc(70px + env(safe-area-inset-bottom)); }
body { background: radial-gradient(ellipse at 92% 0%, #fce9f5 0, transparent 280px), var(--bg); }
.appbar { background:color-mix(in srgb, var(--bg) 94%, transparent); padding-block: .7rem; border-block-end:1px solid #e9e6f3; }
.brand-mark { box-shadow:3px 4px 0 var(--pink); }
.brand-sub { letter-spacing:.14em; }
.back { border:1px solid var(--border); background:var(--card); padding-inline:.9rem; border-radius:999px; font-size:.82rem; }
main { padding-block-start:1rem; }
.hero { margin:.2rem 0 1.15rem; }
.hero h2 { font-size:clamp(1.75rem,7vw,2.15rem); }
.intro-card { background:var(--card); border:1px solid var(--border); border-radius:24px; padding:1.2rem; box-shadow:0 12px 32px #312e810b; }
.import-preview-row { margin-top:.8rem; padding:1rem; border:1px solid var(--border); border-radius:14px; background:#f9f8ff; font-size:.85rem; overflow-wrap:anywhere; }.import-preview-row dl { display:grid; grid-template-columns:minmax(95px, .8fr) minmax(0, 1.2fr); gap:.35rem .75rem; margin-top:.7rem; }.import-preview-row dt { color:var(--mute); }.import-preview-row dd { white-space:pre-wrap; }.import-preview-row .warning { margin-top:.6rem; }
.paste-import { border-top:1px solid var(--border); margin-top:1rem; padding-top:.3rem; }.paste-import .paste-toggle { color:var(--accent); font-weight:750; border:0; }.paste-import textarea { min-height:140px; }.paste-import .btn { margin-bottom:.8rem; }
.intro-card p { color:var(--mute); font-size:.9rem; }.intro-icon { display:grid; place-items:center; width:52px; height:52px; border-radius:16px; background:#fce6f3; color:var(--accent); margin-bottom:1rem; }.intro-icon svg { width:26px; height:26px; }
.lane { min-height:106px; border-radius:22px; padding:1rem 1.2rem; box-shadow:0 8px 24px #312e8109; }
.lane.follow { background:linear-gradient(135deg,#312e81,#4943a0); border-color:#312e81; box-shadow:0 10px 24px #312e8127; }
.lane.follow b { color:var(--yellow); }
.lane.review { background:#fff0f8; border-color:#f8cde4; }
.lane.closed { background:#f0eff7; }
.lane strong { letter-spacing:.025em; line-height:1.25; }
.lane small { margin-top:.3rem; }
.card { box-shadow:0 8px 26px #312e8108; border-radius:22px; }
.total-link.card { background:var(--card); border:1px solid var(--border); padding:1.2rem; }
.total-link.card .section-label { margin:0 0 .25rem; }
.value { overflow-wrap:anywhere; }
.quote-row { align-items:center; gap:.75rem; }.quote-row > span:first-child { flex:1; min-width:0; overflow-wrap:anywhere; }.quote-row > span:last-child { text-align:end; overflow-wrap:anywhere; }
.action-row:last-child,.quote-row:last-child { border-bottom:0; }
.btn { min-height:50px; border-radius:14px; font-weight:750; }
.btn.secondary { background:#fff; }
input,select,textarea { background:#fff; border-radius:13px; min-height:50px; }
.field label { font-weight:700; font-size:.82rem; }
.sheet { border-radius:26px 26px 0 0; max-height:min(78dvh, 720px); box-shadow:0 -12px 48px #19153225; padding-block-start:1.5rem; }
.sheet::before { content:''; display:block; width:38px; height:4px; background:#d9d6e6; border-radius:99px; margin:-.6rem auto 1rem; }
.sheet h2 { font-size:1.15rem; font-weight:800; letter-spacing:-.02em; }.composer-sheet { max-height:min(68dvh, 660px); }.composer-sheet textarea { min-height:120px; }
.sheet-actions { gap:.5rem; }.sheet-actions .btn { min-width:0; padding-inline:.65rem; font-size:.83rem; }
.tabbar { box-shadow:0 -6px 24px #312e8109; }
.tab { min-height:70px; font-size:.68rem; gap:4px; }
.tab.active svg { background:#eeeafb; border-radius:10px; box-sizing:content-box; padding:4px 10px; margin:-4px -10px; }
.sample-banner { padding-inline:calc(1.25rem + env(safe-area-inset-left)) calc(1.25rem + env(safe-area-inset-right)); }
.sample-banner button { min-height:44px; }
:where(button,summary):focus-visible { outline:3px solid var(--pink); outline-offset:3px; }
@media (max-width:350px) { main { padding-inline:calc(.9rem + env(safe-area-inset-left)) calc(.9rem + env(safe-area-inset-right)); } .lane { padding-inline:1rem; }.sheet-actions { flex-wrap:wrap; }.sheet-actions .btn { flex:1 1 40%; } }
@media (prefers-reduced-motion: reduce) {
  .screen.active, .toast, .sheet, .sheet-backdrop { animation: none; }
  .loading::before { animation-duration: 2.4s; }
}
.voice-example { border:1px solid var(--border); border-radius:12px; padding:.85rem 1rem; margin:.5rem 0; background:color-mix(in srgb, var(--accent) 6%, transparent); }
.voice-text { margin:0 0 .5rem 0; font-size:.95rem; color:var(--fg); }
.voice-basis { font-size:.82rem; color:var(--mute); margin:.5rem 0 0 0; }

.ladder { border:1px solid var(--border); border-radius:14px; padding:.75rem 1rem; background:#f9f8ff; margin-top:1rem; overflow-wrap:anywhere; }
.ladder-rung { border:1px solid var(--border); border-radius:12px; padding:.7rem 1rem; margin:.55rem 0; background:#fff; display:flex; align-items:flex-start; gap:.8rem; }
.ladder-rung.ladder-next { border-color:var(--accent); background:color-mix(in srgb, var(--accent) 8%, transparent); }
.ladder-rung.ladder-stale { opacity:.85; }
.rung-number { flex-shrink:0; width:26px; height:26px; border-radius:50%; background:var(--accent); color:#fff; font-weight:800; font-size:.85rem; display:grid; place-items:center; margin-top:.1rem; }
.ladder-next .rung-number { background:var(--accent); box-shadow:0 0 0 3px color-mix(in srgb, var(--accent) 35%); }
.rung-body { flex:1; }
.rung-rev { font-size:.78rem; color:var(--mute); margin-bottom:.2rem; }
.rung-text { font-size:1rem; color:var(--fg); margin-bottom:.35rem; }
.rung-state { font-size:.82rem; color:var(--mute); }
.rung-actions { flex-shrink:0; display:flex; gap:.5rem; flex-wrap:wrap; margin-top:.4rem; }
.rung-actions .btn { font-size:.86rem; padding:.42rem .85rem; }

.check-row { border:1px solid var(--border); border-radius:12px; padding:.75rem 1rem; margin:.5rem 0; background:#fff; }
.check-row .verdict { float:right; font-weight:800; font-size:.85rem; padding:.15rem .6rem; border-radius:8px; }
.check-row .verdict.pass { color:var(--ok); background:color-mix(in srgb, var(--ok) 12%, transparent); }
.check-row .verdict.fail { color:#b3261e; background:color-mix(in srgb, #b3261e 12%, transparent); }
.check-row p { margin:.35rem 0 0 0; font-size:.88rem; color:var(--mute); }
