/* =====================================================================================
 * app.css — web-guardian, built against the REAL Claude Design export ("Ember"), landed
 * 2026-07-12. Imports tokens.css + components.css directly and uses their `.ra-*` classes as the
 * primary building blocks; only structural/page-scaffolding CSS lives here.
 *
 * Hard rules from design/README.md this file (and ui.js) must uphold — see the handoff for the
 * two flagged conflicts (pre-alert / check-in "PIN-gated" vs the binding no-PIN state machine):
 *   1. Green = safe/resolved ONLY. Armed = amber. Live alert = red. Degraded = amber hazard.
 *   2. #10/#11 (PIN entry, cancelled/resolved confirmation) are pixel-identical for safe & duress.
 *   3. Status is never color-alone — every state pairs a glyph + words (components.css bakes
 *      this into .ra-row / .ra-chip / .ra-banner-* already).
 *   4. Touch floors: 56px interactive, 64px primary, 84px critical (SOS / I'm OK), 76px PIN keys
 *      — all from --hit-* tokens, applied via the .ra-btn / .ra-key modifier classes.
 * ===================================================================================== */

@import url("../design/tokens.css");
@import url("../design/components/components.css");

* { box-sizing: border-box; }

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

h1 { font-size: var(--fs-h1); line-height: var(--lh-tight); margin: 0 0 var(--sp-2); font-weight: 800; }
h2 { font-size: var(--fs-h2); line-height: var(--lh-tight); margin: var(--sp-6) 0 var(--sp-2); font-weight: 800; }
p { margin: 0 0 var(--sp-3); color: var(--text-dim); }
.ra-caption { margin: 0; }
a { color: var(--info-text); }

/* ── Screen scaffolding ─────────────────────────────────────────────────────────── */
.screen {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--sp-6) var(--screen-pad) var(--sp-11);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
/* Every screen carries the ambient page gradient (.ra-screen); armed states add the amber wash. */
body { background: var(--bg); }
#app { background: radial-gradient(130% 90% at 50% 0%, var(--bg-top) 0%, var(--bg) 60%); color: var(--text); }
#app.chrome-armed { background: radial-gradient(120% 70% at 50% -10%, var(--accent-glow) 0%, rgba(245,158,11,0) 55%), radial-gradient(130% 90% at 50% 0%, var(--bg-top) 0%, var(--bg) 60%); }

.topbar {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) 0 var(--sp-4);
}
.topbar .brand { font-weight: 800; font-size: var(--fs-title); color: var(--text-dim); }
.topbar-title { font-weight: 700; flex: 1; }
.topbar > .lang-switch { margin-left: auto; }
.icon-btn {
  width: var(--hit-min); height: var(--hit-min);
  border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: none; color: var(--text); font-size: 1.3rem; cursor: pointer;
}
.lang-switch {
  min-height: 40px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); border: 1px solid var(--border-chip);
  background: var(--fill-ghost); color: var(--text-dim);
  font-size: var(--fs-small); font-weight: 700; cursor: pointer;
}

/* Step progress (onboarding) */
.ra-steps { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.ra-steps__bar { flex: 1; height: 3px; border-radius: 2px; background: var(--border-track); }
.ra-steps__bar--done { background: var(--accent); }
.ra-overline { display: block; margin-bottom: var(--sp-2); }

.navbar {
  margin-top: auto; display: flex; gap: var(--sp-2); padding-top: var(--sp-6);
  border-top: 1px solid var(--border-subtle);
}
.nav-btn {
  flex: 1; min-height: var(--hit-min); border-radius: var(--r-md);
  border: none; background: none; color: var(--text-dim); font-weight: 700; cursor: pointer;
}
.nav-btn--active { color: var(--accent-text); }

/* ── Forms ──────────────────────────────────────────────────────────────────────── */
form { display: flex; flex-direction: column; gap: var(--sp-3); }
label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-small); color: var(--text-dim); }
input, select {
  font-family: inherit; font-size: 1rem; min-height: var(--hit-min);
  padding: 0 var(--sp-3); border-radius: var(--r-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
input:focus, select:focus, button:focus-visible {
  outline: 3px solid var(--info); outline-offset: 2px;
}
.toggle-row { flex-direction: row; align-items: center; gap: var(--sp-2); font-size: var(--fs-body); color: var(--text); }
.toggle-row input { width: 24px; height: 24px; min-height: auto; }
.hidden { display: none !important; }

/* Duration chip group (arm-sheet "HOW LONG") */
.ra-chipgroup { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.ra-chipbtn {
  min-height: var(--hit-min); padding: 0 var(--sp-4);
  border-radius: var(--r-md); border: 1.5px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 700; font-size: var(--fs-body);
  cursor: pointer; flex: 1 1 auto;
}
.ra-chipbtn--selected { border-color: var(--accent); background: var(--accent-dim); color: var(--accent-text); }

/* Check-in stepper */
.ra-stepper { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.ra-stepper__btn {
  width: var(--hit-min); height: var(--hit-min); border-radius: var(--r-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 1.4rem; font-weight: 700; cursor: pointer;
}
.ra-stepper__value { font-size: var(--fs-h2); font-weight: 800; font-variant-numeric: tabular-nums; }

/* ── Buttons not already covered by components.css ─────────────────────────────── */
.link-btn, .btn-link {
  background: none; border: none; color: var(--info-text);
  min-height: var(--hit-min); text-decoration: underline; cursor: pointer; font-size: var(--fs-body);
}

/* A <button> reusing a components.css presentational class (e.g. .ra-chip for a tappable
   "Resend invite" pill) must not show native button chrome underneath it. */
button.ra-chip { font-family: inherit; cursor: pointer; }

/* ── Angels ─────────────────────────────────────────────────────────────────────── */
.angel-readiness { list-style: none; margin: 0; padding: 0; }
.angel-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--border-subtle); flex-wrap: wrap;
}
.angel-row:last-child { border-bottom: none; }
.angel-row__main { flex: 1; min-width: 0; }
.angel-name { font-weight: 700; display: block; }
.angel-status { font-size: var(--fs-caption); color: var(--text-muted); }
.angel-status--ok { color: var(--safe-text); }
.angel-status--warn { color: var(--accent-text); }
.angel-row__actions { display: flex; gap: var(--sp-2); }

/* ── Ring / countdowns (arm-sheet, checkin) ─────────────────────────────────────── */
.ring-wrap { display: flex; justify-content: center; padding: var(--sp-4) 0; }

/* ── Pre-alert / check-in grace / discreet: full-bleed, no chrome ──────────────── */
.screen-bare {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: var(--sp-4); padding: var(--sp-8) var(--screen-pad);
  max-width: 480px; margin: 0 auto; width: 100%;
}

/* Discreet AOD: pure black, theme-independent, per design/README hard rule. */
.screen-discreet {
  position: fixed; inset: 0; background: #000; color: rgb(120,128,150);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2); z-index: 10; touch-action: none; user-select: none;
}
.discreet-clock { font-size: 64px; font-weight: 300; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.discreet-date { font-size: var(--fs-body); color: rgb(90,96,116); }
.discreet-hold-hint { position: absolute; bottom: var(--sp-8); font-size: var(--fs-micro); color: rgb(60,64,80); }
.discreet-progress {
  position: absolute; bottom: 0; left: 0; height: 3px; background: rgba(120,128,150,0.5);
  width: 0%; transition: width linear;
}

/* ── Active session ─────────────────────────────────────────────────────────────── */
.trigger-line { color: var(--text-dim); margin-bottom: 0; }
.active-actions { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-2); }
.active-actions-row { display: flex; gap: var(--sp-2); }
.active-actions-row .ra-btn { flex: 1; }

/* ── PIN entry ──────────────────────────────────────────────────────────────────── */
.screen-pin { align-items: center; text-align: center; }
.screen-pin h1 { font-size: var(--fs-h1); }

/* ── Summary timeline ───────────────────────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--border-subtle); }
.timeline li:last-child { border-bottom: none; }
.timeline__dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.timeline__dot--armed { background: var(--accent); }
.timeline__dot--alert { background: var(--danger); }
.timeline__dot--safe { background: var(--safe); }
.timeline__body { flex: 1; }
.timeline__title { font-weight: 700; }
.timeline__time { font-size: var(--fs-caption); color: var(--text-muted); }
.stat-tiles { display: flex; gap: var(--sp-2); }
.stat-tile { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-3); }
.stat-tile__num { font-size: var(--fs-h2); font-weight: 800; }
.stat-tile__label { font-size: var(--fs-caption); color: var(--text-dim); }
.purge-card {
  background: var(--accent-dim); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: var(--sp-4);
}
.purge-card__title { color: var(--accent-text); font-weight: 800; margin-bottom: var(--sp-2); }

/* ── Responsive — a real product at every width ───────────────────────────────────
 * Mobile (default): full-width single column, unchanged.
 * ≥760px: the CHROME'd screens (home, onboarding, angels, summary, settings) become an
 *   intentional centered panel in the ambient gradient — deliberate at any size, never a
 *   phone column stranded in a void. The urgent full-bleed moments (pre-alert, check-in,
 *   discreet AOD, PIN) keep their focused full-screen layout on purpose. */
@media (min-width: 640px) {
  .screen { padding-left: var(--sp-8); padding-right: var(--sp-8); }
}

@media (min-width: 760px) {
  #app { justify-content: center; align-items: center; padding: var(--sp-8) var(--sp-6); }
  .screen {
    flex: 0 1 auto;
    width: 100%;
    max-width: 480px;
    max-height: min(880px, calc(100dvh - 2 * var(--sp-8)));
    overflow-y: auto;
    background: var(--surface-sheet);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: 0 30px 70px -28px rgba(0, 0, 0, 0.65);
    padding: var(--sp-8);
  }
  #app.chrome-armed .screen { border-color: var(--border-strong); }
  /* Bare/focused screens stay full-bleed & centered (they are the "something is happening" moments). */
  .screen-bare { max-width: 520px; }
}

/* Wide desktop: a touch more breathing room, but the app stays a single readable column
   (a safety tool should never make you hunt across a wide canvas under stress). */
@media (min-width: 1100px) {
  .screen, .screen-bare { max-width: 500px; }
}

/* Short/landscape: don't force vertical centering when height is tight — let it scroll. */
@media (min-width: 760px) and (max-height: 720px) {
  #app { justify-content: flex-start; }
  .screen { max-height: none; }
}
