/* PlanToEndure components. Every colour, size, space, radius and shadow comes from the token
   layer (styles.css) or the brand file; this sheet only maps them onto two themes. */
:root, [data-theme="light"] {
  --font-display: var(--brand-font-heading);
  --font-body: var(--brand-font-body);
  --hair: 0.0625rem;
  --bg: var(--brand-background);
  --surface: var(--white);
  --surface-2: color-mix(in srgb, var(--brand-background) 60%, var(--white));
  --ink: var(--brand-text);
  --ink-head: var(--brand-heading);
  --ink-muted: var(--slate-700);
  --line: color-mix(in srgb, var(--brand-primary) 20%, transparent);
  --btn-bg: var(--brand-button-background);
  --btn-ink: var(--brand-button-text);
  --link: var(--blue-700);
  --key-bg: var(--lavender-100);
  --key-ink: var(--violet-600);
  --warn-bg: var(--lavender-50);
  --warn-ink: var(--purple-600);
  --feature-bg: var(--brand-primary);
  --feature-ink: var(--brand-background);
  --bar: var(--brand-primary);
  --bar-2: var(--violet-600);
  --nav-bg: var(--brand-header-background);
  --nav-ink: var(--brand-header-text);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: var(--brand-accent);
  --surface: var(--brand-primary);
  --surface-2: color-mix(in srgb, var(--brand-primary) 55%, var(--brand-accent));
  --ink: var(--brand-background);
  --ink-head: var(--brand-background);
  --ink-muted: var(--slate-200);
  --line: color-mix(in srgb, var(--brand-background) 22%, transparent);
  --btn-bg: var(--brand-background);
  --btn-ink: var(--brand-primary);
  --link: var(--blue-300);
  --key-bg: var(--violet-600);
  --key-ink: var(--white);
  --warn-bg: var(--purple-600);
  --warn-ink: var(--white);
  --feature-bg: var(--blue-800);
  --feature-ink: var(--brand-background);
  --bar: var(--blue-300);
  --bar-2: var(--violet-400);
  --nav-bg: var(--brand-accent);
  --nav-ink: var(--brand-background);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: var(--text-body-md); line-height: var(--line-height-normal); overflow-x: hidden; }
h1, h2, h3 { font-family: var(--font-display); color: var(--ink-head); line-height: var(--line-height-tight); letter-spacing: var(--letter-spacing-tight); margin: 0 0 var(--space-3); }
h1 { font-size: clamp(2rem, 6vw, var(--text-display-2)); }
h2 { font-size: clamp(1.4rem, 4vw, var(--text-display-3)); }
h3 { font-size: var(--text-body-lg); }
p { margin: 0 0 var(--space-3); }
a { color: var(--link); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 0.15em; }
:focus-visible { outline: 0.1875rem solid var(--link); outline-offset: 0.125rem; border-radius: var(--radius-sm); }
.icon { width: 1.25rem; height: 1.25rem; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-muted); }
.small { font-size: var(--text-body-sm); }
.tiny { font-size: var(--text-caption); }
.num { font-variant-numeric: tabular-nums; }
.price { white-space: nowrap; font-variant-numeric: tabular-nums; }
.wrap { max-width: var(--content-max-width); margin: 0 auto; padding: 0 var(--space-4); }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.spacer { flex: 1; }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.grid-3 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 2.75rem; padding: var(--space-2) var(--space-5); border-radius: var(--radius-pill); border: var(--hair) solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold); cursor: pointer; text-decoration: none; transition: transform var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard); }
.btn:hover { transform: var(--hover-lift); box-shadow: var(--shadow-card); }
.btn:active { transform: var(--press-scale); }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--btn-bg); color: var(--btn-ink); border-color: var(--btn-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink); }
.btn-sm { min-height: 2.75rem; padding: var(--space-1) var(--space-4); }
.btn-block { width: 100%; }

/* Surfaces */
.card { background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-card); min-width: 0; }
.card-flat { box-shadow: none; }
.feature { background: var(--feature-bg); color: var(--feature-ink); border-color: transparent; }
.feature h2, .feature h3, .feature .muted { color: var(--feature-ink); }
.chip { display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill); font-size: var(--text-caption); font-weight: var(--font-weight-semibold); background: var(--surface-2); color: var(--ink); border: var(--hair) solid var(--line); white-space: nowrap; }
.chip-key { background: var(--key-bg); color: var(--key-ink); border-color: transparent; }
.chip-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.chip-on-feature { background: var(--brand-background); color: var(--brand-primary); border-color: transparent; }
.notice { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--warn-bg); color: var(--warn-ink); font-size: var(--text-body-sm); }
.notice-plain { background: var(--surface-2); color: var(--ink); }

/* Forms */
label { font-weight: var(--font-weight-semibold); font-size: var(--text-body-sm); }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); min-height: 2.75rem; width: 100%; }
textarea { min-height: 10rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.25rem; height: 1.25rem; min-height: 0; accent-color: var(--btn-bg); }
.check { display: flex; align-items: center; gap: var(--space-3); min-height: 2.75rem; font-weight: var(--font-weight-medium); }
.err { color: var(--warn-ink); font-size: var(--text-caption); min-height: 1em; }
[aria-invalid="true"] { border-color: var(--warn-ink); }
.error-summary { border: var(--hair) solid var(--warn-ink); }

/* Public shell */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--nav-bg); color: var(--nav-ink); border-bottom: var(--hair) solid var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: var(--space-3); min-height: 4rem; }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); text-decoration: none; color: inherit; font-family: var(--font-display); font-weight: var(--font-weight-bold); }
.brand img { height: 2rem; width: auto; }
.topnav { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.topnav a { color: var(--nav-ink); text-decoration: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius-pill); font-size: var(--text-body-sm); min-height: 2.75rem; display: inline-flex; align-items: center; }
.topnav a:hover, .topnav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); }
.hero { position: relative; color: var(--brand-background); background-image: linear-gradient(100deg, color-mix(in srgb, var(--brand-accent) 92%, transparent) 0%, color-mix(in srgb, var(--brand-accent) 70%, transparent) 60%, color-mix(in srgb, var(--brand-accent) 45%, transparent) 100%), url('/assets/stock-1.jpg'); background-size: cover; background-position: center; }
.hero .wrap { padding-top: var(--space-20); padding-bottom: var(--space-20); }
.hero h1 { color: var(--brand-background); font-size: clamp(3rem, 8vw, var(--text-display-1)); line-height: var(--line-height-tight); max-width: 16ch; }
.hero p { font-size: var(--text-body-lg); max-width: 38rem; color: var(--brand-background); }
.hero .btn-primary { background: var(--brand-background); color: var(--brand-primary); border-color: var(--brand-background); }
.hero .btn { background: transparent; color: var(--brand-background); border-color: var(--brand-background); }
.hero .btn.btn-primary { background: var(--brand-background); color: var(--brand-primary); }
.section { padding: var(--space-16) 0; }
.section-alt { background: var(--surface-2); }
.section-head { max-width: 44rem; margin-bottom: var(--space-8); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: var(--text-caption); font-weight: var(--font-weight-bold); color: var(--ink-muted); }
.photo { width: 100%; height: 100%; min-height: 14rem; object-fit: cover; border-radius: var(--radius-lg); display: block; }
.step-num { display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: var(--radius-pill); background: var(--btn-bg); color: var(--btn-ink); font-weight: var(--font-weight-bold); }
.price-card { display: grid; grid-template-rows: auto auto 1fr auto; gap: var(--space-3); height: 100%; }
.price-amount { font-family: var(--font-display); font-size: var(--text-display-3); font-weight: var(--font-weight-bold); line-height: var(--line-height-tight); }
.price-list { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-1); font-size: var(--text-body-sm); }
.footer { background: var(--brand-accent); color: var(--brand-background); padding: var(--space-12) 0 var(--space-8); }
.footer a { color: var(--brand-background); }
.footer .muted { color: var(--brand-background); opacity: 0.9; }

/* App shell */
.app-main { padding: var(--space-6) 0 calc(var(--space-20) + var(--space-4)); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin-bottom: var(--space-5); }
.page-head h1 { margin: 0; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: none; background: var(--nav-bg); border-top: var(--hair) solid var(--line); padding: var(--space-1) var(--space-1) calc(var(--space-1) + env(safe-area-inset-bottom)); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--space-1); min-height: 3.25rem; padding: var(--space-1); font-size: var(--text-caption); color: var(--nav-ink); text-decoration: none; border-radius: var(--radius-sm); }
.tabbar a { min-width: 0; }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar a[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: var(--font-weight-bold); }
@media (max-width: 760px) {
  .tabbar { display: flex; }
  .topnav.app-nav { display: none; }
  .hero .wrap { padding-top: var(--space-12); padding-bottom: var(--space-12); }
  .section { padding: var(--space-12) 0; }
  .card { padding: var(--space-4); }
}

/* My Week */
.stat { display: flex; flex-direction: column; gap: var(--space-1); }
.stat-value { font-family: var(--font-display); font-size: var(--text-display-3); font-weight: var(--font-weight-bold); line-height: var(--line-height-tight); font-variant-numeric: tabular-nums; }
.meter { height: 0.625rem; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; border: var(--hair) solid var(--line); }
.meter > span { display: block; height: 100%; background: var(--bar); border-radius: var(--radius-pill); }
.meter.over > span { background: var(--bar-2); }
.daybars { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--space-2); align-items: end; height: 7rem; }
.daybars .bar { background: var(--bar); border-radius: var(--radius-sm) var(--radius-sm) 0 0; min-height: 0.25rem; }
.daybars .today { background: var(--bar-2); }
.daylabels { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--space-2); text-align: center; }
.session { display: flex; flex-direction: column; gap: var(--space-2); }
.session-top { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.sport { display: inline-grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: var(--radius-md); background: var(--surface-2); color: var(--ink); flex: none; }
.sport.key { background: var(--key-bg); color: var(--key-ink); }
.session-title { font-weight: var(--font-weight-bold); overflow-wrap: anywhere; }
.list { display: grid; gap: var(--space-3); }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2); }
.cal-day { background: var(--surface); border: var(--hair) solid var(--line); border-radius: var(--radius-md); padding: var(--space-2); min-height: 12rem; display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.cal-day.drop { outline: 0.1875rem dashed var(--link); }
.cal-day h3 { font-size: var(--text-body-sm); margin: 0; }
.cal-ev { border-radius: var(--radius-sm); padding: var(--space-2); font-size: var(--text-caption); background: var(--surface-2); border: var(--hair) solid var(--line); cursor: grab; overflow-wrap: anywhere; }
.cal-ev.draft { border-style: dashed; }
.cal-ev.key { background: var(--key-bg); color: var(--key-ink); }
.cal-block { border-radius: var(--radius-sm); padding: var(--space-1) var(--space-2); font-size: var(--text-caption); background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 0.375rem, var(--surface) 0.375rem, var(--surface) 0.75rem); color: var(--ink-muted); border: var(--hair) solid var(--line); }
@media (max-width: 900px) { .cal { grid-template-columns: 1fr; } .cal-day { min-height: 0; } }

/* Effort dial (check-in) */
.effort { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-2); }
.effort button, .seg button { min-height: 2.75rem; border-radius: var(--radius-md); border: var(--hair) solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: var(--font-weight-bold); cursor: pointer; }
.effort button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-ink); border-color: var(--btn-bg); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }

/* Tables */
.table-wrap { overflow-x: auto; border: var(--hair) solid var(--line); border-radius: var(--radius-md); background: var(--surface); max-height: 70vh; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-body-sm); }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: var(--hair) solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--ink); z-index: 1; white-space: nowrap; }
th button { background: none; border: 0; font: inherit; font-weight: var(--font-weight-bold); color: inherit; cursor: pointer; min-height: 2.75rem; padding: 0; }
.pager { display: flex; align-items: center; gap: var(--space-2); justify-content: flex-end; padding: var(--space-2); }

/* States */
.skeleton { height: 3.5rem; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .btn:hover { transform: none; } }
.empty { text-align: center; padding: var(--space-8) var(--space-4); }

/* Toast and dialog */
.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(var(--space-20) + var(--space-2)); display: grid; gap: var(--space-2); width: min(92vw, 28rem); }
.toast { background: var(--feature-bg); color: var(--feature-ink); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); box-shadow: var(--shadow-card-hover); font-size: var(--text-body-sm); }
.toast.error { background: var(--warn-bg); color: var(--warn-ink); border: var(--hair) solid var(--warn-ink); }
dialog { border: var(--hair) solid var(--line); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); padding: var(--space-6); width: min(94vw, 32rem); box-shadow: var(--shadow-card-hover); }
dialog::backdrop { background: color-mix(in srgb, var(--brand-accent) 60%, transparent); }

/* Admin console */
.admin-shell { display: grid; grid-template-columns: 16rem minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--brand-accent); color: var(--brand-background); padding: var(--space-5) var(--space-3); display: flex; flex-direction: column; gap: var(--space-1); position: sticky; top: 0; height: 100vh; }
.sidebar a { color: var(--brand-background); text-decoration: none; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); min-height: 2.75rem; font-size: var(--text-body-sm); }
.sidebar a[aria-current="page"], .sidebar a:hover { background: var(--brand-primary); }
.sidebar .brand-row { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-3) var(--space-4); font-family: var(--font-display); font-weight: var(--font-weight-bold); }
.sidebar .logo-chip { background: var(--brand-background); border-radius: var(--radius-sm); padding: var(--space-1); display: inline-flex; }
.sidebar .logo-chip img { height: 1.75rem; }
.admin-top { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: var(--hair) solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.admin-main { padding: var(--space-5); min-width: 0; }
.kpis { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .c-planned { fill: var(--surface-2); stroke: var(--line); }
.chart .c-done { fill: var(--bar); }
.chart text { fill: var(--ink-muted); font-size: 0.6rem; }
@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: var(--space-2); }
  .sidebar .brand-row { width: 100%; padding-bottom: var(--space-2); }
  .admin-main { padding: var(--space-3); }
}
