/* ============================================================
   WRITS POLLS — base.css
   Design tokens, reset, typography, base components
   ============================================================ */

/* ── 0. Visibility utilities ──────────────────────────────────────────────── */
/* Enforce the HTML hidden attribute even when CSS rules like display:flex
   or display:block would otherwise override the browser's built-in behaviour. */
[hidden]  { display: none !important; }
/* Hide Alpine x-cloak elements until Alpine initialises (results.php etc.) */
[x-cloak] { display: none !important; }

/* ── 1. Design Tokens ────────────────────────────────────── */
:root {
  /* Brand — WRITS identity */
  --primary:       #C90000;   /* WRITS Red */
  --primary-dark:  #A00000;
  --primary-light: #FDEAEA;   /* Soft red tint for backgrounds */
  --navy:          #002B42;   /* Deep Navy */
  --navy-light:    #004166;   /* Lighter navy for hover states */
  --cream:         #FFF8EF;   /* Warm cream background */

  /* Four option/accent colors — used across the entire app */
  --accent-coral:  #fb7185;
  --accent-mint:   #34d399;
  --accent-amber:  #fbbf24;
  --accent-sky:    #38bdf8;

  /* Semantic surface */
  --bg:           #FFF8EF;    /* Warm cream page background */
  --surface:      #ffffff;
  --surface-elev: #ffffff;

  /* Text */
  --text:         #18181b;
  --text-muted:   #71717a;

  /* Chrome */
  --border:       #e4e4e7;
  --success:      var(--accent-mint);
  --danger:       #ef4444;
  --warning:      var(--accent-amber);

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.08);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.12);

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

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

  /* Transitions */
  --transition-fast: 0.12s ease;
  --transition-base: 0.2s ease;
}

/* ── 2. Dark mode tokens (toggle wired in Phase 9) ────────── */
[data-theme="dark"] {
  --bg:           #0d0d0d;
  --surface:      #1a1a1a;
  --surface-elev: #252525;
  --text:         #fafafa;
  --text-muted:   #a1a1aa;
  --border:       #333333;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.6);
  --primary-light: #3D0000;
  --cream:         #1a1a1a;
}

/* ── 3. Reset ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { list-style: none; }

/* ── 4. Typography ────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}
h1 { font-size: clamp(1.5rem, 4vw, 1.875rem); }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }

p { line-height: 1.65; }

small { font-size: 0.8125rem; }

/* ── 5. Forms ─────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.form-input {
  width: 100%;
  min-height: 48px;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(201 0 0 / 0.15);
}
.form-input.is-error { border-color: var(--danger); }
.form-input.is-error:focus {
  box-shadow: 0 0 0 3px rgb(239 68 68 / 0.15);
}

.field-error {
  font-size: 0.8125rem;
  color: var(--danger);
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── 6. Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 11px 20px;
  min-height: 48px;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--transition-fast),
              border-color var(--transition-fast),
              opacity var(--transition-fast),
              transform var(--transition-fast),
              box-shadow var(--transition-fast);
  -webkit-user-select: none;
  user-select: none;
}
.btn:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-full { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-light);
}
.btn-secondary:hover { background: #f9c6c6; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-lg { min-height: 56px; padding: 15px 28px; font-size: 1rem; }
.btn-sm { min-height: 36px; padding: 7px 14px; font-size: 0.875rem; }

/* Loading spinner inside button */
.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 7. Alerts / banners ──────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  line-height: 1.5;
  border: 1px solid transparent;
}
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ── 8. Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
}
.badge-primary  { background: var(--primary-light); color: var(--primary); }
.badge-coral    { background: #ffe4e6; color: #be123c; }
.badge-mint     { background: #dcfce7; color: #166534; }
.badge-amber    { background: #fef9c3; color: #854d0e; }
.badge-sky      { background: #e0f2fe; color: #075985; }

/* ── 9. Loading bar ───────────────────────────────────────── */
.loading-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  background: var(--primary);
  width: 0;
  z-index: 9999;
  border-radius: 0 2px 2px 0;
  transition: opacity 0.3s;
}
.loading-bar.is-active {
  animation: lbar 1.4s ease-in-out infinite;
}
@keyframes lbar {
  0%   { left: -30%; width: 30%; }
  60%  { left: 100%; width: 30%; }
  100% { left: 100%; width: 0; }
}

/* ── 10. Toast notifications ──────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 9999;
  pointer-events: none;
  max-width: 340px;
}
.toast {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--text);
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(12px);
  transition: opacity var(--transition-base), transform var(--transition-base);
  pointer-events: auto;
}
.toast.is-visible    { opacity: 1; transform: translateX(0); }
.toast-success { background: #15803d; }
.toast-error   { background: #b91c1c; }

/* ── 11. Utility ──────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.gap-2       { gap: var(--space-2); }
.gap-3       { gap: var(--space-3); }
.gap-4       { gap: var(--space-4); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.divider { border: none; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

/* Chip (used for batch labels across the app) */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  gap: 6px;
  transition: transform var(--transition-fast);
}
.chip-coral  { background: #ffe4e6; color: #9f1239; }
.chip-mint   { background: #dcfce7; color: #15803d; }
.chip-amber  { background: #fef9c3; color: #a16207; }
.chip-sky    { background: #e0f2fe; color: #0369a1; }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}
.empty-state-icon {
  width: 48px; height: 48px;
  opacity: 0.35;
}

/* ── 12. Skeleton screens ─────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    color-mix(in srgb, var(--border) 30%, var(--bg)) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
  user-select: none;
  pointer-events: none;
}
.skeleton-text  { height: 1em;   margin-bottom: 0.5em; }
.skeleton-title { height: 1.4em; width: 55%; margin-bottom: 0.75em; }
.skeleton-card  {
  height: 80px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}

@keyframes skeleton-wave {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

/* ── 13. Dark-mode overrides for base components ─────────────── */
[data-theme="dark"] .alert-error   { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .alert-success { background: #052e16; border-color: #166534; color: #86efac; }
[data-theme="dark"] .alert-info    { background: #1e3a5f; border-color: #1d4ed8; color: #93c5fd; }

[data-theme="dark"] .badge-primary  { background: #3D0000; color: #ff8080; }
[data-theme="dark"] .badge-coral   { background: #4d1a1f; color: #fb7185; }
[data-theme="dark"] .badge-mint    { background: #0f3020; color: #34d399; }
[data-theme="dark"] .badge-amber   { background: #3d2a00; color: #fbbf24; }
[data-theme="dark"] .badge-sky     { background: #0c2a40; color: #38bdf8; }

[data-theme="dark"] .chip-coral    { background: #4d1a1f; color: #fb7185; }
[data-theme="dark"] .chip-mint     { background: #0f3020; color: #34d399; }
[data-theme="dark"] .chip-amber    { background: #3d2a00; color: #fbbf24; }
[data-theme="dark"] .chip-sky      { background: #0c2a40; color: #38bdf8; }

/* ── 14. prefers-reduced-motion ──────────────────────────────── */
@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;
  }
}
