/* ────────────────────────────────────────────────────────────────────
   WalkSpy Design System — v0.1
   Loaded last in the layout chain so the .w-* layer takes precedence
   over legacy theme styles when both apply. Tokens via CSS custom
   properties; component classes namespaced .w-*. See DESIGN_SYSTEM.md.
   ──────────────────────────────────────────────────────────────────── */

/* ─── Tokens ────────────────────────────────────────────────────────── */

:root {
  /* Brand — anchored to the existing logo teal #16acbe */
  --w-brand-50:  oklch(96% 0.02 213);
  --w-brand-100: oklch(92% 0.04 213);
  --w-brand-300: oklch(78% 0.08 213);
  --w-brand-500: oklch(67% 0.10 213);   /* primary = logo #16acbe */
  --w-brand-600: oklch(58% 0.11 213);   /* hover/active */
  --w-brand-700: oklch(48% 0.11 213);   /* pressed */
  --w-brand-900: oklch(28% 0.08 213);

  /* Navy companion (existing navbar #14162d) */
  --w-navy-700: oklch(28% 0.04 270);
  --w-navy-900: oklch(20% 0.04 270);

  /* Semantic */
  --w-live:    oklch(63% 0.20 25);   /* red-orange — broadcast only */
  --w-money:   oklch(72% 0.16 145);  /* green — $-related affordances only */
  --w-success: oklch(65% 0.13 145);
  --w-warning: oklch(72% 0.14 80);
  --w-danger:  oklch(60% 0.20 25);

  /* Surfaces */
  --w-bg:           oklch(99% 0 0);
  --w-bg-alt:       oklch(96% 0 0);
  --w-surface:      oklch(100% 0 0);
  --w-surface-elev: oklch(99% 0 0);

  /* Text */
  --w-fg:        oklch(20% 0 0);
  --w-fg-muted:  oklch(45% 0 0);
  --w-fg-subtle: oklch(60% 0 0);
  --w-fg-on-brand: oklch(99% 0 0);

  /* Borders */
  --w-border:        oklch(90% 0 0);
  --w-border-strong: oklch(80% 0 0);

  /* Typography */
  --w-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --w-text-xs:   0.75rem;
  --w-text-sm:   0.875rem;
  --w-text-base: 1rem;
  --w-text-lg:   1.125rem;
  --w-text-xl:   1.25rem;
  --w-text-2xl:  1.5rem;
  --w-text-3xl:  1.875rem;
  --w-text-4xl:  2.25rem;
  --w-leading-tight:  1.2;
  --w-leading-snug:   1.4;
  --w-leading-normal: 1.6;
  --w-weight-regular:  400;
  --w-weight-medium:   500;
  --w-weight-semibold: 600;
  --w-weight-bold:     700;

  /* Spacing — 8pt grid */
  --w-space-1: 0.25rem;
  --w-space-2: 0.5rem;
  --w-space-3: 0.75rem;
  --w-space-4: 1rem;
  --w-space-5: 1.5rem;
  --w-space-6: 2rem;
  --w-space-7: 3rem;
  --w-space-8: 4rem;

  /* Radius / shadow / motion */
  --w-radius-sm:     6px;
  --w-radius-md:     12px;
  --w-radius-lg:     20px;
  --w-radius-pill:   999px;
  --w-radius-circle: 50%;

  --w-shadow-sm:   0 1px 2px rgb(0 0 0 / 0.06);
  --w-shadow-md:   0 4px 12px rgb(0 0 0 / 0.08);
  --w-shadow-lg:   0 12px 32px rgb(0 0 0 / 0.12);
  --w-shadow-glow: 0 0 0 4px oklch(67% 0.10 213 / 0.30);

  --w-motion-fast:   120ms;
  --w-motion-base:   200ms;
  --w-motion-slow:   320ms;
  --w-ease:          cubic-bezier(0.2, 0.8, 0.2, 1);
  --w-ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);

  --w-z-base:    0;
  --w-z-overlay: 10;
  --w-z-sheet:   20;
  --w-z-modal:   30;
  --w-z-toast:   40;
  --w-z-tooltip: 50;
}

[data-theme="dark"] {
  --w-bg:           oklch(15% 0 0);
  --w-bg-alt:       oklch(20% 0 0);
  --w-surface:      oklch(22% 0 0);
  --w-surface-elev: oklch(26% 0 0);
  --w-fg:           oklch(95% 0 0);
  --w-fg-muted:     oklch(70% 0 0);
  --w-fg-subtle:    oklch(55% 0 0);
  --w-border:       oklch(30% 0 0);
  --w-border-strong: oklch(40% 0 0);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --w-motion-fast: 0ms;
    --w-motion-base: 0ms;
    --w-motion-slow: 0ms;
  }
}

/* ─── Button ───────────────────────────────────────────────────────── */

.w-btn {
  --_bg:     var(--w-brand-500);
  --_bg-h:   var(--w-brand-600);
  --_bg-a:   var(--w-brand-700);
  --_fg:     var(--w-fg-on-brand);
  --_border: transparent;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--w-space-2);
  padding: var(--w-space-3) var(--w-space-5);
  font: var(--w-weight-semibold) var(--w-text-base) / var(--w-leading-tight) var(--w-font);
  color: var(--_fg);
  background: var(--_bg);
  border: 1px solid var(--_border);
  border-radius: var(--w-radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--w-motion-fast) var(--w-ease),
              transform var(--w-motion-fast) var(--w-ease),
              box-shadow var(--w-motion-fast) var(--w-ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.w-btn:hover  { background: var(--_bg-h); }
.w-btn:active { background: var(--_bg-a); transform: translateY(1px); }
.w-btn:focus-visible { outline: none; box-shadow: var(--w-shadow-glow); }
.w-btn[aria-disabled="true"], .w-btn:disabled, .w-btn.is-disabled, .w-btn.is-loading {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}

/* Variants */
.w-btn--secondary {
  --_bg:   var(--w-surface);
  --_bg-h: var(--w-bg-alt);
  --_bg-a: var(--w-bg-alt);
  --_fg:   var(--w-fg);
  --_border: var(--w-border-strong);
}
.w-btn--ghost {
  --_bg:   transparent;
  --_bg-h: var(--w-brand-50);
  --_bg-a: var(--w-brand-100);
  --_fg:   var(--w-brand-600);
  --_border: transparent;
}
.w-btn--danger {
  --_bg:   var(--w-danger);
  --_bg-h: oklch(54% 0.20 25);
  --_bg-a: oklch(48% 0.20 25);
}
.w-btn--live {
  --_bg:   var(--w-live);
  --_bg-h: oklch(57% 0.20 25);
  --_bg-a: oklch(51% 0.20 25);
  position: relative;
}
.w-btn--live::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: var(--w-radius-circle);
  background: currentColor;
  animation: w-pulse 1.4s ease-in-out infinite;
}
@keyframes w-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.85); }
}

/* Sizes */
.w-btn--sm { padding: var(--w-space-2) var(--w-space-3); font-size: var(--w-text-sm); }
.w-btn--md { /* default */ }
.w-btn--lg { padding: var(--w-space-4) var(--w-space-6); font-size: var(--w-text-lg); }
.w-btn--xl {
  padding: var(--w-space-5) var(--w-space-7);
  font-size: var(--w-text-xl);
  border-radius: var(--w-radius-lg);
}

/* Loading state */
.w-btn__spinner {
  width: 1em; height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--w-radius-circle);
  animation: w-spin var(--w-motion-slow) linear infinite;
}
@keyframes w-spin { to { transform: rotate(360deg); } }
.w-btn.is-loading .w-btn__label { opacity: 0.6; }

/* ─── Field ────────────────────────────────────────────────────────── */

.w-field { display: flex; flex-direction: column; gap: var(--w-space-2); }
.w-field__label {
  font: var(--w-weight-medium) var(--w-text-sm) / var(--w-leading-snug) var(--w-font);
  color: var(--w-fg);
}
.w-field__required { color: var(--w-danger); margin-left: 2px; }
.w-field__control input,
.w-field__control textarea,
.w-field__control select {
  width: 100%;
  padding: var(--w-space-3) var(--w-space-4);
  font: var(--w-weight-regular) var(--w-text-base) / var(--w-leading-snug) var(--w-font);
  color: var(--w-fg);
  background: var(--w-surface);
  border: 1px solid var(--w-border-strong);
  border-radius: var(--w-radius-md);
  transition: border-color var(--w-motion-fast) var(--w-ease),
              box-shadow var(--w-motion-fast) var(--w-ease);
}
.w-field__control input:focus-visible,
.w-field__control textarea:focus-visible,
.w-field__control select:focus-visible {
  outline: none;
  border-color: var(--w-brand-500);
  box-shadow: var(--w-shadow-glow);
}
.w-field__helper {
  font: var(--w-weight-regular) var(--w-text-sm) / var(--w-leading-snug) var(--w-font);
  color: var(--w-fg-muted);
  margin: 0;
}
.w-field__error {
  font: var(--w-weight-medium) var(--w-text-sm) / var(--w-leading-snug) var(--w-font);
  color: var(--w-danger);
  margin: 0;
}
.w-field.is-invalid .w-field__control input,
.w-field.is-invalid .w-field__control textarea,
.w-field.is-invalid .w-field__control select {
  border-color: var(--w-danger);
}

/* ─── Card ─────────────────────────────────────────────────────────── */

.w-card {
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius-md);
  box-shadow: var(--w-shadow-sm);
}
.w-card--p-none { padding: 0; }
.w-card--p-sm   { padding: var(--w-space-4); }
.w-card--p-md   { padding: var(--w-space-5); }
.w-card--p-lg   { padding: var(--w-space-6); }

/* ─── Toast ────────────────────────────────────────────────────────── */

.w-toast-container {
  position: fixed;
  z-index: var(--w-z-toast);
  top: var(--w-space-4);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--w-space-2);
  pointer-events: none;
  width: min(420px, calc(100vw - var(--w-space-6)));
}
@media (min-width: 768px) {
  .w-toast-container { left: auto; right: var(--w-space-5); top: var(--w-space-5); transform: none; }
}
.w-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--w-space-3);
  padding: var(--w-space-4) var(--w-space-5);
  background: var(--w-surface);
  color: var(--w-fg);
  border: 1px solid var(--w-border);
  border-left: 4px solid var(--w-brand-500);
  border-radius: var(--w-radius-md);
  box-shadow: var(--w-shadow-md);
  pointer-events: auto;
  animation: w-toast-in var(--w-motion-base) var(--w-ease-spring);
}
.w-toast.is-leaving { animation: w-toast-out var(--w-motion-base) var(--w-ease) forwards; }
.w-toast--success { border-left-color: var(--w-success); }
.w-toast--warning { border-left-color: var(--w-warning); }
.w-toast--error   { border-left-color: var(--w-danger);  }
.w-toast__body  { flex: 1; font: var(--w-weight-regular) var(--w-text-sm) / var(--w-leading-snug) var(--w-font); }
.w-toast__close {
  background: none; border: 0; padding: 0;
  font-size: var(--w-text-lg); line-height: 1;
  color: var(--w-fg-subtle); cursor: pointer;
}
.w-toast__close:hover { color: var(--w-fg); }
@keyframes w-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes w-toast-out {
  to   { opacity: 0; transform: translateY(-8px); }
}

/* ─── Sheet (bottom sheet / right rail) ────────────────────────────── */

.w-sheet {
  position: fixed;
  inset: 0;
  z-index: var(--w-z-sheet);
  display: none;
}
.w-sheet.is-open { display: block; }
.w-sheet__backdrop {
  position: absolute; inset: 0;
  background: rgb(0 0 0 / 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--w-motion-base) var(--w-ease);
}
.w-sheet.is-open .w-sheet__backdrop { opacity: 1; }
.w-sheet__panel {
  position: absolute;
  background: var(--w-surface);
  box-shadow: var(--w-shadow-lg);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--w-motion-base) var(--w-ease-spring);
  max-height: 90dvh;
  overflow: hidden;
}
.w-sheet.is-open .w-sheet__panel { transform: translateY(0); }

/* anchor: bottom (default — mobile-first) */
.w-sheet--bottom .w-sheet__panel {
  left: 0; right: 0; bottom: 0;
  border-radius: var(--w-radius-lg) var(--w-radius-lg) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.w-sheet--bottom.w-sheet--sm   .w-sheet__panel { max-height: 40dvh; }
.w-sheet--bottom.w-sheet--md   .w-sheet__panel { max-height: 65dvh; }
.w-sheet--bottom.w-sheet--lg   .w-sheet__panel { max-height: 85dvh; }
.w-sheet--bottom.w-sheet--full .w-sheet__panel { max-height: 100dvh; height: 100dvh; }

/* anchor: right (desktop) */
.w-sheet--right .w-sheet__panel {
  top: 0; bottom: 0; right: 0;
  width: min(420px, 100vw);
  border-radius: 0;
  transform: translateX(100%);
}
.w-sheet--right.is-open .w-sheet__panel { transform: translateX(0); }

@media (min-width: 768px) {
  /* On desktop, bottom sheets become right-rail by default for cleaner UX */
  .w-sheet--bottom:not(.w-sheet--keep-bottom) .w-sheet__panel {
    top: 0; bottom: 0; right: 0; left: auto;
    width: min(480px, 100vw);
    max-height: 100dvh; height: 100dvh;
    border-radius: 0;
    transform: translateX(100%);
  }
  .w-sheet--bottom:not(.w-sheet--keep-bottom).is-open .w-sheet__panel { transform: translateX(0); }
}

.w-sheet__handle {
  width: 40px; height: 4px;
  background: var(--w-border-strong);
  border-radius: var(--w-radius-pill);
  margin: var(--w-space-2) auto var(--w-space-3);
}
.w-sheet__header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--w-space-3);
  padding: 0 var(--w-space-5) var(--w-space-3);
  border-bottom: 1px solid var(--w-border);
}
.w-sheet__title {
  font: var(--w-weight-semibold) var(--w-text-lg)/var(--w-leading-snug) var(--w-font);
  margin: 0;
}
.w-sheet__close {
  background: none; border: 0; padding: var(--w-space-1) var(--w-space-2);
  font-size: var(--w-text-2xl); line-height: 1;
  color: var(--w-fg-subtle); cursor: pointer;
  border-radius: var(--w-radius-sm);
}
.w-sheet__close:hover { color: var(--w-fg); background: var(--w-bg-alt); }
.w-sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--w-space-5);
}

/* ─── Pill ─────────────────────────────────────────────────────────── */

.w-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--w-space-2);
  padding: 4px 10px;
  font: var(--w-weight-semibold) var(--w-text-xs)/1 var(--w-font);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--w-radius-pill);
  background: var(--w-bg-alt);
  color: var(--w-fg-muted);
  border: 1px solid var(--w-border);
}
.w-pill--brand   { background: var(--w-brand-50);    color: var(--w-brand-700); border-color: var(--w-brand-300); }
.w-pill--live    { background: var(--w-live);        color: #fff; border-color: transparent; }
.w-pill--success { background: oklch(94% 0.05 145);  color: oklch(38% 0.13 145); border-color: oklch(82% 0.10 145); }
.w-pill--warning { background: oklch(95% 0.05 80);   color: oklch(40% 0.14 80);  border-color: oklch(82% 0.10 80); }
.w-pill--danger  { background: oklch(95% 0.05 25);   color: oklch(40% 0.20 25);  border-color: oklch(82% 0.15 25); }
.w-pill--money   { background: oklch(94% 0.05 145);  color: oklch(38% 0.13 145); border-color: oklch(82% 0.10 145); }
.w-pill__dot {
  width: 8px; height: 8px;
  border-radius: var(--w-radius-circle);
  background: currentColor;
  animation: w-pulse 1.4s ease-in-out infinite;
}

/* ─── IconButton ───────────────────────────────────────────────────── */

.w-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;            /* hits the 44pt mobile target */
  padding: 0;
  font-size: var(--w-text-lg);
  border: 0;
  border-radius: var(--w-radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--w-motion-fast) var(--w-ease),
              color      var(--w-motion-fast) var(--w-ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.w-iconbtn:focus-visible { outline: none; box-shadow: var(--w-shadow-glow); }
.w-iconbtn--sm { width: 36px; height: 36px; font-size: var(--w-text-base); }
.w-iconbtn--lg { width: 56px; height: 56px; font-size: var(--w-text-xl); border-radius: var(--w-radius-lg); }
.w-iconbtn--glass {
  background: rgb(0 0 0 / 0.5);
  color: #fff;
  backdrop-filter: blur(8px);
}
.w-iconbtn--glass:hover { background: rgb(0 0 0 / 0.65); }
.w-iconbtn--solid {
  background: var(--w-surface);
  color: var(--w-fg);
  border: 1px solid var(--w-border);
}
.w-iconbtn--solid:hover { background: var(--w-bg-alt); }
.w-iconbtn--ghost {
  background: transparent;
  color: var(--w-fg-muted);
}
.w-iconbtn--ghost:hover { background: var(--w-bg-alt); color: var(--w-fg); }
