/* ════════════════════════════════════════════════════════════════
   theme.css — single source for the Light / Dark theme.
   Loaded by every user-facing page alongside theme.js. The light
   palette mirrors the variable names already used in the codebase
   (--bg / --card / --black / --muted / --border / --red) so every
   page that already references those vars adapts automatically.
   ──────────────────────────────────────────────────────────────── */

:root {
  --bg:      #fafafa;
  --card:    #ffffff;
  --black:   #0a0a0a;          /* primary text — keeps the legacy name */
  --muted:   #8e8e93;
  --border:  rgba(0, 0, 0, 0.08);
  --red:     #ff3b30;
  --accent:  #ff3b30;
  color-scheme: light;
}

/* Dark palette — applied as `<html data-theme="dark">`. */
:root[data-theme="dark"] {
  --bg:      #0a0a0b;
  --card:    #161618;
  --black:   #ededee;
  --muted:   #9b9ba1;
  --border:  rgba(255, 255, 255, 0.08);
  --red:     #ff453a;
  --accent:  #ff453a;
  color-scheme: dark;
}

/* Top-level swap. Use color-only transitions (cheap, GPU-friendly)
   so the page doesn't trigger heavy layout work on theme toggle. */
html, body {
  background-color: var(--bg);
  color: var(--black);
  transition:
    background-color 0.35s ease,
    color 0.35s ease;
}
*, *::before, *::after {
  transition:
    background-color 0.35s ease,
    color 0.35s ease,
    border-color 0.35s ease;
}

/* Dark-mode form inputs — pages mostly hard-code `background:#fff`
   on inputs, which fights the dark surface. Override the common
   form controls so they inherit the card colour. */
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select {
  background-color: var(--card);
  color: var(--black);
  border-color: var(--border);
}
:root[data-theme="dark"] ::placeholder { color: var(--muted); opacity: 0.7; }

/* Dim photos / illustrations slightly so they don't blare against
   the dark surface. Logos / icons keep full opacity. */
:root[data-theme="dark"] img:not([data-theme-keep]) { opacity: 0.92; }

/* ── Dark-mode hard overrides ─────────────────────────────────────
   Many pages hardcode `background:#fff` / `background:#f5f5f7` on
   their <html>, <body>, headers, and cards inside per-page inline
   <style> blocks. Re-stating the dark variables here with
   !important is the only way to actually flip those surfaces
   without rewriting every page's inline CSS. Light mode is left
   completely untouched. */
:root[data-theme="dark"] html,
:root[data-theme="dark"] body {
  background-color: var(--bg) !important;
  color:            var(--black) !important;
}

:root[data-theme="dark"] header,
:root[data-theme="dark"] footer,
:root[data-theme="dark"] main,
:root[data-theme="dark"] section {
  background-color: transparent;
  color: var(--black);
}

/* Card-shaped surfaces — covers .card, every *-card class
   (profile-card, stat-card, msg-card …), the various sheets, and
   common dashboard panels. */
:root[data-theme="dark"] .card,
:root[data-theme="dark"] [class*="-card"],
:root[data-theme="dark"] [class$="card"],
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .form-card,
:root[data-theme="dark"] .modal-sheet,
:root[data-theme="dark"] .modal-content,
:root[data-theme="dark"] .builder-sheet,
:root[data-theme="dark"] .coach-profile-sheet,
:root[data-theme="dark"] .more-sheet,
:root[data-theme="dark"] .today-plan,
:root[data-theme="dark"] .today-plan-empty,
:root[data-theme="dark"] .planner-day,
:root[data-theme="dark"] .planner-cal,
:root[data-theme="dark"] .filters,
:root[data-theme="dark"] .coll,
:root[data-theme="dark"] .counter,
:root[data-theme="dark"] .stat-card,
:root[data-theme="dark"] .profile-hero,
:root[data-theme="dark"] .coach-identity,
:root[data-theme="dark"] .current-class,
:root[data-theme="dark"] .builder-section,
:root[data-theme="dark"] .cp-section {
  background-color: var(--card) !important;
  color:            var(--black) !important;
  border-color:     var(--border) !important;
}

/* Sticky frosted bars — preserve the blur but swap the tint so
   they don't read as white on dark. */
:root[data-theme="dark"] header,
:root[data-theme="dark"] .app-header,
:root[data-theme="dark"] .app-topbar,
:root[data-theme="dark"] .bottom-bar,
:root[data-theme="dark"] .bottom-nav,
:root[data-theme="dark"] .builder-actions {
  background-color: color-mix(in oklab, var(--bg) 85%, transparent) !important;
  border-color: var(--border) !important;
}

/* Inputs — pages mostly hardcode bg:#fff. */
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] select {
  background-color: var(--card) !important;
  color:            var(--black) !important;
  border-color:     var(--border) !important;
}

/* ── Marketing-page hard overrides ────────────────────────────────
   The shared marketing chrome (drawer / hero / footer) and the
   per-section card surfaces (schedule, contact, belts, programs)
   all hardcode `background:#fff` or `color:#0a0a0a` directly
   instead of going through CSS variables. The flat `[class*="-card"]`
   override doesn't catch most of them because the class names are
   `belt-row`, `class-card`, `contact-item`, `schedule-day` etc.
   These explicit selectors flip the surfaces that the dashboard
   rule misses, without touching the actual belt-color renders. */

/* Side-drawer menu (index/about/programs/schedule/contact/belts). */
:root[data-theme="dark"] .drawer {
  background-color: var(--card) !important;
}
:root[data-theme="dark"] .drawer-header,
:root[data-theme="dark"] .drawer-brand {
  border-color: var(--border) !important;
}
:root[data-theme="dark"] .drawer-divider {
  background-color: var(--border) !important;
}
:root[data-theme="dark"] .drawer-item:hover {
  background-color: color-mix(in oklab, var(--card) 80%, var(--black) 20%) !important;
}
:root[data-theme="dark"] .drawer-cta {
  background-color: var(--red) !important;
  color: #fff !important;
}
:root[data-theme="dark"] .drawer-cta:hover {
  background-color: color-mix(in oklab, var(--red) 88%, #000 12%) !important;
}
:root[data-theme="dark"] .drawer-lang {
  border-color: var(--border) !important;
}

/* Hero block at the top of every marketing page. */
:root[data-theme="dark"] .hero,
:root[data-theme="dark"] .about-hero,
:root[data-theme="dark"] .belt-page {
  background-color: var(--bg) !important;
  color: var(--black) !important;
}

/* Schedule cards / tabs / table rows. */
:root[data-theme="dark"] .schedule-tab.active,
:root[data-theme="dark"] .class-card,
:root[data-theme="dark"] .schedule-day,
:root[data-theme="dark"] .schedule-slot {
  background-color: var(--card) !important;
  color: var(--black) !important;
  border-color: var(--border) !important;
}
:root[data-theme="dark"] .schedule-tabs {
  background-color: color-mix(in oklab, var(--bg) 80%, var(--black) 20%) !important;
}
:root[data-theme="dark"] .class-time,
:root[data-theme="dark"] .class-name,
:root[data-theme="dark"] .schedule-time,
:root[data-theme="dark"] .schedule-day-header {
  color: var(--black) !important;
}
:root[data-theme="dark"] .clock-icon {
  background-color: color-mix(in oklab, var(--card) 78%, var(--black) 22%) !important;
  color: var(--black) !important;
}

/* Contact selections (the four big call-to-action rows). */
:root[data-theme="dark"] .contact-item,
:root[data-theme="dark"] .contact-item--primary {
  background-color: var(--card) !important;
  color: var(--black) !important;
  border-color: var(--border) !important;
}
:root[data-theme="dark"] .contact-item:active {
  background-color: color-mix(in oklab, var(--card) 80%, var(--black) 20%) !important;
}
:root[data-theme="dark"] .contact-icon {
  background-color: color-mix(in oklab, var(--card) 78%, var(--black) 22%) !important;
}
:root[data-theme="dark"] .contact-bg-icon svg,
:root[data-theme="dark"] .contact-icon-wrap svg {
  stroke: var(--black) !important;
}

/* Belt picker — text colours, segmented pill background, and the
   `belt-row` list. Do NOT touch `.belt-swatch` itself: the swatch
   colours ARE the belt rendering. */
:root[data-theme="dark"] .belt-title,
:root[data-theme="dark"] .belt-name,
:root[data-theme="dark"] .belt-row-name {
  color: var(--black) !important;
}
:root[data-theme="dark"] .belt-eyebrow,
:root[data-theme="dark"] .belt-subtitle,
:root[data-theme="dark"] .belt-num,
:root[data-theme="dark"] .belt-number,
:root[data-theme="dark"] .belt-row-number,
:root[data-theme="dark"] .belt-hint {
  color: var(--muted) !important;
}
:root[data-theme="dark"] .belt-row {
  background-color: var(--card) !important;
  border-color: var(--border) !important;
}
:root[data-theme="dark"] .belt-segment {
  background-color: color-mix(in oklab, var(--bg) 78%, var(--black) 22%) !important;
}
:root[data-theme="dark"] .belt-segment-btn:not(.active) {
  color: var(--muted) !important;
}

/* Programs info-card. */
:root[data-theme="dark"] .info-card {
  background-color: var(--card) !important;
  color: var(--black) !important;
  border-color: var(--border) !important;
}

/* Section headings and supporting text across marketing pages —
   most are color:#0a0a0a or color:#555/#666/#999 hardcoded. */
:root[data-theme="dark"] .section-eyebrow,
:root[data-theme="dark"] .section-title,
:root[data-theme="dark"] .section-sub {
  color: var(--black) !important;
}

/* Login page brand block + a few other places that use
   `color:#0a0a0a` directly for branding text. */
:root[data-theme="dark"] .brand-main,
:root[data-theme="dark"] .drawer-brand-name,
:root[data-theme="dark"] .drawer-brand-sub,
:root[data-theme="dark"] .footer-brand-text h4,
:root[data-theme="dark"] .footer-brand-text p {
  color: var(--black) !important;
}
:root[data-theme="dark"] .brand-divider {
  background-color: var(--border) !important;
}

/* "Black-fill, white-text" buttons — .btn-primary, .about-btn-primary,
   .back-home, .role-pill, etc. all read `background:var(--black);
   color:#fff`. In dark mode --black flips to off-white so the *text*
   becomes white-on-white and the button vanishes. Repaint with the
   page bg as the text colour so the off-white fill keeps a readable
   dark label. Drawer CTA stays red (set above) for emphasis. */
:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .about-btn-primary,
:root[data-theme="dark"] .back-home,
:root[data-theme="dark"] .role-pill {
  color: var(--bg) !important;
}

/* login.html's #loginBtn hardcodes `background:#0a0a0a; color:#fff`
   with literal hex (not var(--black)) so the dark-mode variable swap
   misses it entirely. The button stayed near-black on the dark page
   bg with only the white "Sign In" label floating on it — looked
   like the button had disappeared. Force the flipped palette here. */
:root[data-theme="dark"] button#loginBtn {
  background: var(--black) !important;
  color: var(--bg) !important;
}

/* The marketing-page footer uses `background:var(--black); color:#fff`.
   Dark-mode flip makes it off-white-bg with white text → unreadable.
   Re-pin it to the card surface with off-white labels in dark mode. */
:root[data-theme="dark"] footer {
  background-color: var(--card) !important;
  color: var(--black) !important;
  border-top: 1px solid var(--border);
}
:root[data-theme="dark"] footer h4,
:root[data-theme="dark"] footer p,
:root[data-theme="dark"] .footer-brand-text h4,
:root[data-theme="dark"] .footer-brand-text p,
:root[data-theme="dark"] .footer-bottom p {
  color: var(--black) !important;
}

/* Outline button — border + text both flip via var(--black) so
   they remain visible, but force explicit colour in case the
   page hardcoded a fallback. */
:root[data-theme="dark"] .btn-outline {
  color: var(--black) !important;
  border-color: var(--black) !important;
}

/* Logout button on every dashboard — `background:#f5f5f5;
   border:#e8e8e8; color:#555` all hardcoded. */
:root[data-theme="dark"] .logout-btn,
:root[data-theme="dark"] .lang-switch {
  background-color: color-mix(in oklab, var(--card) 75%, var(--black) 25%) !important;
  color: var(--black) !important;
  border-color: var(--border) !important;
}

/* ── Contact page map illustration ────────────────────────────────
   The "map" on contact.html is a CSS illustration (not an iframe):
   a light radial gradient backdrop, a faint SVG road network,
   a white bottom-fade overlay, and a frosted-glass info card.
   Re-tint the whole stack for dark mode so it reads as a night
   map instead of staying a bright daytime panel. */
:root[data-theme="dark"] .map-bg {
  background: radial-gradient(
    ellipse at 30% 40%,
    #0f2030 0%,
    #11161e 55%,
    #07090d 100%
  ) !important;
}
:root[data-theme="dark"] .map-bg svg path {
  stroke: rgba(255, 255, 255, 0.18) !important;
  fill: none;
}
:root[data-theme="dark"] .map-bg svg path[fill] {
  fill: rgba(255, 255, 255, 0.05) !important;
  stroke: none !important;
}
:root[data-theme="dark"] .map-overlay {
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.35) 60%,
    rgba(0, 0, 0, 0.7) 100%
  ) !important;
}
:root[data-theme="dark"] .map-glass {
  background-color: rgba(20, 20, 22, 0.65) !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
  color: var(--black) !important;
}
:root[data-theme="dark"] .map-glass .contact-icon-wrap svg {
  stroke: var(--black) !important;
}
:root[data-theme="dark"] .map-arrow { color: var(--muted) !important; }
:root[data-theme="dark"] .contact-item.map-card:hover .map-arrow {
  color: var(--black) !important;
}

/* Scrollbar in dark mode (WebKit + Firefox). */
:root[data-theme="dark"] {
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
:root[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background-color: rgba(255,255,255,0.15);
}

/* ── Theme toggle ───────────────────────────────────────────────
   Single circular sun/moon button injected by theme.js. Default
   placement is inside the page's <header>; when no header exists
   the script falls back to a floating bottom-corner button using
   the same base class. Logical positioning works in RTL + LTR. */
.kempo-theme-toggle {
  /* shared appearance (both header + floating variants) */
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--card);
  color: var(--black);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  flex-shrink: 0;
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    transform 0.18s ease;
}
.kempo-theme-toggle:hover  { background: color-mix(in oklab, var(--card) 92%, var(--black) 8%); }
.kempo-theme-toggle:active { transform: scale(0.94); }
.kempo-theme-toggle svg {
  width: 18px; height: 18px;
  stroke: currentColor; fill: none;
  stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
}

/* In-header variant: lives in the normal flow next to the page's
   other header actions (logout / EN switch / etc.). Slightly bigger
   margin against neighbours and a transparent background so it
   blends with the frosted header. */
.kempo-theme-toggle--in-header {
  background: transparent;
  margin-inline: 4px;
}
.kempo-theme-toggle--in-header:hover {
  background: color-mix(in oklab, var(--card) 86%, var(--black) 14%);
}

/* In-drawer variant — small transparent button placed next to
   the language flags inside .drawer-header. */
.kempo-theme-toggle--in-drawer {
  background: transparent;
  border-color: transparent;
  width: 32px; height: 32px;
}
.kempo-theme-toggle--in-drawer:hover {
  background: color-mix(in oklab, var(--card) 86%, var(--black) 14%);
  border-color: var(--border);
}
.kempo-theme-toggle--in-drawer svg { width: 16px; height: 16px; }

/* ── Drawer language flags + theme toggle group ───────────────────
   Replaces the single .drawer-lang text button (still in the DOM
   so the page's existing toggleLanguage JS keeps wiring through —
   we just hide it). The group renders the KW + GB flags side by
   side with the theme toggle next to them. The currently selected
   language's flag gets a soft ring behind it as a visual cue. */
.kempo-lang-flags {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.drawer-lang {
  display: none !important;   /* original toggle stays for legacy JS */
}

/* Floating placement on login.html (no header, no drawer) — pinned
   where the original .lang-toggle used to sit (top corner, opposite
   the back-link). Uses logical inset so RTL/LTR Just Work. */
.kempo-lang-flags--floating {
  position: fixed;
  top: 16px;
  inset-inline-end: 16px;
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px;
}

/* Coach dashboards inject the group at the top of the bottom-
   sheet "more" panel. Give the row some breathing room + a hairline
   separator so it reads as a control header for the menu items
   below it. */
.kempo-more-sheet-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.kempo-more-sheet-row .kempo-lang-flags {
  gap: 10px;
}

/* Mini-tool pages (coach-planner, admin-curriculum) lay their
   header out as a CSS grid with a fixed-width right column sized
   for the original single-square lang button. Once we inject the
   flag group there it overflows / collapses. Widen the right
   column to fit auto content when the flag group is present. */
header.app-header.kempo-has-lang-flags,
header.app-header:has(.kempo-lang-flags) {
  grid-template-columns: 38px 1fr auto !important;
  gap: 8px;
}

/* ── Show / hide password toggle ──────────────────────────────────
   theme.js wraps every <input type="password"> in .kempo-pw-wrap
   and appends a small eye button absolutely positioned at the
   inline-end of the input. Inline-end + logical inset keep RTL
   and LTR layouts behaving the same. */
.kempo-pw-wrap {
  position: relative;
  display: block;
}
.kempo-pw-wrap input {
  /* Reserve room for the eye button so the typed text doesn't
     collide with it. !important wins against the per-page input
     rules that hardcode shorthand `padding: 13px 15px`. */
  padding-inline-end: 44px !important;
}
.kempo-pw-toggle {
  position: absolute;
  top: 50%;
  inset-inline-end: 6px;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: #8a8a8e;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.18s ease, background-color 0.18s ease;
}
.kempo-pw-toggle:hover  { color: #444; background: rgba(0,0,0,0.04); }
.kempo-pw-toggle:active { transform: translateY(-50%) scale(0.94); }
.kempo-pw-toggle svg {
  width: 18px; height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
:root[data-theme="dark"] .kempo-pw-toggle        { color: var(--muted); }
:root[data-theme="dark"] .kempo-pw-toggle:hover  {
  color: var(--black);
  background: rgba(255,255,255,0.06);
}

.lang-flag {
  width: 26px; height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: transparent;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  opacity: 0.55;
  transition: opacity 0.2s ease, transform 0.18s ease, box-shadow 0.2s ease;
}
.lang-flag:hover  { opacity: 0.9; }
.lang-flag:active { transform: scale(0.94); }

/* KW flag (the .lang-flag--ar button). 1:1 viewBox so the black
   hoist trapezoid stays inside the circular crop — the old 12×6
   viewBox got sliced down the middle and lopped the black off,
   leaving only the green / white / red stripes (hence "Italy"). */
.lang-flag--ar {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' preserveAspectRatio='xMidYMid slice'><rect width='12' height='4' fill='%23007a3d'/><rect y='4' width='12' height='4' fill='%23fff'/><rect y='8' width='12' height='4' fill='%23ce1126'/><path d='M0,0 L4,4 L4,8 L0,12 Z' fill='%23000'/></svg>");
}
/* GB flag (the .lang-flag--en button) */
.lang-flag--en {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 30' preserveAspectRatio='xMidYMid slice'><clipPath id='t'><rect width='60' height='30'/></clipPath><rect width='60' height='30' fill='%23012169'/><g clip-path='url(%23t)'><path d='M0,0 L60,30 M60,0 L0,30' stroke='%23fff' stroke-width='6'/><path d='M0,0 L60,30 M60,0 L0,30' stroke='%23C8102E' stroke-width='2'/><path d='M30,0 v30 M0,15 h60' stroke='%23fff' stroke-width='10'/><path d='M30,0 v30 M0,15 h60' stroke='%23C8102E' stroke-width='6'/></g></svg>");
}

/* Selected language gets the soft halo + full opacity.
   Driven by [data-active] on .kempo-lang-flags so the same rule
   works for both in-page toggles (body.en flips live) and link-
   based toggles (the page reloads — data-active is set on render). */
.kempo-lang-flags[data-active="ar"] .lang-flag--ar,
.kempo-lang-flags[data-active="en"] .lang-flag--en {
  opacity: 1;
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3.5px color-mix(in oklab, var(--black) 28%, transparent);
}
:root[data-theme="dark"] .kempo-lang-flags[data-active="ar"] .lang-flag--ar,
:root[data-theme="dark"] .kempo-lang-flags[data-active="en"] .lang-flag--en {
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3.5px rgba(255,255,255,0.22);
}

/* Floating fallback — pages with no <header> AND no .drawer-header
   AND no .menu-btn (e.g. login.html) get a button anchored to the
   bottom-start corner. The :not(...) chain must list every other
   placement variant so the fixed-position styling doesn't bleed
   onto an in-flow toggle (which makes it appear at the bottom-
   left of the screen instead of next to its neighbours). */
.kempo-theme-toggle:not(.kempo-theme-toggle--in-header):not(.kempo-theme-toggle--in-drawer):not(.kempo-theme-toggle--menu-mirror) {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  inset-inline-start: 16px;
  z-index: 9000;
  width: 40px; height: 40px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.10);
}
:root[data-theme="dark"] .kempo-theme-toggle:not(.kempo-theme-toggle--in-header):not(.kempo-theme-toggle--in-drawer):not(.kempo-theme-toggle--menu-mirror) {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* Pages can opt out entirely by adding [data-theme-toggle-hide] to <body>. */
body[data-theme-toggle-hide] .kempo-theme-toggle { display: none; }
