/* ROOVI design system: tokens, base, shell layouts and every UI kit component.
   Mobile first (390px), light theme only. Area files in css/areas/ build on these tokens and
   classes and must scope their own selectors with an area prefix.

   Contents
     1  Tokens
     2  Reset and base
     3  Utilities and accessibility helpers
     4  Shell: boot, demo bar, topbar, sidebar, tab bar, main
     5  Components: card, buttons, chips, badges, avatar, forms, tiles, lists, tables, ...
     6  Overlays: dialog, sheet, toast
     7  Feedback: skeleton, spinner, error
     8  Responsive and motion
*/

/* ============================================================
   1  Tokens
   ============================================================ */
:root {
  /* Brand (client palette) */
  --brand: #1C2B2A;
  --brand-raised: #2A3D3B;
  --brand-text: #EAEDE7;
  --brand-muted: #B4C0BB;
  --amber: #B8863B;
  --amber-strong: #96692E;   /* filled amber surfaces with white text (AA) */
  --amber-ink: #7A5420;      /* small amber text on amber tint (AA) */
  --amber-tint: #F7EFE3;
  --amber-border: #E4CB9F;

  /* Stone neutrals */
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --surface-2: #F5F5F4;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --text: #1C1917;
  --text-secondary: #57534E;
  --text-tertiary: #6F6862;  /* darkened from the prototype so it passes AA on every surface */

  /* Green accent */
  --accent: #166534;
  --accent-strong: #14532D;
  --accent-tint: #ECFDF3;
  --accent-border: #BBF7D0;

  /* Semantic */
  --warning-bg: #FEF3C7;
  --warning-border: #FDE68A;
  --warning-text: #92400E;
  --danger: #B91C1C;
  --danger-bg: #FEF2F2;
  --danger-border: #FECACA;
  --info: #1E40AF;
  --info-bg: #EFF6FF;
  --info-border: #BFDBFE;
  --focus: #166534;
  --focus-on-dark: #F2D9A6;

  /* Shape and depth */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(28, 25, 23, 0.05), 0 2px 6px rgba(28, 25, 23, 0.05);
  --shadow-2: 0 2px 4px rgba(28, 25, 23, 0.06), 0 12px 28px -12px rgba(28, 25, 23, 0.18);
  --shadow-3: 0 8px 16px rgba(28, 25, 23, 0.12), 0 24px 48px -16px rgba(28, 25, 23, 0.28);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Layout */
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --sidebar-w: 240px;
  --content-max: 680px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --demo-h: 0px;
  --bar-top: var(--safe-top);

  /* Stacking */
  --z-bar: 20;
  --z-sidebar: 25;
  --z-demo: 30;
  --z-overlay: 100;
  --z-toast: 110;
}

/* ============================================================
   2  Reset and base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
ul, ol { padding: 0; }
img, svg, video { max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 13px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-tint); color: var(--accent-strong); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
[tabindex="-1"]:focus { outline: none; }

.topbar :focus-visible,
.sidebar :focus-visible,
.demo-bar :focus-visible { outline-color: var(--focus-on-dark); }
.demo-bar :focus-visible { outline-color: var(--amber-ink); }

/* ============================================================
   3  Utilities and accessibility helpers
   ============================================================ */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px; left: 8px;
  z-index: calc(var(--z-overlay) + 10);
  padding: 10px 16px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--focus);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-6); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grow { flex: 1 1 0; min-width: 0; }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.center-text { text-align: center; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.card-grid { display: grid; gap: var(--space-3); }

.link { font-size: 14px; font-weight: 600; color: var(--accent-strong); }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ============================================================
   4  Shell
   ============================================================ */
#app { min-height: 100dvh; }

.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.shell-athlete, .shell-focus { --content-max: 680px; }
.shell-tm { --content-max: 760px; }
.shell-staff { --content-max: 1100px; }
.shell-public, .shell-bare { --content-max: 560px; }
.shell.has-demo { --demo-h: calc(40px + var(--safe-top)); --bar-top: 0px; }

/* ----- boot splash and static fallbacks ----- */
.boot {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--brand); color: var(--brand-text);
}
.boot-mark {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
}
.boot-mark svg { display: block; }
.boot-name { font-size: 20px; font-weight: 700; letter-spacing: 0.12em; }
.noscript { max-width: 480px; margin: 40px auto; padding: 0 var(--space-4); }
.boot-error {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
}
.boot-error-card { max-width: 480px; display: flex; flex-direction: column; gap: var(--space-3); }
.brand-mark { display: inline-flex; line-height: 0; }

/* ----- demo bar ----- */
/* --demo-h is the measured height of this bar (set by js/ui/shell.js); the value below is the
   one-line fallback. A second line (long NL text on a phone) just makes the bar taller. */
.demo-bar {
  position: sticky; top: 0;
  z-index: var(--z-demo);
  min-height: 40px;
  padding: calc(var(--safe-top) + 4px) var(--space-3) 4px;
  text-wrap: balance;
  display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  background: var(--amber-tint);
  color: var(--amber-ink);
  border-bottom: 1px solid var(--amber-border);
  font-size: 12px; font-weight: 600;
  text-align: center;
}
.demo-link {
  position: relative;
  display: inline-flex; align-items: center;
  min-height: 32px;
  padding: 0 var(--space-2);
  color: var(--amber-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
}
/* The bar stays slim; the invisible overlay makes the link a 44px touch target. */
.demo-link::after { content: ""; position: absolute; inset: -8px -4px; }

/* ----- top bar (dark brand chrome) ----- */
.topbar {
  position: sticky; top: var(--demo-h);
  z-index: var(--z-bar);
  padding-top: var(--bar-top);
  background: var(--brand);
  color: var(--brand-text);
}
.topbar-inner {
  max-width: calc(var(--content-max) + 2 * var(--space-4));
  margin: 0 auto;
  min-height: var(--topbar-h);
  padding: 0 var(--space-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.topbar-right { display: flex; align-items: center; gap: var(--space-1); }

.wordmark { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); }
.wordmark-name { font-weight: 700; letter-spacing: 0.12em; font-size: 15px; }

/* language toggle: 44px hit areas, 30px visual pill */
.lang-toggle { display: inline-flex; align-items: center; }
.lang-btn {
  position: relative;
  min-width: var(--tap); min-height: var(--tap);
  padding: 0 4px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--brand-muted);
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
}
.lang-btn::before {
  content: ""; position: absolute; inset: 7px 2px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(234, 237, 231, 0.28);
  z-index: -1;
}
.lang-btn { isolation: isolate; }
.lang-btn.is-active { color: var(--brand); }
.lang-btn.is-active::before { background: var(--brand-text); border-color: var(--brand-text); }

/* icon-only buttons (bell, close, ...) */
.icon-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap);
  padding: 0;
  background: transparent; border: 0; border-radius: var(--radius-pill);
  color: inherit; cursor: pointer;
  transition: background 0.15s var(--ease);
}
.icon-btn:hover { background: rgba(120, 113, 108, 0.14); }
.topbar .icon-btn:hover { background: rgba(234, 237, 231, 0.12); }
.icon { display: inline-flex; line-height: 0; }
.bell-badge { position: absolute; top: 6px; right: 4px; line-height: 0; pointer-events: none; }
.bell-badge .badge { box-shadow: 0 0 0 2px var(--brand); }
.avatar-link { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); border-radius: var(--radius-pill); }

/* ----- sidebar (staff, wide screens) ----- */
.sidebar {
  display: none;
  position: fixed;
  top: var(--demo-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  z-index: var(--z-sidebar);
  padding: 0 var(--space-3) var(--space-4);
  background: var(--brand);
  color: var(--brand-text);
  flex-direction: column; gap: var(--space-3);
  overflow-y: auto;
}
.sidebar .wordmark { min-height: var(--topbar-h); padding: 0 var(--space-3); }
.sidebar-list, .sidebar-sub { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.sidebar-list { flex: 1; }
.sidebar-sub { margin: 2px 0 6px 14px; padding-left: 10px; border-left: 1px solid rgba(234, 237, 231, 0.18); }
.side-link {
  width: 100%;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: var(--brand-muted);
  font-size: 15px; font-weight: 600; text-align: left; cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.side-link:hover { background: rgba(234, 237, 231, 0.08); color: var(--brand-text); }
.side-link.is-active { background: rgba(234, 237, 231, 0.14); color: var(--brand-text); box-shadow: inset 3px 0 0 var(--amber); }
.side-sub { font-size: 14px; min-height: 40px; }
.sidebar-foot { border-top: 1px solid rgba(234, 237, 231, 0.18); padding-top: var(--space-3); }

/* ----- tab bar ----- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: var(--z-bar);
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar-list {
  list-style: none;
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex;
}
/* each tab takes the width its label needs first ("Herinneringen" in Dutch), then shares the rest */
.tabbar-list > li { flex: 1 1 auto; min-width: 0; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px;
  padding: 6px 2px;
  color: var(--text-tertiary);
  font-size: 11px; font-weight: 600; text-align: center;
  transition: color 0.15s var(--ease);
}
.tab .nav-icon {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 30px;
  border-radius: var(--radius-pill);
  transition: background 0.15s var(--ease);
}
.tab.is-active { color: var(--accent-strong); }
.tab.is-active .nav-icon { background: var(--accent-tint); }
.tab-badge-holder { position: absolute; top: -2px; right: 6px; line-height: 0; }
.nav-label { overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.side-link .nav-icon { display: inline-flex; position: relative; }

/* ----- main outlet ----- */
.main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--content-max) + 2 * var(--space-4));
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-8);
}
.shell-athlete .main, .shell-tm .main, .shell-staff .main {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--space-6));
}
.shell-bare .main, .shell-public .main { padding-top: var(--space-6); }
.view { min-width: 0; }

/* ============================================================
   5  Components
   ============================================================ */

/* ----- page header and sections ----- */
.page-header { margin: 4px 0 var(--space-4); }
.page-header-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.page-title { font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { margin-top: 6px; color: var(--text-secondary); font-size: 15px; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap);
  margin-bottom: 2px;
  font-size: 14px; font-weight: 600; color: var(--text-secondary);
}
.back-link:hover { color: var(--text); }

.section { margin: var(--space-6) 0 0; }
.section:first-child { margin-top: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: 10px; }
.section-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.section-actions { display: flex; gap: var(--space-2); }
.section-collapsible > summary { list-style: none; cursor: pointer; min-height: var(--tap); margin-bottom: 0; }
.section-collapsible > summary::-webkit-details-marker { display: none; }
.section-chevron { display: inline-flex; color: var(--text-tertiary); transition: transform 0.2s var(--ease); }
.section-collapsible[open] > summary .section-chevron { transform: rotate(180deg); }
.section-body { padding-top: var(--space-2); }

/* ----- cards ----- */
a.card { display: block; }
.card {
  min-width: 0;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  overflow-wrap: anywhere;
}
.card + .card { margin-top: var(--space-3); }
.card-title { margin-bottom: 10px; font-size: 16px; font-weight: 700; }
.card-flat { box-shadow: none; }
.card-accent { background: var(--accent-tint); border-color: var(--accent-border); }
.card-amber { background: var(--amber-tint); border-color: var(--amber-border); }
.card-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.card-emergency { background: var(--danger-bg); border-color: var(--danger-border); border-left: 4px solid var(--danger); }
.card-error { text-align: center; border-color: var(--danger-border); background: var(--danger-bg); }
.card-interactive { transition: box-shadow 0.15s var(--ease), transform 0.1s var(--ease), border-color 0.15s var(--ease); cursor: pointer; }
.card-interactive:hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.card-interactive:active { transform: scale(0.99); }

/* ----- buttons ----- */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap);
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; line-height: 1.2; text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.1s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: default; pointer-events: none; }
.btn-label { min-width: 0; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.14), 0 1px 2px rgba(28, 25, 23, 0.12); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-amber { background: var(--amber-strong); color: #fff; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16), 0 1px 2px rgba(28, 25, 23, 0.12); }
.btn-amber:hover { background: var(--amber-ink); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8); }
.btn-secondary:hover { border-color: var(--text-tertiary); }
.btn-ghost { background: transparent; color: var(--accent-strong); }
.btn-ghost:hover { background: var(--accent-tint); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 14px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading > * { opacity: 0; }
.btn.is-loading::after {
  content: ""; position: absolute;
  width: 18px; height: 18px;
  border: 2px solid #fff; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after, .btn-danger.is-loading::after { border-color: var(--text-secondary); border-right-color: transparent; }

/* ----- chips, badges, avatar ----- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12px; font-weight: 700; letter-spacing: 0.01em; line-height: 1.4;
  white-space: nowrap;
}
.chip-green { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent-strong); }
.chip-amber { background: var(--amber-tint); border-color: var(--amber-border); color: var(--amber-ink); }
.chip-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.chip-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.chip-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
.status-todo { background: var(--surface-2); color: var(--text-secondary); }
.status-inprogress { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent-strong); }
.status-waiting { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.status-completed { background: var(--accent); border-color: var(--accent); color: #fff; }
.status-blocked { background: var(--surface); border-style: dashed; color: var(--text-secondary); }
.chip-class { background: var(--surface); }
.class-with-note { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.class-note { font-size: 13px; color: var(--text-secondary); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.badge-accent { background: var(--accent); color: #fff; }
.badge-amber { background: var(--amber-strong); color: #fff; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-neutral { background: var(--text-secondary); color: #fff; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  border-radius: 50%;
  font-weight: 700; letter-spacing: 0.02em;
  user-select: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: 14px; }
.avatar-lg { width: 56px; height: 56px; font-size: 19px; }
.avatar-t0 { background: #DDE9E3; color: #14392B; }
.avatar-t1 { background: #F3E4C8; color: #5E4012; }
.avatar-t2 { background: #E1E4F0; color: #26306B; }
.avatar-t3 { background: #F0DDE0; color: #5C1F2B; }
.avatar-t4 { background: #E5E0F0; color: #3F2A6B; }
.avatar-t5 { background: #E4E2DC; color: #38342B; }

/* ----- forms ----- */
.field { margin-bottom: var(--space-4); min-width: 0; border: 0; padding: 0; }
.label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 700; color: var(--text); padding: 0; }
.req { color: var(--danger); }
.optional { font-weight: 500; color: var(--text-secondary); }
.helper { margin-top: 6px; font-size: 13px; line-height: 1.45; color: var(--text-secondary); }
.field-error { margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--danger); }

.input {
  display: block;
  width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS from zooming on focus */
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input::placeholder { color: var(--text-tertiary); }
.input:hover { border-color: var(--text-tertiary); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint), 0 0 0 4px var(--accent); }
.input:disabled { background: var(--surface-2); color: var(--text-secondary); cursor: not-allowed; }
.input-invalid, .input[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2357534E' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 20px;
}
.input-compact { width: auto; min-height: 36px; padding: 6px 10px; font-size: 14px; }

.choices { display: flex; flex-direction: column; gap: var(--space-2); }
.radio-inline .choices { flex-direction: row; flex-wrap: wrap; }
.choice {
  display: flex; align-items: flex-start; gap: var(--space-3);
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.choice:hover { border-color: var(--text-tertiary); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.choice:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.choice-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice-label { font-size: 15px; line-height: 1.35; }
.choice-help { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.choice-check { align-items: center; }
.checklist { display: grid; gap: var(--space-2); }

.switch { position: relative; display: flex; align-items: center; gap: var(--space-3); min-height: var(--tap); cursor: pointer; }
.switch input { position: absolute; left: 0; top: 50%; width: 46px; height: 28px; margin: -14px 0 0; opacity: 0; cursor: pointer; }
.switch-track {
  position: relative; flex: none;
  width: 46px; height: 28px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background 0.2s var(--ease);
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(28, 25, 23, 0.3);
  transition: transform 0.2s var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch-body { display: flex; flex-direction: column; min-width: 0; }
.switch-label { font-size: 15px; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.segment {
  min-height: var(--tap); padding: 0 18px;
  border: 0; background: transparent;
  font-size: 14px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.segment.active, .segment.is-active, .segment[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ----- stepper and progress ring ----- */
.stepper { margin-bottom: var(--space-5); }
.stepper-track { height: 6px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; }
.stepper-fill { height: 100%; background: var(--accent); border-radius: var(--radius-pill); transition: width 0.3s var(--ease); }
.stepper-label { display: block; margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }

.ring { position: relative; display: inline-block; flex: none; }
.ring svg { display: block; }
.ring-track { stroke: var(--border); }
.ring-value { stroke: var(--accent); transition: stroke-dashoffset 0.6s var(--ease); }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ring-number { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.ring-sub { margin-top: 2px; font-size: 11px; font-weight: 600; color: var(--text-secondary); }

/* ----- module tiles ----- */
.tile {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0; min-height: 96px;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.15s var(--ease), transform 0.1s var(--ease), border-color 0.15s var(--ease);
}
.tile:hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.tile:active { transform: scale(0.98); }
.tile-icon {
  width: 36px; height: 36px; margin-bottom: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--amber-tint); color: var(--amber-ink);
  border-radius: var(--radius-sm);
}
.tile-name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; overflow-wrap: anywhere; }
.tile-count { font-size: 13px; font-weight: 700; color: var(--amber-ink); font-variant-numeric: tabular-nums; }
.tile-done .tile-count { color: var(--accent-strong); }
.tile-summary { margin-top: 4px; font-size: 13px; line-height: 1.4; color: var(--text-secondary); }

/* ----- countdown ----- */
.countdown { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.countdown-ok { color: var(--text-secondary); }
.countdown-soon { color: var(--warning-text); }
.countdown-overdue { color: var(--danger); font-weight: 700; }
/* SPEC 19.2: a ROOVI advice date is neutral, also after the date (never red, never "overdue") */
.countdown-advice { color: var(--text-secondary); font-weight: 500; }

/* ----- lists ----- */
.list { list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.list-item { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); transition: box-shadow 0.15s var(--ease), border-color 0.15s var(--ease); }
.list-item:has(a.list-item-link:hover), .list-item:has(button.list-item-link:hover) { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.list-item-link, .list-item-static {
  width: 100%; min-height: 56px;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) 14px;
  background: transparent; border: 0; border-radius: var(--radius);
  text-align: left; cursor: default;
}
a.list-item-link, button.list-item-link { cursor: pointer; }
.list-item-lead { display: inline-flex; flex: none; }
.list-item-body { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.list-item-title { font-weight: 600; font-size: 15px; }
.list-item-sub { font-size: 14px; color: var(--text-secondary); }
.list-item-meta { font-size: 13px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.list-item-trail { display: inline-flex; flex: none; align-items: center; gap: var(--space-2); }
.list-item-chevron { display: inline-flex; flex: none; color: var(--text-tertiary); }

.empty { padding: var(--space-8) var(--space-5); text-align: center; color: var(--text-secondary); font-size: 15px; }
.empty-icon { display: inline-flex; margin-bottom: var(--space-2); color: var(--text-tertiary); }
.empty-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.empty-action { margin-top: var(--space-4); }

/* ----- banner ----- */
.banner { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid; border-radius: var(--radius); font-size: 14px; }
.banner-icon { display: inline-flex; flex: none; margin-top: 1px; }
.banner-body { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.banner-title { font-weight: 700; }
.banner-text { margin-top: 2px; }
.banner-action { flex: none; }
.banner-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
.banner-success { background: var(--accent-tint); border-color: var(--accent-border); color: var(--accent-strong); }
.banner-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.banner-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.banner-amber { background: var(--amber-tint); border-color: var(--amber-border); color: var(--amber-ink); }

/* ----- key/value, timeline ----- */
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv dt { flex: none; max-width: 45%; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.kv dd { min-width: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.kv-empty { color: var(--text-tertiary); font-weight: 500; }

.timeline { list-style: none; position: relative; display: flex; flex-direction: column; gap: var(--space-4); padding-left: 4px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; display: flex; gap: var(--space-3); }
.timeline-dot {
  position: relative; z-index: 1; flex: none;
  width: 12px; height: 12px; margin: 4px 0 0 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--text-tertiary); color: #fff;
}
.timeline-item.timeline-done .timeline-dot, .timeline-item.timeline-success .timeline-dot { background: var(--accent); border-color: var(--accent); }
.timeline-item.timeline-warning .timeline-dot { border-color: var(--warning-text); }
.timeline-item.timeline-danger .timeline-dot { border-color: var(--danger); }
.timeline-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.timeline-date { font-size: 12px; font-weight: 700; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.timeline-title { font-weight: 600; font-size: 15px; }
.timeline-text { font-size: 14px; color: var(--text-secondary); }

/* ----- table (stacks into cards on phones) ----- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table-link { display: inline-block; padding: 12px 0; margin: -12px 0; font-weight: 600; color: var(--accent-strong); }
.table-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ----- tabs ----- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px;
  margin-bottom: -1px;
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  font-size: 14px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; cursor: pointer;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab-panel { padding-top: var(--space-4); }

/* ----- share row, markdown ----- */
.share-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.md { font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.md > * + * { margin-top: 0.7em; }
.md ul, .md ol { padding-left: 1.3em; }
.md li + li { margin-top: 0.25em; }
.md a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
.md code { padding: 1px 5px; background: var(--surface-2); border-radius: 4px; font-family: var(--mono); font-size: 0.9em; }
.md-heading { margin-top: 1em; }

/* ============================================================
   6  Overlays
   ============================================================ */
.overlay {
  position: fixed; inset: 0;
  z-index: var(--z-overlay);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  background: rgba(28, 25, 23, 0.55);
  animation: fade-in 0.15s var(--ease);
}
.overlay-sheet { align-items: flex-end; padding: 0; }
.dialog {
  width: min(100%, 520px);
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  animation: pop-in 0.18s var(--ease);
}
.dialog-sm { width: min(100%, 400px); }
.dialog-lg { width: min(100%, 720px); }
.dialog-sheet { width: 100%; max-height: 90dvh; padding-bottom: var(--safe-bottom); border-radius: 20px 20px 0 0; animation: slide-up 0.22s var(--ease); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-3) 0 var(--space-4); }
.dialog-title { padding-top: 10px; font-size: 18px; font-weight: 700; line-height: 1.25; }
.dialog-body { padding: var(--space-3) var(--space-4); overflow-y: auto; overflow-wrap: anywhere; }
.dialog-message { color: var(--text-secondary); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4) var(--space-4); }
.dialog-actions .btn { flex: 1 1 140px; }

.toast-region {
  position: fixed; left: var(--space-3); right: var(--space-3);
  bottom: calc(var(--safe-bottom) + var(--space-4));
  z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  pointer-events: none;
}
body:has(.tabbar) .toast-region { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--space-3)); }
.toast {
  pointer-events: auto;
  width: 100%; max-width: 520px;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 4px 6px var(--space-3);
  background: var(--brand); color: var(--brand-text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  animation: toast-in 0.2s var(--ease);
}
.toast-icon { display: inline-flex; flex: none; }
.toast-success .toast-icon { color: #86EFAC; }
.toast-warning .toast-icon { color: #FCD34D; }
.toast-error .toast-icon { color: #FCA5A5; }
.toast-text { flex: 1 1 0; min-width: 0; font-size: 14px; line-height: 1.4; padding: 6px 0; overflow-wrap: anywhere; }
.toast .icon-btn:hover { background: rgba(234, 237, 231, 0.14); }
.toast .btn-ghost { color: var(--focus-on-dark); }
.toast .btn-ghost:hover { background: rgba(234, 237, 231, 0.12); }
.toast :focus-visible { outline-color: var(--focus-on-dark); }

/* ============================================================
   7  Feedback
   ============================================================ */
.skeleton-wrap { padding: var(--space-1) 0; }
.skeleton {
  display: block;
  background: linear-gradient(90deg, #ECEAE8 25%, #F5F4F3 37%, #ECEAE8 63%);
  background-size: 400% 100%;
  border-radius: 6px;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-title { width: 55%; height: 28px; margin: 6px 0 var(--space-4); }
.skeleton-card { padding: var(--space-4); margin-bottom: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.skeleton-line { width: 100%; height: 14px; margin: 8px 0; }
.skeleton-line-short { width: 60%; }

.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.error-card { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-6) var(--space-4); }
.error-icon { display: inline-flex; color: var(--danger); }
.error-title { font-size: 18px; font-weight: 700; }
.error-text { color: var(--text-secondary); max-width: 38ch; }
.error-detail { max-width: 100%; margin-bottom: var(--space-2); text-align: left; font-size: 13px; color: var(--text-secondary); }
.error-detail summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============================================================
   8  Responsive and motion
   ============================================================ */

/* Touch targets stay 44px on touch screens; mouse users get denser small buttons. */
@media (pointer: fine) {
  .btn-sm { min-height: 36px; }
  .input-compact { min-height: 32px; }
}

/* Tables become stacked cards on phones: no horizontal scroll at 390px. */
@media (max-width: 639px) {
  .table-wrap { overflow: visible; background: transparent; border: 0; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .table tr { margin-bottom: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden; }
  .table td { display: flex; justify-content: space-between; gap: var(--space-4); padding: 10px 14px; text-align: right; }
  .table td::before { content: attr(data-label); flex: none; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); text-align: left; }
  .table td:not([data-label])::before { content: none; }
  .table tbody tr:hover td { background: transparent; }
}

@media (min-width: 640px) {
  .card { padding: var(--space-5); }
  .overlay-sheet { align-items: center; padding: var(--space-4); }
  .dialog-sheet { width: min(100%, 520px); border-radius: var(--radius-lg); padding-bottom: 0; animation: pop-in 0.18s var(--ease); }
  .tile-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .card-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-title { font-size: 30px; }
}

/* Staff and admin: left sidebar on wide screens, bottom tab bar on phones. */
@media (min-width: 960px) {
  .shell-staff { padding-left: var(--sidebar-w); }
  .shell-staff .demo-bar { margin-left: calc(-1 * var(--sidebar-w)); width: calc(100% + var(--sidebar-w)); }
  .shell-staff .sidebar { display: flex; }
  .shell-staff .tabbar { display: none; }
  .shell-staff .topbar .wordmark { display: none; }
  .shell-staff .topbar-inner { justify-content: flex-end; }
  .shell-staff .main { padding-top: var(--space-6); padding-bottom: var(--space-8); }
  body:has(.shell-staff) .toast-region { bottom: var(--space-6); }
  .tabbar-list { padding: 0 var(--space-4); }
}

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

@media (forced-colors: active) {
  .switch-track { border: 1px solid CanvasText; }
  .ring-value { stroke: Highlight; }
  .btn { border: 1px solid ButtonText; }
}
