/* =============================================================================
   TeamTasks — Design System
   Mobile-first CSS for a standalone team task manager.
   Single file, no dependencies, system fonts only.

   Table of contents
     1.  Design tokens (:root)          — color, spacing, radius, shadow, type
     2.  Dark theme override
     3.  Global reset & base
     4.  Layout: app shell, app-bar, view, bottom-nav
     5.  Typography helpers
     6.  Buttons
     7.  Form controls (input / select / textarea / form-row)
     8.  Cards & lists
     9.  Badges (status + priority)
     10. Chips (filters)
     11. Stat tiles & grid
     12. Avatars
     13. Modal / bottom-sheet + backdrop
     14. Toasts
     15. Empty state
     16. Boot splash & auth screen
     17. Utilities
     18. Responsive enhancements (tablet / desktop)
   ========================================================================== */

/* -----------------------------------------------------------------------------
   1. Design tokens — light theme
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces & text */
  --color-bg: #f4f5fb;
  --color-surface: #ffffff;
  --color-surface-2: #f0f1f8;
  --color-text: #14162b;
  --color-muted: #64708a;
  --color-border: #e2e5ef;

  /* Brand */
  --color-primary: #3f9384;
  --color-primary-hover: #347a6d;
  --color-primary-soft: #e5f1ee;
  --color-primary-contrast: #ffffff;

  /* Feedback */
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-soft: #fdeaea;

  /* Status colors: todo=slate, in_progress=amber, done=green */
  --color-status-todo: #64748b;
  --color-status-todo-soft: #eef1f5;
  --color-status-in_progress: #d97706;
  --color-status-in_progress-soft: #fdf1df;
  --color-status-done: #16a34a;
  --color-status-done-soft: #e6f6ec;

  /* Priority colors: low=slate, medium=blue, high=red */
  --color-prio-low: #64748b;
  --color-prio-low-soft: #eef1f5;
  --color-prio-medium: #2563eb;
  --color-prio-medium-soft: #e7eefe;
  --color-prio-high: #dc2626;
  --color-prio-high-soft: #fdeaea;

  /* Spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius scale */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(20, 22, 43, 0.06);
  --shadow-md: 0 4px 12px rgba(20, 22, 43, 0.08);
  --shadow-lg: 0 12px 28px rgba(20, 22, 43, 0.14);
  --shadow-focus: 0 0 0 3px rgba(63, 147, 132, 0.28);

  /* Type scale */
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";

  /* Layout */
  --app-bar-h: 56px;
  --bottom-nav-h: 60px;
  --content-max: 720px;

  /* Motion */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 180ms;
}

/* -----------------------------------------------------------------------------
   2. Theme — light/white only (dark auto-theme intentionally disabled)
   -------------------------------------------------------------------------- */
/* The app is fixed to the light theme regardless of the OS colour-scheme
   preference, so the UI always matches the Node build's white look. */

/* -----------------------------------------------------------------------------
   3. Global reset & base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  font-weight: 700;
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }

:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* -----------------------------------------------------------------------------
   4. Layout: app shell, app-bar, view, bottom-nav
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Sticky top bar */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--app-bar-h);
  padding: 0 var(--space-4);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--app-bar-h) + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--color-border);
}

.app-bar .app-bar-title,
.app-bar h1 {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-bar .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 800;
  flex: 0 0 auto;
}

/* Brand logo in the app bar */
.app-bar .app-bar-brand {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}
.app-bar .app-bar-logo {
  height: 26px;
  width: auto;
  display: block;
}

/* Brand logo on the login card */
.auth-card .auth-logo-img {
  display: block;
  height: 44px;
  width: auto;
  max-width: 78%;
  margin: 0 auto var(--space-4);
}

/* Content area — pushes content clear of the fixed bottom nav */
#view,
main {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: calc(
    var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--space-6)
  );
}

/* Fixed bottom navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  padding-bottom: calc(var(--space-1) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--color-border);
}

.bottom-nav a {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.1;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.bottom-nav a .nav-icon,
.bottom-nav a svg {
  width: 22px;
  height: 22px;
  font-size: 20px;
  line-height: 1;
}

.bottom-nav a:active {
  background: var(--color-surface-2);
}

.bottom-nav a.active {
  color: var(--color-primary);
}

.bottom-nav a.active .nav-icon,
.bottom-nav a.active svg {
  transform: translateY(-1px);
}

/* -----------------------------------------------------------------------------
   5. Typography helpers
   -------------------------------------------------------------------------- */
.page-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
}

.section-title {
  font-size: var(--text-md);
  font-weight: 700;
  margin: var(--space-5) 0 var(--space-3);
}

.muted { color: var(--color-muted); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }

/* -----------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--dur) var(--ease),
    border-color var(--dur) var(--ease), transform var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--color-primary);
  border-color: transparent;
  color: var(--color-primary-contrast);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-primary);
}
.btn-ghost:hover { background: var(--color-primary-soft); }

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

/* Button sizing/shape modifiers */
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: 44px; }

/* Floating action button (e.g. "＋ New task") */
.fab {
  position: fixed;
  right: var(--space-4);
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--space-4));
  z-index: 35;
  min-height: 52px;
  padding: 0 var(--space-5);
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

/* -----------------------------------------------------------------------------
   7. Form controls
   -------------------------------------------------------------------------- */
.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--color-muted);
  opacity: 0.85;
}

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

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

/* Custom chevron for selects */
.select {
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364708a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  cursor: pointer;
}

/* Field group with label */
.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-row > label,
.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-muted);
}

.form-row .field-error,
.field-error {
  font-size: var(--text-sm);
  color: var(--color-danger);
}

/* Two-up rows collapse to single column on narrow screens by default */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

/* -----------------------------------------------------------------------------
   8. Cards & lists
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

/* Tappable card affordance */
a.card,
.card-link,
.card[role="button"],
.card[data-href] {
  display: block;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
a.card:hover,
.card-link:hover,
.card[role="button"]:hover,
.card[data-href]:hover {
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
  box-shadow: var(--shadow-md);
}
a.card:active,
.card-link:active,
.card[data-href]:active {
  transform: scale(0.99);
}

.card + .card { margin-top: var(--space-3); }

.card-title {
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

/* Vertical list container */
.list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Optional divided-row list (comments, etc.) */
.list-rows {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.list-rows > * {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.list-rows > *:last-child { border-bottom: 0; }

/* -----------------------------------------------------------------------------
   9. Badges (status + priority)
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

/* Status badges */
.badge-status-todo {
  color: var(--color-status-todo);
  background: var(--color-status-todo-soft);
  border-color: color-mix(in srgb, var(--color-status-todo) 22%, transparent);
}
.badge-status-in_progress {
  color: var(--color-status-in_progress);
  background: var(--color-status-in_progress-soft);
  border-color: color-mix(in srgb, var(--color-status-in_progress) 24%, transparent);
}
.badge-status-done {
  color: var(--color-status-done);
  background: var(--color-status-done-soft);
  border-color: color-mix(in srgb, var(--color-status-done) 22%, transparent);
}

/* Priority badges */
.badge-prio-low {
  color: var(--color-prio-low);
  background: var(--color-prio-low-soft);
  border-color: color-mix(in srgb, var(--color-prio-low) 22%, transparent);
}
.badge-prio-medium {
  color: var(--color-prio-medium);
  background: var(--color-prio-medium-soft);
  border-color: color-mix(in srgb, var(--color-prio-medium) 24%, transparent);
}
.badge-prio-high {
  color: var(--color-prio-high);
  background: var(--color-prio-high-soft);
  border-color: color-mix(in srgb, var(--color-prio-high) 26%, transparent);
}

/* -----------------------------------------------------------------------------
   10. Chips (filters)
   -------------------------------------------------------------------------- */
.chip-row {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-1);
  margin: 0 calc(-1 * var(--space-4)) var(--space-3);
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}
.chip:hover {
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
}

/* Selected state via .active or aria-pressed */
.chip.active,
.chip[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: transparent;
  color: var(--color-primary-contrast);
}

/* -----------------------------------------------------------------------------
   11. Stat tiles & grid
   -------------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
a.stat-tile,
.stat-tile[data-href] { cursor: pointer; }
a.stat-tile:hover,
.stat-tile[data-href]:hover {
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
  box-shadow: var(--shadow-md);
}
a.stat-tile:active,
.stat-tile[data-href]:active { transform: scale(0.99); }

.stat-tile .stat-value {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-tile .stat-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-muted);
}

/* Accent variants for KPI tiles */
.stat-tile.accent-primary .stat-value { color: var(--color-primary); }
.stat-tile.accent-todo .stat-value { color: var(--color-status-todo); }
.stat-tile.accent-in_progress .stat-value { color: var(--color-status-in_progress); }
.stat-tile.accent-done .stat-value { color: var(--color-status-done); }
.stat-tile.accent-danger .stat-value { color: var(--color-danger); }

/* -----------------------------------------------------------------------------
   12. Avatars
   -------------------------------------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  overflow: hidden;
}
.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 56px; height: 56px; font-size: var(--text-lg); }

/* -----------------------------------------------------------------------------
   13. Modal / bottom-sheet + backdrop
   -------------------------------------------------------------------------- */
.modal-backdrop,
.modal .backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(9, 12, 26, 0.5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: backdrop-in var(--dur) var(--ease);
}

/* When the backdrop is nested inside .modal (see ui.js modal()), it must sit
   BEHIND the panel so the panel remains clickable; the panel has z-index: 1. */
.modal .backdrop {
  z-index: 0;
}

/* .modal is the positioning layer; it holds a backdrop + a sheet/panel */
.modal {
  position: fixed;
  inset: 0;
  z-index: 51;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-panel,
.modal .sheet,
.modal-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--content-max);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-5) var(--space-4);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: sheet-in 260ms var(--ease);
}

/* Grab handle for the bottom-sheet feel */
.modal-panel::before,
.modal .sheet::before {
  content: "";
  display: block;
  width: 40px;
  height: 4px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
}
.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-5);
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes sheet-in {
  from { transform: translateY(24px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* -----------------------------------------------------------------------------
   14. Toasts
   -------------------------------------------------------------------------- */
.toast-stack,
.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--space-4));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-text);
  color: var(--color-bg);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 220ms var(--ease);
}

/* When not stacked, a lone .toast still sits near the bottom */
.toast:not(.toast-stack .toast):not(.toasts .toast) {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--space-4));
  z-index: 60;
  width: min(92vw, 420px);
}

.toast-success { background: var(--color-status-done); color: #fff; }
.toast-error,
.toast-danger { background: var(--color-danger); color: #fff; }
.toast-info { background: var(--color-primary); color: var(--color-primary-contrast); }

@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* -----------------------------------------------------------------------------
   15. Empty state
   -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-5);
  color: var(--color-muted);
}
.empty-state .empty-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  border-radius: 50%;
  background: var(--color-surface-2);
  color: var(--color-muted);
}
.empty-state .empty-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-text);
}

/* -----------------------------------------------------------------------------
   16. Boot splash & auth screen
   -------------------------------------------------------------------------- */
.boot-splash {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--color-muted);
  font-weight: 600;
}
.boot-splash::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  animation: spin 700ms linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Login / auth screen container */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  padding-top: calc(var(--space-5) + env(safe-area-inset-top));
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  background:
    radial-gradient(1200px 600px at 50% -10%,
      color-mix(in srgb, var(--color-primary) 14%, transparent), transparent),
    var(--color-bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-5);
  box-shadow: var(--shadow-lg);
}
.auth-card .auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 800;
  font-size: var(--text-xl);
}
.auth-card .auth-title {
  text-align: center;
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.auth-card .auth-subtitle {
  text-align: center;
  color: var(--color-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-5);
}

/* -----------------------------------------------------------------------------
   17. Utilities
   -------------------------------------------------------------------------- */
.row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}
.row-between { justify-content: space-between; }
.row-wrap { flex-wrap: wrap; }

.col {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

.text-center { text-align: center; }
.text-right { text-align: right; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nowrap { white-space: nowrap; }

.hidden,
[hidden] { display: none !important; }

.full-width { width: 100%; }

/* Visually hidden but accessible to screen readers */
.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;
}

/* -----------------------------------------------------------------------------
   18. Responsive enhancements (tablet / desktop)
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  :root {
    --content-max: 760px;
  }

  #view,
  main {
    padding: var(--space-6) var(--space-6);
    padding-bottom: calc(
      var(--bottom-nav-h) + env(safe-area-inset-bottom) + var(--space-8)
    );
  }

  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Two-column form fields on wider screens */
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Chip row no longer needs to bleed to edges */
  .chip-row {
    flex-wrap: wrap;
    overflow: visible;
    margin: 0 0 var(--space-4);
    padding-left: 0;
    padding-right: 0;
  }

  /* Modal becomes a centered dialog rather than a bottom-sheet */
  .modal {
    align-items: center;
    padding: var(--space-5);
  }
  .modal-panel,
  .modal .sheet,
  .modal-content {
    border-radius: var(--radius-xl);
    max-width: 520px;
    max-height: 88vh;
    padding-bottom: var(--space-5);
    animation: dialog-in 220ms var(--ease);
  }
  .modal-panel::before,
  .modal .sheet::before {
    display: none;
  }

  @keyframes dialog-in {
    from { transform: translateY(8px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
  }
}

@media (min-width: 900px) {
  :root {
    --content-max: 880px;
  }

  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Give the app bar and nav a touch more breathing room */
  .app-bar {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }

  /* Toast stack aligns to bottom-right on large screens */
  .toast-stack,
  .toasts {
    left: auto;
    right: var(--space-6);
    transform: none;
    bottom: calc(var(--bottom-nav-h) + var(--space-6));
    align-items: flex-end;
  }
}

/* ---------------------------------------------------------------------------
   Addendum 2: CAPTCHA login + admin Activity log
   (appended — does not modify existing rules)
--------------------------------------------------------------------------- */

/* CAPTCHA block on the login screen */
.captcha-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

.captcha-img {
  display: block;
  width: 100%;
  max-width: 200px;
  height: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  margin-bottom: var(--space-2);
}

.captcha-refresh {
  flex: 0 0 auto;
  padding: 0 var(--space-3);
}

/* Activity log */
.audit-filters .select { flex: 1 1 140px; min-width: 0; }
.audit-filters .input { flex: 2 1 180px; min-width: 0; }

.audit-summary {
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.audit-meta { margin-top: var(--space-1); }

.audit-more:empty { display: none; }
