/* AskSathi V3 — design tokens (single source of truth for the UI).
   XIV.1: NO hardcoded visual value in any component, ever — every colour,
   spacing, radius, and type value resolves through a token here.
   XIV.2 token order: primitives -> semantic aliases -> numeric scales ->
   components. Fork F-2: this sheet drives separate HTML files (no HTML in
   Python). Contrast pairs meet WCAG 2.2 AA (>= 4.5:1 body text; >= 3:1
   large text and UI parts); focus is always visible; targets >= 44px. */

:root {
  /* 1 — primitives */
  --raw-paper: #faf9f7;
  --raw-white: #ffffff;
  --raw-ink-900: #1f2933;
  --raw-ink-600: #3e4c59;
  --raw-terracotta-800: #7c2d12;
  --raw-green-900: #14532d;
  --raw-amber-800: #92400e;
  --raw-red-900: #7f1d1d;
  --raw-sand-300: #d3cec4;
  --raw-blue-700: #1d4ed8;

  /* 2 — semantic aliases */
  --color-bg: var(--raw-paper);
  --color-surface: var(--raw-white);
  --color-ink: var(--raw-ink-900);        /* 14.6:1 on surface */
  --color-ink-soft: var(--raw-ink-600);   /* 9.4:1 on surface */
  --color-brand: var(--raw-terracotta-800);
  --color-good: var(--raw-green-900);
  --color-watch: var(--raw-amber-800);
  --color-attention: var(--raw-red-900);
  --color-line: var(--raw-sand-300);
  --color-focus: var(--raw-blue-700);

  /* 3 — numeric scales */
  --font-body: system-ui, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --size-body: 1.06rem;
  --size-h1: 1.6rem;
  --size-h2: 1.25rem;
  --leading: 1.6;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --radius: 10px;
  --target-min: 44px;   /* WCAG 2.2 minimum target size */
}

/* 4 — components (shared across the separate HTML surfaces) */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--size-body);
  line-height: var(--leading);
}
header.site {
  background: var(--color-brand);
  color: var(--color-surface);
  padding: var(--space-2) var(--space-3);
}
main { max-width: 60rem; margin: 0 auto; padding: var(--space-3); }
h1 { font-size: var(--size-h1); margin: 0; }
h2 { font-size: var(--size-h2); color: var(--color-ink-soft); }
section.card {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}
label { display: block; margin-bottom: var(--space-1); font-weight: 600; }
input, select, textarea, button {
  font: inherit;
  min-height: var(--target-min);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-ink-soft);
  border-radius: var(--radius);
}
button {
  background: var(--color-brand);
  color: var(--color-surface);
  border: none;
  cursor: pointer;
}
button.secondary { background: var(--color-ink-soft); }
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
table { border-collapse: collapse; width: 100%; }
th, td {
  text-align: left;
  padding: var(--space-1);
  border-bottom: 1px solid var(--color-line);
}
.badge {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: var(--radius);
  color: var(--color-surface);
  font-weight: 600;
}
.badge.good { background: var(--color-good); }
.badge.watch { background: var(--color-watch); }
.badge.needs_attention { background: var(--color-attention); }
.hint {
  color: var(--color-muted, #555);
  font-size: 0.9rem;
}
.setting-row { margin: var(--space-2) 0; }
.setting-row label { font-weight: 600; }
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
[aria-live] { min-height: var(--space-3); }
a { color: var(--color-brand); }
a:visited { color: var(--color-brand); }
header.site nav a, footer.site a { color: inherit; }
header.site { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
footer.site {
  max-width: 60rem;
  margin: 0 auto;
  padding: var(--space-3);
  color: var(--color-ink-soft);
  border-top: 1px solid var(--color-line);
}
a.button {
  display: inline-flex;
  align-items: center;
  min-height: var(--target-min);
  padding: var(--space-1) var(--space-2);
  background: var(--color-brand);
  color: var(--color-surface);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}
.legal-body p { white-space: pre-wrap; }
.doc-meta { color: var(--color-ink-soft); font-size: 0.95rem; }
ol.timeline { list-style: none; padding-left: 0; }
ol.timeline li { border-left: 3px solid var(--color-line); padding: var(--space-1) var(--space-2); margin: 0; }
ol.timeline time { color: var(--color-ink-soft); margin-right: var(--space-1); }
.rhythm-row { display: flex; align-items: center; gap: var(--space-1); min-height: 1.5rem; }
.rhythm-day { min-width: 4rem; color: var(--color-ink-soft); }
.rhythm-bar { background: var(--color-brand); height: 0.9rem; border-radius: var(--radius); min-width: 2px; display: inline-block; }

/* UI-1/TR2-37/A-34 — environment banner. A clone must LOOK like a clone: a
   non-live environment shows a loud striped bar so staff never mistake stage
   for production. On live it is a slim, calm confirmation strip. */
.env-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.4rem 1rem;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-bottom: 2px solid var(--color-line);
}
.env-banner[hidden] { display: none; }
.env-banner--live {
  background: var(--color-good);
  color: var(--raw-white, #fff);
}
.env-banner--clone {
  color: #1a1200;
  background: repeating-linear-gradient(
    45deg,
    var(--color-watch) 0,
    var(--color-watch) 12px,
    #f4c95d 12px,
    #f4c95d 24px
  );
  border-bottom-color: var(--color-attention);
}

/* UI-3/A-36 — responsive breakpoints. Supervisor phone triage is first-class:
   at phone width every table collapses to stacked cards (no horizontal
   scrolling), tap targets stay >=44px, and forms go single-column. */
@media (max-width: 480px) {
  main { padding: var(--space-2); }
  header.site, .env-banner { padding-left: var(--space-2); padding-right: var(--space-2); }

  /* Tables become cards: hide the head, stack each row, label each cell. */
  table, tbody, tr, td { display: block; width: 100%; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden;
          clip: rect(0 0 0 0); white-space: nowrap; }
  tr { border: 1px solid var(--color-line); border-radius: var(--radius);
       margin-bottom: var(--space-2); padding: var(--space-1) var(--space-2); }
  td { border: none; padding: 0.3rem 0; display: flex; gap: var(--space-1);
       align-items: baseline; }
  td::before { content: attr(data-label); font-weight: 600;
               color: var(--color-ink-soft); flex: 0 0 7rem; }
  td[data-label=""]::before, td:not([data-label])::before { content: none; }

  /* Tap targets + single-column forms; nothing overflows the viewport. */
  .card button, form button { width: 100%; }
  input, select, textarea { width: 100%; box-sizing: border-box; }
  body { overflow-wrap: anywhere; }
}

/* UI-16 — kill-switch presentation: radios with consequence text, the
   partial-service and full-stop modes visually distinct. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.kill-modes { border: none; padding: 0; margin: 0; display: grid; gap: var(--space-1); }
.kill-opt {
  display: flex; gap: var(--space-1); align-items: start;
  padding: var(--space-1) var(--space-2); border: 1px solid var(--color-line);
  border-radius: var(--radius); font-weight: 400;
}
.kill-opt input { margin-top: 0.2rem; min-height: auto; }
.kill-opt--distinct { border-color: var(--color-watch); background: #fff8e9; }
.kill-opt--danger { border-color: var(--color-attention); background: #fdecec; }

/* Confirm modal — the shared destructive-action gate (also used by B2-S3.6). */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; display: flex;
  align-items: center; justify-content: center; padding: var(--space-2);
  background: rgba(0, 0, 0, 0.5);
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--color-surface); border-radius: var(--radius);
  padding: var(--space-3); max-width: 32rem; width: 100%;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.modal-actions { display: flex; gap: var(--space-1); margin-top: var(--space-2); }

/* UI-27 — shared component styles (toast, empty-state, skeleton). The modal
   and .sr-only live above. */
.modal--danger { border-top: 4px solid var(--color-attention); }
.toast-host {
  position: fixed; bottom: var(--space-2); right: var(--space-2); z-index: 300;
  display: flex; flex-direction: column; gap: var(--space-1); max-width: 22rem;
}
.toast {
  padding: var(--space-1) var(--space-2); border-radius: var(--radius);
  background: var(--color-ink); color: var(--color-surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.toast--error { background: var(--color-attention); }
.toast--success { background: var(--color-good); }
.empty-state { color: var(--color-ink-soft); font-style: italic; padding: var(--space-2) 0; }
.skeleton-row {
  height: 1.1rem; margin: 0.4rem 0; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--color-line) 25%, #ececec 37%, var(--color-line) 63%);
  background-size: 400% 100%; animation: skeleton 1.4s ease infinite;
}
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton-row { animation: none; } }
