/* WaitClock base styles (foundation). Brand tokens from docs/ARCHITECTURE.md "Brand".
   Contract tokens are kept exactly; *-ink variants are additions for TEXT on light grounds where the contract hue is
   below WCAG AA 4.5:1 (e.g. --warn #B77E00 is 3.1:1 on --paper). Status color is never used alone: pair it with a
   text label and a shape (.status-*::before). No inline styles anywhere (CSP). */

:root {
  color-scheme: light;
  /* Contract palette (light) */
  --ink: #13212B;
  --paper: #EEF1EE;
  --sage: #5C7064;
  --bentonite: #C9B99A;
  --signal: #E3A21A;       /* fills and icons only; never text on light */
  --signal-ink: #8A5300;   /* amber for text on light */
  --ok: #1E7F4A;
  --warn: #B77E00;
  --bad: #B53A2E;
  --unknown: #6B7780;

  /* Derived (additions) */
  --text: var(--ink);
  --text-muted: #4F5E56;
  --surface: #FFFFFF;
  --surface-2: #E4EAE5;
  --line: #C8D0CA;
  --ok-ink: #176B3D;
  --warn-ink: #7A5600;
  --bad-ink: #B53A2E;
  --unknown-ink: #56616A;
  --ok-tint: #DCEFE3;
  --warn-tint: #FBEFD2;
  --bad-tint: #F7E0DD;
  --unknown-tint: #E3E7EA;
  --focus: #13212B;
  --btn-primary-bg: #13212B;
  --btn-primary-fg: #FFFFFF;
  --shadow: 0 1px 2px rgba(19, 33, 43, 0.08), 0 4px 12px rgba(19, 33, 43, 0.06);

  /* Type. Brand faces are listed first and used when installed/self-hosted (CSP font-src 'self'); otherwise the
     system stack renders. */
  --font-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 6px;
  --gap: 16px;
  --touch: 44px;
  --maxw: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #0F1A22;         /* ground */
    --paper: #0F1A22;
    --text: #E6EBE7;
    --text-muted: #A9B6AE;
    --sage: #9FB5A7;
    --bentonite: #C9B99A;
    --signal: #E3A21A;
    --signal-ink: #F0B94A;
    --ok: #4CC38A;
    --warn: #E3A21A;
    --bad: #F08A7E;
    --unknown: #9AA5AE;
    --surface: #172630;
    --surface-2: #1D2F3B;
    --line: #2E4250;
    --ok-ink: #4CC38A;
    --warn-ink: #E3A21A;
    --bad-ink: #F08A7E;
    --unknown-ink: #9AA5AE;
    --ok-tint: #123326;
    --warn-tint: #3A2E10;
    --bad-tint: #3D1D1A;
    --unknown-tint: #243039;
    --focus: #E3A21A;
    --btn-primary-bg: #E6EBE7;
    --btn-primary-fg: #0F1A22;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #0F1A22;
  --paper: #0F1A22;
  --text: #E6EBE7;
  --text-muted: #A9B6AE;
  --sage: #9FB5A7;
  --bentonite: #C9B99A;
  --signal: #E3A21A;
  --signal-ink: #F0B94A;
  --ok: #4CC38A;
  --warn: #E3A21A;
  --bad: #F08A7E;
  --unknown: #9AA5AE;
  --surface: #172630;
  --surface-2: #1D2F3B;
  --line: #2E4250;
  --ok-ink: #4CC38A;
  --warn-ink: #E3A21A;
  --bad-ink: #F08A7E;
  --unknown-ink: #9AA5AE;
  --ok-tint: #123326;
  --warn-tint: #3A2E10;
  --bad-tint: #3D1D1A;
  --unknown-tint: #243039;
  --focus: #E3A21A;
  --btn-primary-bg: #E6EBE7;
  --btn-primary-fg: #0F1A22;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.01em;
  margin: 0 0 0.5em;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; font-weight: 600; }
h3 { font-size: 1.2rem; font-weight: 600; }

p { margin: 0 0 1em; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.lead { font-size: 1.2rem; }
.num, .mono, time, .timer {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* Focus: always visible, never removed. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

/* Brand mark */
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); min-height: var(--touch); }
.mark { flex: none; }
.mark-stroke { stroke: currentColor; }
.mark-stroke-fill { fill: currentColor; }
.mark-wedge { fill: var(--signal); }
.wordmark { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; letter-spacing: 0.02em; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); border-color: var(--btn-primary-bg); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-signal { background: var(--signal); color: #13212B; border-color: var(--signal); }
.btn-quiet { background: transparent; border-color: transparent; }
.btn-quiet:hover { border-color: var(--line); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.inline-form { display: inline; margin: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
label { font-weight: 600; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--text-muted);
  border-radius: var(--radius);
  min-height: var(--touch);
  padding: 8px 12px;
  width: 100%;
}
textarea { min-height: 96px; }
input[aria-invalid="true"], .input-validation-error { border-color: var(--bad); border-width: 2px; }
.field-error { color: var(--bad-ink); font-size: 0.9rem; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius); border-left: 4px solid; margin: 0 0 16px; }
.alert-ok { background: var(--ok-tint); border-color: var(--ok); color: var(--ok-ink); }
.alert-warn { background: var(--warn-tint); border-color: var(--warn); color: var(--warn-ink); }
.alert-bad { background: var(--bad-tint); border-color: var(--bad); color: var(--bad-ink); }

/* Status badges: color + text + shape (survives glare and color blindness). */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-demo { background: var(--bentonite); color: #13212B; }
.status-ok { background: var(--ok-tint); color: var(--ok-ink); }
.status-warn { background: var(--warn-tint); color: var(--warn-ink); }
.status-bad { background: var(--bad-tint); color: var(--bad-ink); }
.status-unknown { background: var(--unknown-tint); color: var(--unknown-ink); }
.status-ok::before, .status-warn::before, .status-bad::before, .status-unknown::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  background: currentColor;
}
.status-ok::before { border-radius: 50%; }                                   /* circle */
.status-warn::before { clip-path: polygon(50% 0, 100% 100%, 0 100%); }       /* triangle */
.status-bad::before { border-radius: 1px; }                                   /* square */
.status-unknown::before { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); } /* diamond */

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.table tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 24px; text-align: center; color: var(--text-muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Toasts (wc.toast) */
.toasts { position: fixed; right: 16px; bottom: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 50; pointer-events: none; }
.toast { pointer-events: auto; max-width: 420px; padding: 12px 16px; border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow); border-left: 4px solid var(--sage); }
.toast-ok { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn); }
.toast-bad { border-left-color: var(--bad); }

/* Auth pages (login, logout, password) */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 24px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 16px; }

/* Marketing shell (content styling lives in marketing.css, owned by Marketing) */
.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.site-header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }
.site-main { min-height: 60vh; }
.site-footer { border-top: 1px solid var(--line); padding: 24px 0; margin-top: 48px; }
.placeholder-hero { padding: 64px 16px; }
.placeholder-hero h1 { font-size: clamp(2rem, 6vw, 3.25rem); }

/* Visually hidden, still read by screen readers (shared; integration request dispatch #3). */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
