/* ==========================================================================
   GreenyAI design system
   One source of truth for colour, type, spacing, motion and components.
   Page templates should compose these classes and tokens rather than
   re-declaring their own palette, shadows or animations.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Surfaces: flat, layered neutrals with a faint green tint */
  --bg: #0b0e0d;
  --surface-1: #111513;
  --surface-2: #161b18;
  --surface-3: #1c221f;
  --surface-hover: #1f2622;
  --border: #242b27;
  --border-strong: #313a35;

  /* Text */
  --text: #e7ece9;
  --text-2: #a4afa9;
  --text-3: #6e7a73;

  /* Brand accent */
  --accent: #10b981;
  --accent-hover: #34d399;
  --accent-press: #059669;
  --accent-contrast: #03140d;
  --accent-soft: rgba(16, 185, 129, 0.12);
  --accent-soft-2: rgba(16, 185, 129, 0.2);
  --accent-text: #4ade80;

  /* Status */
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.12);

  /* Type */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-reading: 'Literata', Georgia, 'Times New Roman', serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-brand: 'Orbitron', var(--font-sans);

  --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;
  --text-3xl: 2.25rem;

  /* Space (4px grid) */
  --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;
  --space-16: 64px;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

  /* Motion: short and purposeful. Nothing above 200ms. */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 90ms;
  --dur: 140ms;
  --dur-slow: 200ms;

  --header-h: 56px;
  --page-max: 1160px;
  --read-max: 42rem;

  /* Legacy aliases so older page styles pick up the new palette */
  --color-primary: var(--accent);
  --color-primary-dark: var(--accent-press);
  --color-text: var(--text);
  --color-text-muted: var(--text-2);
  --color-background: var(--bg);
  --color-surface: var(--surface-1);
  --color-border: var(--border);
  --color-error: var(--danger);
  --color-warning: var(--warning);
  --color-success: var(--accent);
  --font-primary: var(--font-sans);
  --font-display: var(--font-sans);
  --transition-fast: var(--dur-fast) var(--ease);
  --transition-base: var(--dur) var(--ease);
  --transition-slow: var(--dur-slow) var(--ease);
}

/* ==========================================================================
   Base
   ========================================================================== */

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

* {
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11', 'ss01';
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--text);
}

a {
  color: var(--accent-text);
  text-underline-offset: 2px;
}

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

/* The hidden attribute always wins, even over components that set display */
[hidden] {
  display: none !important;
}

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

::selection {
  background: var(--accent-soft-2);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Thin, quiet scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-track { background: transparent; }

@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;
  }
}

.skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-3);
  z-index: 2000;
  padding: var(--space-2) var(--space-3);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: var(--space-3); }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Layout
   ========================================================================== */

/* The site shell. Pages sit inside .container > main. */
.container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-main {
  flex: 1;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

/* Full-bleed pages (landing, editor) opt out of the page padding */
.site-main--bleed {
  max-width: none;
  padding: 0;
}

.page-narrow { max-width: 760px; margin-inline: auto; }
.page-read { max-width: var(--read-max); margin-inline: auto; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-subtitle {
  margin-top: var(--space-1);
  color: var(--text-2);
  font-size: var(--text-base);
}

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grow { flex: 1; min-width: 0; }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--space-6) 0; }

.main-interface {
  max-width: 800px;
  margin: 0 auto;
}

/* ==========================================================================
   Header
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 900;
  height: var(--header-h);
  background: rgba(11, 14, 13, 0.85);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  height: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
  border-radius: var(--radius);
}
.brand img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.brand-word {
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.brand-word .g { color: var(--accent); }
.brand-word .a { color: var(--text-2); }

.primary-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active,
.nav-link[aria-current="page"] { color: var(--text); background: var(--surface-3); }

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.header-search {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  width: 220px;
  height: 34px;
  padding: 0 var(--space-3);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-3);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.header-search:hover { border-color: var(--border-strong); color: var(--text-2); }
.header-search kbd { margin-left: auto; }

.credits-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.credits-pill:hover { border-color: var(--accent); color: var(--text); }
.credits-pill svg { color: var(--accent); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--accent-soft-2);
  color: var(--accent-text);
  font-weight: 600;
  font-size: var(--text-sm);
  object-fit: cover;
  overflow: hidden;
}
.avatar-sm { width: 24px; height: 24px; font-size: var(--text-xs); }
.avatar-lg { width: 64px; height: 64px; font-size: var(--text-xl); }

.avatar-button {
  padding: 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  background: none;
  cursor: pointer;
  display: inline-flex;
}
.avatar-button:hover,
.avatar-button[aria-expanded="true"] { border-color: var(--border-strong); }

.menu-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.mobile-nav {
  display: none;
}

@media (max-width: 860px) {
  .site-header-inner { padding: 0 var(--space-4); gap: var(--space-3); }
  .primary-nav, .header-search, .header-actions .desktop-only { display: none; }
  .menu-toggle { display: inline-flex; }
  .mobile-nav {
    position: fixed;
    inset: var(--header-h) 0 auto 0;
    z-index: 899;
    display: flex;
    flex-direction: column;
    padding: var(--space-2) var(--space-4) var(--space-4);
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    visibility: hidden;
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility 0s linear var(--dur);
  }
  .mobile-nav.open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    visibility: visible;
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility 0s;
  }
  .mobile-nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--space-3);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
  }
  .mobile-nav a:hover, .mobile-nav a.active { background: var(--surface-3); }
  .mobile-nav .menu-sep { height: 1px; background: var(--border); margin: var(--space-2) 0; }
}

/* ==========================================================================
   Menus (dropdowns). Open instantly, fade in 90ms.
   ========================================================================== */

.menu-wrap { position: relative; }

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1000;
  min-width: 200px;
  padding: var(--space-1);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-4px);
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility 0s linear var(--dur-fast);
}
.menu.open {
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility 0s;
}
.menu-left { right: auto; left: 0; }

.menu-header {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-1);
}
.menu-header strong { display: block; font-size: var(--text-sm); }
.menu-header span { font-size: var(--text-xs); color: var(--text-3); }

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover,
.menu-item:focus-visible { background: var(--surface-hover); outline: none; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-2); }
.menu-sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  /* default = secondary */
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn:hover { background: var(--surface-3); }
.btn:active { background: var(--surface-hover); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary,
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover,
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active,
.btn--primary:active { background: var(--accent-press); }

.btn-secondary,
.btn--secondary { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }

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

.btn-danger { background: transparent; border-color: rgba(248, 113, 113, 0.4); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger-solid:hover { background: #ef4444; }

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: var(--text-base); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }

.btn .spinner { width: 14px; height: 14px; }

/* ==========================================================================
   Forms
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--space-4); }

.label,
.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

.hint,
.form-help-text { font-size: var(--text-xs); color: var(--text-3); }

.input,
.select,
.textarea,
.form-input,
.form-textarea {
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea,
.form-textarea {
  height: auto;
  min-height: 120px;
  padding: var(--space-3);
  line-height: 1.6;
  resize: vertical;
}
.input::placeholder,
.textarea::placeholder,
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: #3d4842; }
.input:focus, .select:focus, .textarea:focus,
.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { font-size: var(--text-xs); color: var(--danger); }

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

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  cursor: pointer;
}
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ==========================================================================
   Surfaces
   ========================================================================== */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-sm { padding: var(--space-4); }
.card-flush { padding: 0; }
/* No overflow clipping, so row menus can escape the card. Round the ends instead. */
.card-flush > :first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); border-top-right-radius: calc(var(--radius-lg) - 1px); }
.card-flush > :last-child,
.card-flush > :last-child > :last-child { border-bottom-left-radius: calc(var(--radius-lg) - 1px); border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--text-md); font-weight: 600; }
.card-body { padding: var(--space-5); }

a.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
a.card-link:hover { border-color: var(--border-strong); background: var(--surface-2); }

/* Lists: rows separated by hairlines, the default way to show collections */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease);
}
.list-row:last-child { border-bottom: 0; }
a.list-row:hover,
.list-row.is-clickable:hover { background: var(--surface-2); }
.list-row-title { font-weight: 550; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-meta { font-size: var(--text-xs); color: var(--text-3); }

/* ==========================================================================
   Small parts
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 550;
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

kbd {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
}

.muted, .text-muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.text-primary { color: var(--accent-text); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tabs: underline style */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 var(--space-3);
  border: 0;
  background: none;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active,
.tab[aria-selected="true"],
.tab[aria-current="page"] { color: var(--text); }
.tab.active::after,
.tab[aria-selected="true"]::after,
.tab[aria-current="page"]::after {
  content: '';
  position: absolute;
  left: var(--space-2);
  right: var(--space-2);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.tab .count { color: var(--text-3); font-weight: 500; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.segmented > * {
  height: 28px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.segmented > .active,
.segmented > [aria-pressed="true"],
.segmented > [aria-current="page"] { background: var(--surface-3); color: var(--text); }

/* Empty states */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-6);
  color: var(--text-2);
}
.empty-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background: var(--surface-3);
  color: var(--text-2);
  margin-bottom: var(--space-2);
}
.empty-icon svg { width: 20px; height: 20px; }
.empty h3 { font-size: var(--text-md); color: var(--text); }
.empty p { max-width: 360px; font-size: var(--text-sm); }
.empty .btn { margin-top: var(--space-3); }

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Top progress bar for navigation and long requests */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 3000;
  height: 2px;
  width: 0;
  background: var(--accent);
  opacity: 0;
  transition: width 300ms var(--ease), opacity var(--dur) var(--ease);
}
.progress-bar.active { opacity: 1; }

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-region {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 4000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease);
}
.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.leaving { opacity: 0; transform: translateY(4px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.toast button {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--text-3);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Dialogs (native <dialog>)
   ========================================================================== */

dialog.dialog {
  margin: auto;
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
dialog.dialog[open] { animation: dialog-in var(--dur-slow) var(--ease); }
dialog.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-body { padding: var(--space-6); }
.dialog-title { font-size: var(--text-lg); font-weight: 650; margin-bottom: var(--space-2); }
.dialog-text { color: var(--text-2); font-size: var(--text-sm); }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Page messages (Django messages framework)
   ========================================================================== */

.site-messages {
  max-width: var(--page-max);
  margin: 0 auto var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.site-message {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--info-soft);
  font-size: var(--text-sm);
}
.site-message-success { background: var(--accent-soft); border-color: rgba(16, 185, 129, 0.35); }
.site-message-error { background: var(--danger-soft); border-color: rgba(248, 113, 113, 0.35); }
.site-message-warning { background: var(--warning-soft); border-color: rgba(251, 191, 36, 0.35); }
.site-message-close {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--text-2);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: var(--text-sm);
}
.site-footer-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.site-footer-links { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); }
.site-footer-links a { color: var(--text-2); text-decoration: none; }
.site-footer-links a:hover { color: var(--text); }

/* ==========================================================================
   Reading typography (chapters)
   ========================================================================== */

.prose {
  font-family: var(--font-reading);
  font-size: 1.125rem;
  line-height: 1.8;
  color: #dfe5e1;
  max-width: var(--read-max);
}
.prose p { margin: 0 0 1.1em; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 640px) {
  .site-main { padding: var(--space-5) var(--space-4) var(--space-12); }
  .page-title { font-size: var(--text-xl); }
  .card { padding: var(--space-4); }
  .list-row { padding: var(--space-3) var(--space-4); }
  .site-footer-inner { padding: var(--space-6) var(--space-4); flex-direction: column; align-items: flex-start; }
}

/* Utility spacing kept for older templates */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: var(--space-1); } .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-4); } .mb-4 { margin-bottom: var(--space-6); } .mb-5 { margin-bottom: var(--space-8); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-4); } .mt-4 { margin-top: var(--space-6); } .mt-5 { margin-top: var(--space-8); }
