/*
 * Lumera Learning — Design System
 *
 * Color contract (WCAG 2.1 AA):
 *   --bp  (#8B7FCC) on white = ~3.0:1 — decorative fills, borders, large text ONLY. Never normal text.
 *   --bpD (#3C3489) on white = ~7.5:1 — all body text, links, tab labels, button labels (passes AAA)
 *   --bpD (#3C3489) on --bpL  = ~7.5:1 — card header text
 *   white on --navy (#2A1F6A) = ~13:1  — topbar, nav (passes AAA)
 *   --amber (#EF9F27) on white = ~2.8:1 — borders and accent strokes ONLY. Never text.
 *
 * Sizing: all in rem. Font scale multiplier applied at :root so text
 * scaling (Default / Large / X-Large) works across all components automatically.
 *
 * Mobile-first: base styles target 320px+. Scale up via min-width breakpoints.
 */

/* ─── TOKENS ─────────────────────────────────────────────────────────────── */

:root {
  /* Brand colors */
  --navy:     #2A1F6A;  /* Topbar, nav background */
  --bp:       #8B7FCC;  /* Decorative fills, borders, large text (≥18pt) only */
  --bpD:      #3C3489;  /* All interactive text — buttons, links, labels */
  --bpL:      #EEEDFE;  /* Card backgrounds, sidebar highlights */
  --amber:    #EF9F27;  /* Warning borders, accent strokes — never text on white */
  --red:      #dc2626;  /* Error states, Critical alerts */
  --green:    #16a34a;  /* Success states */

  /* Neutral */
  --text:        #1A1A2E;  /* Body text */
  --text-muted:  #6B7280;  /* Secondary labels, hints */
  --border:      #e5e7eb;  /* Table borders, dividers */
  --surface:     #f9fafb;  /* Alternate row backgrounds */
  --white:       #FFFFFF;

  /* Font scale — override via JS preferences */
  --font-scale:    1;
  --font-base:     calc(1rem * var(--font-scale));
  --font-sm:       calc(0.875rem * var(--font-scale));
  --font-xs:       calc(0.75rem * var(--font-scale));
  --font-lg:       calc(1.125rem * var(--font-scale));
  --font-xl:       calc(1.25rem * var(--font-scale));
  --font-2xl:      calc(1.5rem * var(--font-scale));

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Layout */
  --nav-width:      240px;
  --topbar-height:  56px;
  --radius:         8px;
  --radius-sm:      4px;
  --radius-lg:      12px;

  /* Transitions */
  --transition: 150ms ease;

  /* Focus ring — never suppress; override browser default with something visible */
  --focus-ring: 0 0 0 3px rgba(60, 52, 137, 0.4);
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── RESET ──────────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: var(--font-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  min-height: 100vh;
}

img, svg {
  max-width: 100%;
  display: block;
}

/* ─── FOCUS MANAGEMENT ───────────────────────────────────────────────────── */

/* Visible focus indicator on all interactive elements — WCAG 2.4.7 */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ─── TYPOGRAPHY ─────────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  color: var(--bpD);
  line-height: 1.25;
  font-weight: 700;
}

h1 { font-size: var(--font-2xl); }
h2 { font-size: var(--font-xl); }
h3 { font-size: var(--font-lg); }
h4 { font-size: var(--font-base); }

p { line-height: 1.6; }

a {
  color: var(--bpD);
  text-decoration: underline;
}

a:hover {
  opacity: 0.8;
}

/* ─── LOGIN PAGE ─────────────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--bpD) 100%);
  padding: var(--space-6);
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-8);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(42, 31, 106, 0.3);
  text-align: center;
}

.login-wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.login-wordmark-icon {
  width: 48px;
  height: 48px;
  background: var(--navy);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-wordmark-icon svg {
  width: 28px;
  height: 28px;
}

.login-wordmark-text {
  text-align: left;
}

.login-wordmark-name {
  font-size: var(--font-xl);
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
  letter-spacing: -0.5px;
}

.login-wordmark-sub {
  font-size: var(--font-xs);
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.login-heading {
  font-size: var(--font-lg);
  color: var(--text);
  margin-bottom: var(--space-2);
  font-weight: 600;
}

.login-subheading {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-8);
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-4) var(--space-6);
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 44px; /* WCAG touch target minimum */
  text-decoration: none;
}

.btn-google:hover {
  border-color: var(--bp);
  box-shadow: 0 2px 8px rgba(139, 127, 204, 0.2);
}

.btn-google:active {
  transform: translateY(1px);
}

.login-error {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: var(--font-sm);
  display: none;
}

.login-error.visible {
  display: block;
}

.login-footer {
  margin-top: var(--space-8);
  font-size: var(--font-xs);
  color: var(--text-muted);
}

/* ─── APP SHELL ──────────────────────────────────────────────────────────── */

.app-shell {
  display: none; /* shown after auth */
  min-height: 100vh;
}

.app-shell.visible {
  display: flex;
}

/* Topbar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-4);
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.topbar-nav-toggle {
  display: none; /* shown on mobile */
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: white;
  min-height: 44px;
  min-width: 44px;
  align-items: center;
  justify-content: center;
}

.topbar-wordmark {
  color: white;
  font-size: var(--font-lg);
  font-weight: 800;
  letter-spacing: -0.3px;
  text-decoration: none;
  flex: 1;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-user-name {
  color: rgba(255,255,255,0.85);
  font-size: var(--font-sm);
  font-weight: 500;
}

.topbar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bp);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--font-sm);
  font-weight: 700;
  flex-shrink: 0;
}

/* Sidebar nav — desktop */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--nav-width);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 90;
  transition: transform var(--transition);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
}

.nav-section-label {
  font-size: var(--font-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: var(--space-4) var(--space-5) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: var(--text);
  text-decoration: none;
  font-size: var(--font-sm);
  font-weight: 500;
  border-radius: 0;
  min-height: 44px;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bpL);
  color: var(--bpD);
}

.nav-item.active {
  background: var(--bpL);
  color: var(--bpD);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--bpD);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg {
  opacity: 1;
}

/* Bottom section of sidebar (Accessibility, Settings) */
.sidebar-bottom {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
}

/* Main content area */
.main-content {
  margin-top: var(--topbar-height);
  margin-left: var(--nav-width);
  flex: 1;
  padding: var(--space-8);
  min-width: 0;
}

/* ─── LOADING STATE ──────────────────────────────────────────────────────── */

.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  z-index: 200;
}

.loading-screen.hidden {
  display: none;
}

.loading-wordmark {
  color: white;
  font-size: var(--font-2xl);
  font-weight: 800;
  letter-spacing: -0.5px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── CARDS ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--bpD);
}

/* Stat cards (dashboard) */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
}

.stat-value {
  font-size: var(--font-2xl);
  font-weight: 800;
  color: var(--bpD);
  line-height: 1;
  margin-bottom: var(--space-1);
}

.stat-label {
  font-size: var(--font-sm);
  color: var(--text-muted);
  font-weight: 500;
}

/* ─── BUTTONS ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
  border: none;
  min-height: 44px;
  text-decoration: none;
  transition: opacity var(--transition), transform var(--transition);
}

.btn:hover   { opacity: 0.88; }
.btn:active  { transform: translateY(1px); }

.btn-primary {
  background: var(--bpD);
  color: var(--white);
}

.btn-secondary {
  background: var(--bpL);
  color: var(--bpD);
}

.btn-outline {
  background: transparent;
  color: var(--bpD);
  border: 1.5px solid var(--bpD);
}

.btn-danger {
  background: var(--red);
  color: var(--white);
}

/* ─── BADGES ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-3);
  border-radius: 100px;
  font-size: var(--font-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-active       { background: #dcfce7; color: #15803d; }
.badge-planning     { background: var(--bpL); color: var(--bpD); }
.badge-completed    { background: #f3f4f6; color: #6b7280; }
.badge-discontinued { background: #fef2f2; color: #dc2626; }
.badge-on-hold      { background: #fffbeb; border: 1px solid var(--amber); color: #92400e; }
.badge-pending-eval { background: #fffbeb; color: #92400e; }

/* ─── TABLES ─────────────────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
}

thead th {
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 700;
  color: var(--bpD);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: var(--font-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Sortable column affordance */
thead th[aria-sort] {
  cursor: pointer;
  user-select: none;
}
thead th[aria-sort]:hover { background: var(--bpL); }
thead th[aria-sort="ascending"]::after  { content: ' ↑'; }
thead th[aria-sort="descending"]::after { content: ' ↓'; }
thead th[aria-sort="none"]::after       { content: ' ↕'; opacity: 0.4; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:hover { background: var(--bpL); }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  vertical-align: middle;
}

/* ─── FORMS ──────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: var(--space-5);
}

/* Every input must have a visible associated label — WCAG 1.3.1 */
label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-2);
}

label .required-marker {
  color: var(--red);
  margin-left: var(--space-1);
  aria-hidden: true;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--font-base);
  color: var(--text);
  background: var(--white);
  min-height: 44px;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--bpD);
  box-shadow: var(--focus-ring);
}

.field-hint {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.field-error {
  font-size: var(--font-xs);
  color: var(--red);
  margin-top: var(--space-1);
  display: none;
}

.field-error.visible { display: block; }

/* Needs Attention flag */
.needs-attention-flag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--amber);
  font-size: var(--font-xs);
  font-weight: 600;
  border: 1px solid var(--amber);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
}

/* ─── ALERT BANNERS ──────────────────────────────────────────────────────── */

.alert {
  padding: var(--space-4);
  border-radius: var(--radius);
  font-size: var(--font-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.alert-warning {
  background: #fffbeb;
  border: 1px solid var(--amber);
  color: #92400e;
}

.alert-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert-info {
  background: var(--bpL);
  border: 1px solid var(--bp);
  color: var(--bpD);
}

.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
}

/* ─── MOBILE ─────────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  /* Topbar: show hamburger, hide user name */
  .topbar-nav-toggle { display: flex; }
  .topbar-user-name { display: none; }

  /* Sidebar becomes a slide-in drawer on mobile */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Main content fills full width */
  .main-content {
    margin-left: 0;
    padding: var(--space-4);
  }

  /* Stat grid: 2 columns on mobile */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Tables: horizontal scroll on mobile (with visible overflow cue) */
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
  }

  /* Bottom tab nav on mobile */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--border);
    z-index: 90;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .main-content {
    padding-bottom: calc(var(--space-4) + 64px); /* space for bottom nav */
  }
}

@media (min-width: 768px) {
  /* Bottom nav is hidden on tablet+ */
  .bottom-nav { display: none; }
}

/* Bottom nav items */
.bottom-nav {
  display: none; /* hidden by default; shown on mobile via @media above */
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-2) var(--space-1);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  min-height: 56px;
  border: none;
  background: none;
  cursor: pointer;
  transition: color var(--transition);
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
}

.bottom-nav-item.active {
  color: var(--bpD);
}

/* ─── DASHBOARD PLACEHOLDER ──────────────────────────────────────────────── */

.dashboard-welcome {
  margin-bottom: var(--space-6);
}

.dashboard-welcome h1 {
  font-size: var(--font-2xl);
  margin-bottom: var(--space-2);
}

.dashboard-welcome p {
  color: var(--text-muted);
  font-size: var(--font-base);
}
