/* =============================================================================
   PositiveGym – Shared Theme + HCI Layer  v2026-11
   Loaded after page styles (see html/helpers/theme_head.php).

   1. Colour-scheme / theme tokens
   2. Theme toggle button
   3. Accessibility & usability (focus, skip link, touch targets, reduced motion)
   4. Forms
   5. Tables & overflow
   6. Light-mode polish
   ============================================================================= */

/* ── 1. Tokens ─────────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --pgx-focus:          #ffd21f;
  --pgx-focus-contrast: #111;
  --pgx-page:           #0d0f11;
  --pgx-selection:      rgba(255,210,31,.35);
  --pgx-tap:            44px;
}
html[data-theme="light"] {
  color-scheme: light;
  --pgx-focus:          #1a56db;
  --pgx-focus-contrast: #fff;
  --pgx-page:           #f0f2f5;
  --pgx-selection:      rgba(255,210,31,.55);
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
html[data-theme="light"] body { background-color: var(--pgx-page); }
::selection { background: var(--pgx-selection); }

/* smooth theme transition (not for prefers-reduced-motion users) */
html.pg-theme-anim,
html.pg-theme-anim *,
html.pg-theme-anim *::before,
html.pg-theme-anim *::after {
  transition: background-color .25s ease, border-color .25s ease, color .25s ease, box-shadow .25s ease !important;
}

/* ── 2. Theme toggle ─────────────────────────────────────────────────────── */
.pg-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 0 0 auto;
  min-width: var(--pgx-tap);
  height: var(--pgx-tap);
  margin: 0 0 0 16px;
  padding: 0 12px;
  color: #f0f2f5;
  background: rgba(255,255,255,.07);
  border: 1.5px solid rgba(255,215,0,.5);
  border-radius: 10px;
  font: 600 13px/1 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .2s, border-color .2s, transform .15s;
}
.pg-theme-toggle:hover  { background: rgba(255,215,0,.14); border-color: #ffd700; }
.pg-theme-toggle:active { transform: scale(.96); }

.pg-theme-toggle__icon  { display: inline-flex; width: 20px; height: 20px; }
.pg-theme-toggle__icon svg { width: 100%; height: 100%; }
.pg-theme-toggle__label { white-space: nowrap; }

/* icon-only on small screens, full label on desktop */
@media (max-width: 1024px) {
  .pg-theme-toggle {
    order: 8;
    margin-left: auto;
    margin-right: 10px;
    padding: 0;
    width: var(--pgx-tap);
  }
  .pg-theme-toggle__label { display: none; }
  .nav-container > .nav-toggle,
  .client-header > .app-nav-toggle,
  .coach-header  > .app-nav-toggle { order: 9; margin-left: 0; }
}
@media (min-width: 1025px) {
  .nav-container > .nav-links { margin-left: auto !important; }
  .pg-theme-toggle__label { display: inline; }
}

/* Floating toggle for pages without a header */
.pg-theme-toggle--floating {
  position: fixed;
  z-index: 2000;
  top: 12px;
  right: 12px;
  margin: 0;
  color: #f4f5f6;
  background: rgba(16,18,21,.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
html[data-theme="light"] .pg-theme-toggle--floating {
  color: #14171a;
  background: rgba(255,255,255,.95);
  border-color: #c9a800;
  box-shadow: 0 6px 18px rgba(15,23,42,.18);
}
@media (max-width: 1024px) { .pg-theme-toggle--floating { width: auto; margin: 0; } }

/* ── 3. Accessibility & usability ───────────────────────────────────────── */

/* Skip-to-content link */
.pg-skip-link {
  position: fixed;
  z-index: 3000;
  left: 12px;
  top: -80px;
  padding: 12px 18px;
  border-radius: 8px;
  background: #ffd21f;
  color: #111;
  font: 700 14px/1 system-ui, sans-serif;
  text-decoration: none;
  transition: top .15s ease;
}
.pg-skip-link:focus { top: 12px; outline: 3px solid #111; outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

/* Universal keyboard-only focus ring */
:where(a, button, input, select, textarea, summary, [role="button"], [tabindex]):focus { outline: none; }
:where(a, button, input, select, textarea, summary, [role="button"], [tabindex]):focus-visible {
  outline: 3px solid var(--pgx-focus) !important;
  outline-offset: 2px !important;
  border-radius: max(var(--pgx-r, 0px), 4px);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--pgx-focus) 28%, transparent);
}

/* Keep gold ring on dark headers */
.nav-bar :focus-visible,
.client-header :focus-visible,
.coach-header   :focus-visible,
.hero           :focus-visible { --pgx-focus: #ffd21f; }

button, [role="button"], a.btn, input[type="submit"], input[type="button"], label[for] {
  touch-action: manipulation;
}
:disabled, [aria-disabled="true"] { cursor: not-allowed; }
button:not(:disabled), [role="button"] { cursor: pointer; }
:where(button, [role="button"], input[type="submit"]):active:not(:disabled) { transform: translateY(1px); }
[aria-busy="true"] { cursor: progress; opacity: .8; }

/* Fitts's law — bigger tap targets on touch devices */
@media (pointer: coarse) {
  :where(button, input[type="submit"], input[type="button"], select, .btn, [role="button"]) {
    min-height: var(--pgx-tap);
  }
  :where(nav a, .nav-links a, .admin-sidebar a, .client-header nav a, .coach-header nav a) {
    min-height: var(--pgx-tap);
  }
  :where(input[type="checkbox"], input[type="radio"]) { width: 22px; height: 22px; }
  :where(table a, .pagination a, .pagination button, .table-tools button) {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
}

/* Reduced-motion respect */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── 4. Forms ────────────────────────────────────────────────────────────── */
/* 16 px prevents iOS viewport zoom on focus */
@media (max-width: 760px) {
  :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea) {
    font-size: 16px !important;
  }
  :where(input, select, textarea) { max-width: 100%; }
}

:where(input, select, textarea):user-invalid { border-color: #e5484d !important; }
html[data-theme="light"] :where(input, select, textarea):user-invalid { border-color: #c62828 !important; }

::placeholder { opacity: 1; }
html[data-theme="light"]  ::placeholder { color: #6b7280; }
html:not([data-theme="light"]) ::placeholder { color: #98a0aa; }

:where(label)    { cursor: pointer; }
:where(textarea) { resize: vertical; }
:where(input[type="number"]) { -moz-appearance: textfield; }

/* ── 5. Tables & overflow ───────────────────────────────────────────────── */
.pg-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.pg-table-scroll:focus-visible { outline-offset: -3px !important; }

img, video, canvas, iframe, svg { max-width: 100%; }
img, video { height: auto; }
body { overflow-wrap: break-word; }

/* ── 6. Light-mode polish ───────────────────────────────────────────────── */
html[data-theme="light"] { scrollbar-color: #b6bcc4 #eceef0; }

/* Dark header / hero stay dark in light mode */
html[data-theme="light"] .pg-dark-zone,
html[data-theme="light"] .nav-bar,
html[data-theme="light"] .client-header,
html[data-theme="light"] .coach-header { color-scheme: dark; }

/* Custom-arrow selects in light mode */
html[data-theme="light"] .admin-add-user-page .admin-user-form .form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='m5 7.5 5 5 5-5' stroke='%23374151' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Inline-<style> page light variants */
html[data-theme="light"] .admin-user-form .admin-password-error,
html[data-theme="light"] .account-setup-details .account-setup-error:not(:empty),
html[data-theme="light"] .account-setup-form [data-message][data-state="error"] { color: #b42318; }

html[data-theme="light"] .admin-user-form input[aria-invalid="true"] {
  border-color: #c62828 !important;
  box-shadow: 0 0 0 2px rgba(198,40,40,.16);
}
html[data-theme="light"] .account-setup-details select    { background: #fff; color: #14171a; border-color: #c9ced6; color-scheme: light; }
html[data-theme="light"] .account-setup-details small,
html[data-theme="light"] .account-setup-form [data-message] { color: #4b5563; }
html[data-theme="light"] .account-setup-otp > label         { color: #14171a; }
html[data-theme="light"] .account-setup-form [data-message][data-state="success"] { color: #166534; }
html[data-theme="light"] .account-setup-form .pass-form__otp-digits input {
  background: #fff; color: #14171a; border-color: #aab1bb;
}
html[data-theme="light"] .account-setup-form .pass-form__otp-digits input:focus {
  border-color: #1a56db;
  box-shadow: 0 0 8px rgba(26,86,219,.28);
  outline-color: rgba(26,86,219,.4);
}
html[data-theme="light"] .account-setup-form .pass-form__otp-actions button,
html[data-theme="light"] .account-setup-back {
  background: #fff; color: #14171a; border-color: #b58f00;
}
