/* styles.css — custom-property theming. Light/dark/system via data-theme,
 * high contrast via data-contrast, reduced motion via data-motion, calm
 * mode via data-calm. No pure black/white; 4.5:1 minimum everywhere. */

:root {
  --bg: #f7f9fb;
  --surface: #ffffff;
  --text: #1c2733;
  --text-muted: #4a5a68;
  --accent: #0f4c81;
  --accent-contrast: #f5f9fd;
  --border: #c9d4de;
  --danger: #8f2f2f;
  --danger-bg: #fbeeee;
  --ok: #2e6b46;
  --ok-bg: #ecf6f0;
  --warn-bg: #fdf6e3;
  --warn-border: #b58a2a;
  --focus: #b34700;
  --radius: 8px;
  --maxw: 52rem;
}

[data-theme="dark"] {
  --bg: #131a21;
  --surface: #1c2530;
  --text: #e4ebf1;
  --text-muted: #a9b8c5;
  --accent: #6aa9dd;
  --accent-contrast: #10314e;
  --border: #3a4a5a;
  --danger: #e09393;
  --danger-bg: #3a2323;
  --ok: #93c9a8;
  --ok-bg: #1e3328;
  --warn-bg: #33301e;
  --warn-border: #c9a44a;
  --focus: #ffb066;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #131a21; --surface: #1c2530; --text: #e4ebf1; --text-muted: #a9b8c5;
    --accent: #6aa9dd; --accent-contrast: #10314e; --border: #3a4a5a;
    --danger: #e09393; --danger-bg: #3a2323; --ok: #93c9a8; --ok-bg: #1e3328;
    --warn-bg: #33301e; --warn-border: #c9a44a; --focus: #ffb066;
  }
}

[data-contrast="high"] {
  --text: #000000; --text-muted: #1c2733; --border: #1c2733; --bg: #ffffff; --surface: #ffffff;
}
[data-theme="dark"][data-contrast="high"] {
  --text: #ffffff; --text-muted: #e4ebf1; --border: #e4ebf1; --bg: #000000; --surface: #0a0f14;
}

[data-fontsize="small"]  body { zoom: 0.9; }
[data-fontsize="large"]  body { zoom: 1.15; }
[data-fontsize="xlarge"] body { zoom: 1.35; }

[data-font="hyperlegible"] body, [data-font="hyperlegible"] input, [data-font="hyperlegible"] select, [data-font="hyperlegible"] button, [data-font="hyperlegible"] textarea { font-family: "Atkinson Hyperlegible", system-ui, sans-serif; }
[data-font="lexend"] body, [data-font="lexend"] input, [data-font="lexend"] select, [data-font="lexend"] button, [data-font="lexend"] textarea { font-family: "Lexend", system-ui, sans-serif; }

[data-motion="reduced"] *, [data-motion="reduced"] *::before, [data-motion="reduced"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Calm mode hides countdown chips and softens risk color to neutral. */
[data-calm="on"] .days-chip { display: none; }
[data-calm="on"] .flag-hard { border-color: var(--border); background: var(--surface); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.55;
  min-width: 320px;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--accent-contrast);
  padding: 0.6rem 1rem; z-index: 20; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.app-header { background: var(--surface); border-bottom: 2px solid var(--border); }
.app-header-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0.6rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
}
.app-title { color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.app-title-scope { display: block; font-weight: 400; font-size: 0.78rem; color: var(--text-muted); }

.quick-exit {
  background: var(--danger); color: #ffffff; border: 2px solid var(--danger);
  border-radius: var(--radius); font-weight: 700; font-size: 0.95rem;
  padding: 0.65rem 1rem; min-width: 60px; min-height: 44px; cursor: pointer;
}
[data-theme="dark"] .quick-exit { color: #1c1010; }

/* Right-side header cluster: the always-visible a11y toolbar sits next to
   Quick Exit. Wraps with the header (.app-header-inner already flex-wraps) so
   nothing clips on narrow screens or at large text-zoom. */
.header-controls {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.header-tools {
  display: inline-flex; align-items: center; gap: 0.35rem;
}
/* Theme toggle + text-size stepper. Neutral surface pills so they read as
   chrome, distinct from the red Quick Exit. Each is a ≥44×44 tap target
   (WCAG 2.5.5). */
.header-tool-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 0.4rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-weight: 700; font-size: 1.05rem; line-height: 1; cursor: pointer;
}
.header-tool-btn:hover { background: var(--bg); }
.header-tool-btn:disabled { opacity: 0.4; cursor: default; }
.header-tool-a-dec { font-size: 0.85em; }
.header-tool-a-inc { font-size: 1.1em; }

.app-nav {
  max-width: var(--maxw); margin: 0 auto; padding: 0 0.5rem 0.5rem;
  display: flex; flex-wrap: wrap; gap: 0.25rem;
}
.app-nav a {
  color: var(--accent); text-decoration: none; padding: 0.55rem 0.7rem;
  border-radius: var(--radius); min-height: 44px; display: inline-flex; align-items: center;
  font-size: 0.92rem;
}
.app-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-contrast); }
.app-nav a:hover { text-decoration: underline; }

.view { max-width: var(--maxw); margin: 0 auto; padding: 1rem; }
.view:focus { outline: none; }

.app-footer {
  border-top: 2px solid var(--border); margin-top: 2rem;
  color: var(--text-muted); font-size: 0.85rem;
}
.app-footer p { max-width: var(--maxw); margin: 0 auto; padding: 0.9rem 1rem; }

h1 { font-size: 1.5rem; margin: 0.4rem 0 0.6rem; }
h2 { font-size: 1.2rem; margin: 1.2rem 0 0.5rem; }
a { color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9rem 1rem; margin: 0.7rem 0;
}
.card-note { color: var(--text-muted); font-size: 0.9rem; margin: 0.35rem 0 0; }

.banner {
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  border-radius: var(--radius); padding: 0.7rem 0.9rem; margin: 0.7rem 0; font-size: 0.93rem;
}
.banner-danger { background: var(--danger-bg); border-color: var(--danger); }
.banner-ok { background: var(--ok-bg); border-color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 44px; padding: 0.6rem 1rem;
  background: var(--surface); color: var(--accent);
  border: 2px solid var(--accent); border-radius: var(--radius);
  font-size: 0.95rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); min-height: 60px; }
.btn:hover { filter: brightness(1.08); }

label { display: block; font-weight: 600; margin: 0.7rem 0 0.2rem; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; max-width: 24rem; padding: 0.55rem 0.6rem; font-size: 1rem;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius); min-height: 44px;
}
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0.8rem 0; padding: 0.6rem 0.9rem; }
legend { font-weight: 700; padding: 0 0.3rem; }

.choice-row { display: flex; align-items: flex-start; gap: 0.55rem; padding: 0.45rem 0; }
.choice-row input[type="checkbox"], .choice-row input[type="radio"] {
  width: 1.35rem; height: 1.35rem; min-height: 0; margin-top: 0.15rem; flex: none;
}
.choice-row label { margin: 0; font-weight: 400; }

.figure-pair { display: flex; gap: 1rem; flex-wrap: wrap; margin: 0.8rem 0; }
.figure-box {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 0.7rem 1rem; min-width: 12rem; flex: 1;
}
.figure-box .figure-label { font-size: 0.85rem; color: var(--text-muted); }
.figure-box .figure-value { font-size: 1.45rem; font-weight: 700; }
.figure-delta { font-size: 0.92rem; color: var(--text-muted); }

.flag-hard { border-left: 5px solid var(--danger); }
.flag-soft { border-left: 5px solid var(--warn-border); }

.status-select { max-width: 12rem; }
.doc-done .doc-label { text-decoration: line-through; color: var(--text-muted); }
.status-text { font-weight: 700; font-size: 0.85rem; }
.status-text::before { content: "• "; }

.timeline-item { border-left: 3px solid var(--accent); padding-left: 0.9rem; margin: 0.9rem 0; }
.timeline-date { font-weight: 700; }
.days-chip {
  display: inline-block; background: var(--accent); color: var(--accent-contrast);
  border-radius: 999px; padding: 0.1rem 0.6rem; font-size: 0.8rem; margin-left: 0.4rem;
}

.progress-badge { font-weight: 700; color: var(--ok); }

.welcome-dialog {
  max-width: 34rem; border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 1.2rem 1.4rem;
}
.welcome-dialog::backdrop { background: rgba(10, 20, 30, 0.6); }
.welcome-privacy { background: var(--ok-bg); border-radius: var(--radius); padding: 0.6rem 0.8rem; }
.welcome-actions { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.9rem; }

.src-link { font-size: 0.85rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 480px) {
  .app-header-inner { flex-direction: row; }
  .figure-pair { flex-direction: column; }
}
