/* ============================================================================
   TMS FOUNDATION CSS
   Design system for Trak Management System

   Philosophy: Professional, high-density enterprise UI with greyscale-first
   aesthetic and subtle accent colors. Smart, modern, clean, delightful.
   ============================================================================ */

/* ============================================================================
   1. DESIGN TOKENS
   ============================================================================ */

:root {
  /* === NEUTRALS (GREYSCALE PALETTE) === */
  --neutral-950: #0a0a0b;
  --neutral-900: #0b0b0c;
  --neutral-800: #1f1f21;
  --neutral-700: #3a3a3d;
  --neutral-600: #545459;
  --neutral-500: #6f7377;
  --neutral-400: #9ca3af;
  --neutral-300: #d1d5db;
  --neutral-200: #e5e7eb;
  --neutral-100: #f3f4f6;
  --neutral-50: #f9fafb;

  /* === ACCENT COLORS === */
  /* Primary accent - cyan from company logo */
  --accent-primary-600: #007d94;
  --accent-primary-500: #009cb6;
  --accent-primary-400: #00b7d3;

  /* Secondary accent - amber for warnings/highlights */
  --accent-secondary-600: #d97706;
  --accent-secondary-500: #f59e0b;
  --accent-secondary-400: #fbbf24;

  /* === STATUS COLORS === */
  --status-success-700: #15803d;
  --status-success-600: #16a34a;
  --status-success-500: #22c55e;
  --status-success-100: #dcfce7;

  --status-danger-700: #b91c1c;
  --status-danger-600: #dc2626;
  --status-danger-500: #ef4444;
  --status-danger-100: #fee2e2;

  --status-warning-700: #c2410c;
  --status-warning-600: #ea580c;
  --status-warning-500: #f97316;
  --status-warning-100: #ffedd5;

  --status-info-700: #1d4ed8;
  --status-info-600: #2563eb;
  --status-info-500: #3b82f6;
  --status-info-100: #dbeafe;

  /* === SEMANTIC TOKENS === */
  /* Text hierarchy */
  --text-strong: var(--neutral-950);
  --text: var(--neutral-900);
  --text-muted: var(--neutral-600);
  --text-subtle: var(--neutral-500);
  --text-inverse: #ffffff;

  /* Interactive elements */
  --link: var(--accent-primary-500);
  --link-hover: var(--accent-primary-600);

  /* Surface hierarchy */
  --bg-page: var(--neutral-50);
  --bg-elev-1: #ffffff;
  --bg-elev-2: var(--neutral-100);
  --bg-elev-3: var(--neutral-200);

  /* Borders */
  --border: var(--neutral-300);
  --border-strong: var(--neutral-400);
  --border-subtle: var(--neutral-200);

  /* Header/footer */
  --bg-header: var(--neutral-950);
  --bg-footer: var(--neutral-900);

  /* === 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;
  --space-16: 64px;
  --space-20: 80px;

  /* === TYPOGRAPHY === */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Font sizes - compact scale for high density */
  --text-xs: 0.6875rem;    /* 11px */
  --text-sm: 0.8125rem;    /* 13px */
  --text-base: 0.875rem;   /* 14px */
  --text-md: 0.9375rem;    /* 15px */
  --text-lg: 1rem;         /* 16px */
  --text-xl: 1.125rem;     /* 18px */
  --text-2xl: 1.25rem;     /* 20px */
  --text-3xl: 1.5rem;      /* 24px */
  --text-4xl: 1.875rem;    /* 30px */

  /* Font weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Line heights - compact */
  --leading-tight: 1.25;
  --leading-normal: 1.4;
  --leading-relaxed: 1.5;

  /* === EFFECTS === */
  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  /* Shadows - subtle */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.05), 0 4px 6px rgba(0, 0, 0, 0.03);

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.15);
  --focus-ring-danger: 0 0 0 3px rgba(239, 68, 68, 0.15);

  /* Transitions */
  --duration-fast: 120ms;
  --duration-base: 150ms;
  --duration-slow: 200ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================================
   DARK THEME
   ============================================================================ */

[data-theme="dark"] {
  /* === SEMANTIC TOKENS (DARK MODE) === */
  /* Text hierarchy - inverted */
  --text-strong: #f9fafb;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-subtle: #6f7377;
  /* Note: --text-inverse stays #ffffff - header is always dark */

  /* Interactive elements - slightly brighter in dark mode */
  --link: var(--accent-primary-400);
  --link-hover: var(--accent-primary-500);

  /* Surface hierarchy - darker base, lighter elevations */
  --bg-page: #0a0a0b;
  --bg-elev-1: #1f1f21;
  --bg-elev-2: #2a2a2d;
  --bg-elev-3: #35353a;

  /* Borders - lighter for visibility on dark backgrounds */
  --border: #3a3a3d;
  --border-strong: #545459;
  --border-subtle: #2a2a2d;

  /* Header/footer - keep very dark */
  --bg-header: #0a0a0b;
  --bg-footer: #0b0b0c;

  /* === EFFECTS (DARK MODE) === */
  /* Shadows - stronger for depth on dark backgrounds */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.6), 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.7), 0 2px 4px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.8), 0 4px 6px rgba(0, 0, 0, 0.7);

  /* Focus rings - adjusted for dark backgrounds */
  --focus-ring: 0 0 0 3px rgba(0, 183, 211, 0.3);
  --focus-ring-danger: 0 0 0 3px rgba(239, 68, 68, 0.3);

  /* Form fields - darker backgrounds */
  --field-bg: #1f1f21;
  --field-border: var(--border);
  --field-border-focus: var(--accent-primary-400);
  --field-shadow-focus: var(--focus-ring);
}

/* Dark mode: Keep status alert/card text dark for contrast on light backgrounds */
/* Alerts */
[data-theme="dark"] .alert--info,
[data-theme="dark"] .alert--info .alert__title,
[data-theme="dark"] .alert--info .alert__message {
  color: var(--status-info-700);
}

[data-theme="dark"] .alert--success,
[data-theme="dark"] .alert--success .alert__title,
[data-theme="dark"] .alert--success .alert__message {
  color: var(--status-success-700);
}

[data-theme="dark"] .alert--warning,
[data-theme="dark"] .alert--warning .alert__title,
[data-theme="dark"] .alert--warning .alert__message {
  color: var(--status-warning-700);
}

[data-theme="dark"] .alert--danger,
[data-theme="dark"] .alert--danger .alert__title,
[data-theme="dark"] .alert--danger .alert__message {
  color: var(--status-danger-700);
}

/* Cards - target all child elements to override global text colors */
[data-theme="dark"] .card--info,
[data-theme="dark"] .card--info *,
[data-theme="dark"] .card--info h1,
[data-theme="dark"] .card--info h2,
[data-theme="dark"] .card--info h3,
[data-theme="dark"] .card--info h4,
[data-theme="dark"] .card--info h5,
[data-theme="dark"] .card--info h6,
[data-theme="dark"] .card--info p {
  color: var(--status-info-700) !important;
}

[data-theme="dark"] .card--success,
[data-theme="dark"] .card--success *,
[data-theme="dark"] .card--success h1,
[data-theme="dark"] .card--success h2,
[data-theme="dark"] .card--success h3,
[data-theme="dark"] .card--success h4,
[data-theme="dark"] .card--success h5,
[data-theme="dark"] .card--success h6,
[data-theme="dark"] .card--success p {
  color: var(--status-success-700) !important;
}

[data-theme="dark"] .card--warning,
[data-theme="dark"] .card--warning *,
[data-theme="dark"] .card--warning h1,
[data-theme="dark"] .card--warning h2,
[data-theme="dark"] .card--warning h3,
[data-theme="dark"] .card--warning h4,
[data-theme="dark"] .card--warning h5,
[data-theme="dark"] .card--warning h6,
[data-theme="dark"] .card--warning p {
  color: var(--status-warning-700) !important;
}

[data-theme="dark"] .card--danger,
[data-theme="dark"] .card--danger *,
[data-theme="dark"] .card--danger h1,
[data-theme="dark"] .card--danger h2,
[data-theme="dark"] .card--danger h3,
[data-theme="dark"] .card--danger h4,
[data-theme="dark"] .card--danger h5,
[data-theme="dark"] .card--danger h6,
[data-theme="dark"] .card--danger p {
  color: var(--status-danger-700) !important;
}

/* Dark mode adjustments for specific components */
[data-theme="dark"] .user-menu__dropdown {
  background: #1f1f21;
  border-color: var(--border);
}

[data-theme="dark"] .user-menu__header {
  background: #2a2a2d;
  border-bottom-color: var(--border-subtle);
}

[data-theme="dark"] code {
  background: #2a2a2d;
  color: var(--text-strong);
}

[data-theme="dark"] pre {
  background: #2a2a2d;
}

/* ============================================================================
   2. CSS RESET & BASE STYLES
   ============================================================================ */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg-page);
  min-height: 100vh;
}

/* ============================================================================
   3. TYPOGRAPHY
   ============================================================================ */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-semibold);
  color: var(--text-strong);
  line-height: var(--leading-tight);
  margin: 0;
}

h1 { font-size: var(--text-4xl); margin-bottom: var(--space-6); }
h2 { font-size: var(--text-3xl); margin-bottom: var(--space-5); }
h3 { font-size: var(--text-2xl); margin-bottom: var(--space-4); }
h4 { font-size: var(--text-xl); margin-bottom: var(--space-3); }
h5 { font-size: var(--text-lg); margin-bottom: var(--space-3); }
h6 { font-size: var(--text-md); margin-bottom: var(--space-2); }

p {
  margin: 0 0 var(--space-4) 0;
  line-height: var(--leading-normal);
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--duration-base) var(--ease);
}

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

a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

strong, b {
  font-weight: var(--font-semibold);
  color: var(--text-strong);
}

em, i {
  font-style: italic;
}

small {
  font-size: var(--text-sm);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-strong);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--bg-elev-2);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
}

pre code {
  background: none;
  padding: 0;
}

ul, ol {
  margin: 0 0 var(--space-4) 0;
  padding-left: var(--space-6);
}

ul {
  list-style-type: disc;
}

ol {
  list-style-type: decimal;
}

li {
  margin-bottom: var(--space-2);
  line-height: var(--leading-normal);
}

li:last-child {
  margin-bottom: 0;
}

ul ul, ol ul {
  list-style-type: circle;
  margin-top: var(--space-2);
  margin-bottom: var(--space-2);
}

ul ol, ol ol {
  list-style-type: lower-alpha;
  margin-top: var(--space-2);
  margin-bottom: var(--space-2);
}

/* Typography utilities */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.font-normal { font-weight: var(--font-normal); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.text-strong { color: var(--text-strong); }
.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-inverse { color: var(--text-inverse); }

.leading-tight { line-height: var(--leading-tight); }
.leading-normal { line-height: var(--leading-normal); }
.leading-relaxed { line-height: var(--leading-relaxed); }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

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

/* ============================================================================
   4. LAYOUT & SURFACES
   ============================================================================ */

.container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.container--narrow {
  max-width: 1000px;
}

.container--wide {
  max-width: 1600px;
}

.section {
  padding: var(--space-12) 0;
}

.section--sm {
  padding: var(--space-8) 0;
}

.section--lg {
  padding: var(--space-16) 0;
}

/* Card component */
.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}

.card--interactive {
  cursor: pointer;
  transition: box-shadow var(--duration-base) var(--ease),
              transform var(--duration-base) var(--ease),
              border-color var(--duration-base) var(--ease);
}

.card--interactive:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.card--interactive:active {
  transform: translateY(0);
}

.card--compact {
  padding: var(--space-4);
}

.card--spacious {
  padding: var(--space-8);
}

.card__header {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-strong);
  margin: 0;
}

.card__subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.card__content {
  color: var(--text);
}

.card__footer {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* Card grid - two column layout, stacks on mobile */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Card variants */
.card--danger {
  background: var(--status-danger-100);
  border-color: var(--status-danger-500);
}

.card--warning {
  background: var(--status-warning-100);
  border-color: var(--status-warning-500);
}

.card--success {
  background: var(--status-success-100);
  border-color: var(--status-success-500);
}

.card--info {
  background: var(--status-info-100);
  border-color: var(--status-info-500);
}

/* ============================================================================
   LIST CARD GRID - Responsive grid for list pages
   ============================================================================ */

/* Grid container - fills width, responsive columns */
.list-card-grid {
  display: grid;
  gap: var(--space-3);
  /* Mobile: 2 columns that fill available width */
  grid-template-columns: repeat(2, 1fr);
}

/* Very small screens: single column */
@media (max-width: 399px) {
  .list-card-grid {
    grid-template-columns: 1fr;
  }
}

/* Tablet and up: 3 columns */
@media (min-width: 640px) {
  .list-card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Desktop: 4 columns */
@media (min-width: 1024px) {
  .list-card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Large desktop: 5 columns */
@media (min-width: 1280px) {
  .list-card-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* List card - clickable item in a list */
.list-card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color var(--duration-base) var(--ease),
              box-shadow var(--duration-base) var(--ease);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0; /* Allow flex item to shrink */
}

.list-card:hover {
  border-color: var(--accent-primary-400);
  box-shadow: var(--shadow-sm);
}

.list-card:focus-visible {
  outline: 2px solid var(--accent-primary-500);
  outline-offset: 2px;
}

/* List card as anchor - remove link styling */
a.list-card {
  text-decoration: none;
  color: inherit;
}

a.list-card:hover {
  text-decoration: none;
  color: inherit;
}

/* List card field hierarchy */
.list-card__primary {
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--text-strong);
}

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

.list-card__badges {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

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

/* ============================================================================
   STAT CARDS - Clickable statistic display cards
   ============================================================================ */

.stat-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-3);
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-4);
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: box-shadow var(--duration-base) var(--ease),
              transform var(--duration-base) var(--ease),
              border-color var(--duration-base) var(--ease);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.stat-card:active {
  transform: translateY(0);
}

.stat-card:focus-visible {
  outline: 2px solid var(--accent-primary-500);
  outline-offset: 2px;
}

/* Stat card as anchor - remove link styling */
a.stat-card {
  text-decoration: none;
  color: inherit;
}

a.stat-card:hover {
  text-decoration: none;
  color: inherit;
}

.stat-card__value {
  font-size: var(--text-3xl);
  font-weight: var(--font-semibold);
  color: var(--text-strong);
  line-height: 1;
}

.stat-card__label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-2);
}

/* ============================================================================
   LIST VIEW SWITCHER - Toggle between table and card views
   ============================================================================ */

/* View switcher - hidden on mobile */
.view-switcher {
  display: none;
}

@media (min-width: 768px) {
  .view-switcher {
    display: flex;
    gap: var(--space-1);
    align-items: center;
  }

  .view-switcher__label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-right: var(--space-2);
  }

  .view-switcher__btn {
    padding: var(--space-2);
    border: 1px solid var(--border);
    background: var(--bg-elev-1);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
  }

  .view-switcher__btn:hover {
    background: var(--bg-elev-2);
    border-color: var(--border-strong);
  }

  .view-switcher__btn--active {
    background: var(--accent-primary-500);
    border-color: var(--accent-primary-500);
    color: var(--text-inverse);
  }

  .view-switcher__btn--active:hover {
    background: var(--accent-primary-600);
    border-color: var(--accent-primary-600);
  }

  .view-switcher__btn svg {
    width: 18px;
    height: 18px;
    display: block;
  }
}

/* List view visibility - default state */
.list-table-view {
  display: block;
}

.list-card-view {
  display: none;
}

/* Mobile: always show cards, hide table */
@media (max-width: 767px) {
  .list-table-view {
    display: none !important;
  }

  .list-card-view {
    display: grid !important;
  }
}

/* Desktop: controlled by JavaScript via body attribute */
@media (min-width: 768px) {
  body[data-list-view="table"] .list-table-view {
    display: block;
  }

  body[data-list-view="table"] .list-card-view {
    display: none;
  }

  body[data-list-view="cards"] .list-table-view {
    display: none;
  }

  body[data-list-view="cards"] .list-card-view {
    display: grid;
  }
}

/* ============================================================================
   5. HEADER
   ============================================================================ */

.header {
  background: var(--bg-header);
  color: var(--text-inverse);
  border-bottom: 1px solid var(--neutral-800);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  max-width: 1600px;
  margin: 0 auto;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-inverse);
  text-decoration: none;
}

.header__brand:hover {
  text-decoration: none;
  opacity: 0.9;
}

.header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.header__link {
  color: var(--text-inverse);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: background-color var(--duration-base) var(--ease);
}

.header__link:hover {
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
}

.header__link--active {
  background: rgba(255, 255, 255, 0.15);
}

/* User menu dropdown */
.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  color: var(--text-inverse);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background-color var(--duration-base) var(--ease);
}

.user-menu__trigger:hover {
  background: rgba(255, 255, 255, 0.1);
}

.user-menu__dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 240px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.1s ease-out, transform 0.1s ease-out;
}

.user-menu__dropdown--open {
  opacity: 1;
  transform: scale(1);
}

.user-menu__header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elev-2);
}

.user-menu__name {
  font-weight: var(--font-semibold);
  color: var(--text-strong);
  font-size: var(--text-sm);
  margin-bottom: var(--space-1);
}

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

.user-menu__links {
  padding: var(--space-2) 0;
}

.user-menu__footer {
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border-subtle);
}

.user-menu__link {
  display: block;
  padding: var(--space-2) var(--space-4);
  color: var(--text);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: background-color var(--duration-base) var(--ease);
}

.user-menu__link:hover {
  background: var(--bg-elev-2);
  text-decoration: none;
}

.user-menu__link--danger {
  color: var(--status-danger-600);
}

.user-menu__link--danger:hover {
  background: var(--status-danger-100);
}

/* ============================================================================
   6. FOOTER
   ============================================================================ */

.footer {
  padding: var(--space-6);
  margin-top: auto;
}

.footer__text {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  margin: 0;
}

/* ============================================================================
   7. BUTTONS
   ============================================================================ */

:root {
  --btn-radius: var(--radius-md);
  --btn-padding-y: 8px;
  --btn-padding-x: 14px;
  --btn-font-size: var(--text-sm);
  --btn-font-weight: var(--font-medium);
  --btn-transition: all var(--duration-base) var(--ease);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--btn-radius);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-font-weight);
  font-family: inherit;
  line-height: 1;
  padding: var(--btn-padding-y) var(--btn-padding-x);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: var(--btn-transition);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  text-decoration: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:active {
  transform: translateY(0.5px);
}

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

/* Button with icon */
.btn__icon {
  flex-shrink: 0;
}

/* Button variants */
.btn--primary {
  background: var(--accent-primary-500);
  color: var(--text-inverse);
  border-color: var(--accent-primary-500);
}

.btn--primary:hover {
  background: var(--accent-primary-600);
  color: var(--text-inverse);
  border-color: var(--accent-primary-600);
}

.btn--secondary {
  background: transparent;
  color: var(--accent-primary-500);
  border-color: var(--accent-primary-500);
}

.btn--secondary:hover {
  background: var(--accent-primary-500);
  color: var(--text-inverse);
  border-color: var(--accent-primary-500);
}

.btn--tertiary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn--tertiary:hover {
  background: var(--bg-elev-2);
  color: var(--text);
  border-color: var(--border-strong);
}

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

.btn--ghost:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

.btn--danger {
  background: var(--status-danger-600);
  color: var(--text-inverse);
  border-color: var(--status-danger-600);
}

.btn--danger:hover {
  background: var(--status-danger-700);
  color: var(--text-inverse);
  border-color: var(--status-danger-700);
}

.btn--danger:focus-visible {
  box-shadow: var(--focus-ring-danger);
}

.btn--danger-outline {
  background: transparent;
  color: var(--status-danger-600);
  border-color: var(--status-danger-600);
}

.btn--danger-outline:hover {
  background: var(--status-danger-600);
  color: var(--text-inverse);
  border-color: var(--status-danger-600);
}

.btn--danger-outline:focus-visible {
  box-shadow: var(--focus-ring-danger);
}

.btn--success {
  background: var(--status-success-600);
  color: var(--text-inverse);
  border-color: var(--status-success-600);
}

.btn--success:hover {
  background: var(--status-success-700);
  color: var(--text-inverse);
  border-color: var(--status-success-700);
}

/* Button sizes */
.btn--xs {
  padding: 4px 8px;
  font-size: var(--text-xs);
  gap: 4px;
}

.btn--sm {
  padding: 6px 10px;
  font-size: var(--text-sm);
}

.btn--lg {
  padding: 10px 18px;
  font-size: var(--text-md);
}

.btn--xl {
  padding: 12px 22px;
  font-size: var(--text-lg);
}

/* Button block (full width) */
.btn--block {
  display: flex;
  width: 100%;
}

/* ============================================================================
   8. FORMS
   ============================================================================ */

:root {
  --field-radius: var(--radius-md);
  --field-padding-y: 8px;
  --field-padding-x: 10px;
  --field-bg: var(--bg-elev-1);
  --field-border: var(--border);
  --field-border-focus: var(--accent-primary-500);
  --field-shadow-focus: var(--focus-ring);
  --field-font-size: var(--text-sm);
}

.field {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field:last-child {
  margin-bottom: 0;
}

.inline-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.inline-fields .field {
  flex: 1;
  min-width: 150px;
  margin-bottom: 0;
}

.inline-fields .select {
  width: 100%;
}

.label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-strong);
  display: block;
}

.label--required::after {
  content: " *";
  color: var(--status-danger-500);
}

.input,
.textarea,
.select {
  width: 100%;
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--field-border);
  border-radius: var(--field-radius);
  padding: var(--field-padding-y) var(--field-padding-x);
  font-size: var(--field-font-size);
  font-family: inherit;
  line-height: var(--leading-normal);
  transition: border-color var(--duration-base) var(--ease),
              box-shadow var(--duration-base) var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-subtle);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--border-strong);
}

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

.input:disabled,
.textarea:disabled,
.select:disabled {
  background: var(--bg-elev-2);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Validation states */
.input[aria-invalid="true"],
.textarea[aria-invalid="true"],
.select[aria-invalid="true"] {
  border-color: var(--status-danger-500);
}

.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus {
  box-shadow: var(--focus-ring-danger);
}

/* Input sizes */
.input--sm,
.select--sm {
  padding: 6px 8px;
  font-size: var(--text-xs);
}

.input--lg,
.select--lg {
  padding: 10px 12px;
  font-size: var(--text-base);
}

/* Textarea */
.textarea {
  min-height: 80px;
  resize: vertical;
}

.textarea--sm {
  min-height: 60px;
  padding: 6px 8px;
  font-size: var(--text-xs);
}

.textarea--lg {
  min-height: 120px;
  padding: 10px 12px;
  font-size: var(--text-base);
}

/* Helper text */
.help-text {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin: 0;
}

.error-text {
  font-size: var(--text-xs);
  color: var(--status-danger-600);
  margin: 0;
}

.success-text {
  font-size: var(--text-xs);
  color: var(--status-success-600);
  margin: 0;
}

/* Checkbox and radio */
.checkbox,
.radio {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  margin-bottom: var(--space-3);
}

.checkbox input[type="checkbox"],
.radio input[type="radio"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent-primary-500);
}

.checkbox input[type="checkbox"]:focus-visible,
.radio input[type="radio"]:focus-visible {
  outline: 2px solid var(--accent-primary-500);
  outline-offset: 2px;
}

.checkbox__label,
.radio__label {
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
}

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

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

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

/* Form actions */
.form-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-subtle);
  justify-content: space-between;
}

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

.form-actions--right {
  justify-content: flex-end;
}

.form-actions--center {
  justify-content: center;
}

.form-actions--between {
  justify-content: space-between;
}

/* Page header with back link */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-header > :first-child {
  flex: 1;
  min-width: 0;
}

.page-header__title {
  margin: 0 0 var(--space-2) 0;
}

.page-header__subtitle {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
}

.page-header__back {
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) 0;
  transition: color var(--transition-fast);
}

.page-header__back:hover {
  color: var(--text);
}

.page-header__actions {
  display: flex;
  flex-shrink: 0;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-1);
}

/* Mobile: stack page header vertically with actions above title */
@media (max-width: 767px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header__actions {
    order: -1;
    margin-top: 0;
    margin-bottom: var(--space-3);
  }

  .page-header__back {
    display: none;
  }
}

/* Autocomplete component */
.autocomplete {
  position: relative;
}

.autocomplete__search {
  width: 100%;
}

.autocomplete__results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 300px;
  overflow-y: auto;
}

.autocomplete__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--duration-base) var(--ease);
}

.autocomplete__item:last-child {
  border-bottom: none;
}

.autocomplete__item:hover {
  background: var(--bg-elev-2);
}

.autocomplete__item--create {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent-primary-500);
  font-weight: var(--font-medium);
  border-top: 1px solid var(--border);
  background: var(--bg-elev-2);
}

.autocomplete__item--create:hover {
  background: var(--bg-elev-3);
}

.autocomplete__item-icon {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
}

.autocomplete__item-name {
  font-size: var(--text-sm);
  color: var(--text);
}

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

.autocomplete__empty {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
}

.autocomplete__selected {
  display: none;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.autocomplete__selected-text {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text);
}

.autocomplete__clear {
  flex-shrink: 0;
  padding: var(--space-1);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1;
  transition: color var(--duration-base) var(--ease);
}

.autocomplete__clear:hover {
  color: var(--text);
}

/* Inline create fields */
.autocomplete__create {
  display: none;
  padding: var(--space-4);
  margin-top: var(--space-2);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

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

.autocomplete__create-title {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-strong);
}

.autocomplete__create-cancel {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
}

.autocomplete__create-cancel:hover {
  color: var(--text);
}

/* ============================================================================
   8b. MODAL
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: var(--space-4);
}

.modal {
  background: var(--bg-elev-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - var(--space-8));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.modal__header h3 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
}

.modal__body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
}

.modal__footer {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-4);
  border-top: 1px solid var(--border);
}

/* ============================================================================
   8c. WIZARD-SPECIFIC COMPONENTS
   ============================================================================ */

/* Legacy autocomplete styles for wizard (uses dash instead of BEM) */
.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.autocomplete-item {
  padding: var(--space-3);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: var(--bg-elev-2);
}

.autocomplete-item--empty {
  color: var(--text-muted);
  font-style: italic;
  cursor: default;
}

.autocomplete-item--empty:hover {
  background: transparent;
}

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

/* Selected item display (wizard contacts/orgs) */
.selected-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: var(--space-2);
}

/* Contact row in wizard */
.contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}

.contact-row:last-child {
  margin-bottom: 0;
}

.contact-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ============================================================================
   9. DATA TABLES
   ============================================================================ */

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

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

.table thead {
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
}

.table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: var(--font-semibold);
  font-size: var(--text-xs);
  color: var(--text-strong);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  border-top: 1px solid var(--border-subtle);
}

.table tbody tr:first-child td {
  border-top: none;
}

/* Interactive rows - hover highlight only, links handle navigation */
.table--interactive tbody tr {
  transition: background-color var(--duration-fast) var(--ease);
}

.table--interactive tbody tr:hover {
  background: var(--bg-elev-2);
}

/* Clickable rows with data-href */
.table--interactive tbody tr[data-href] {
  cursor: pointer;
}

/* Compact variant */
.table--compact th,
.table--compact td {
  padding: var(--space-2) var(--space-3);
}

/* Striped variant */
.table--striped tbody tr:nth-child(even) {
  background: var(--bg-elev-2);
}

/* Column alignment */
.table th.align-right,
.table td.align-right {
  text-align: right;
}

.table th.align-center,
.table td.align-center {
  text-align: center;
}

/* Table cell links */
.table__link {
  color: var(--text-strong);
  text-decoration: none;
  font-weight: var(--font-semibold);
}

.table__link:hover {
  color: var(--accent-primary-600);
  text-decoration: underline;
}

.table__link code {
  font-weight: var(--font-semibold);
}

/* Status cell */
.table__status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.table__status--active {
  background: var(--status-success-100);
  color: var(--status-success-700);
}

.table__status--inactive {
  background: var(--neutral-200);
  color: var(--neutral-700);
}

.table__status--warning {
  background: var(--status-warning-100);
  color: var(--status-warning-700);
}

.table__status--danger {
  background: var(--status-danger-100);
  color: var(--status-danger-700);
}

/* Detail grid for displaying key-value pairs */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.detail-item--full {
  grid-column: 1 / -1;
}

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

.detail-value {
  font-weight: var(--font-medium);
}

/* ============================================================================
   10. ALERTS & STATUS
   ============================================================================ */

.alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid;
  display: flex;
  gap: var(--space-3);
  align-items: start;
  margin-bottom: var(--space-4);
}

.alert__icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.alert__content {
  flex: 1;
  min-width: 0;
}

.alert__title {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  margin: 0 0 var(--space-1) 0;
}

.alert__message {
  font-size: var(--text-sm);
  margin: 0;
  line-height: var(--leading-relaxed);
}

/* Alert variants */
.alert--info {
  background: var(--status-info-100);
  border-color: var(--status-info-500);
  color: var(--status-info-700);
}

.alert--success {
  background: var(--status-success-100);
  border-color: var(--status-success-500);
  color: var(--status-success-700);
}

.alert--warning {
  background: var(--status-warning-100);
  border-color: var(--status-warning-500);
  color: var(--status-warning-700);
}

.alert--danger {
  background: var(--status-danger-100);
  border-color: var(--status-danger-500);
  color: var(--status-danger-700);
}

/* Compact variant */
.alert--compact {
  padding: var(--space-3);
}

/* Badge component */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1;
  white-space: nowrap;
}

.badge--primary {
  background: var(--accent-primary-500);
  color: var(--text-inverse);
}

.badge--secondary {
  background: var(--neutral-200);
  color: var(--neutral-700);
}

.badge--success {
  background: var(--status-success-100);
  color: var(--status-success-700);
}

.badge--warning {
  background: var(--status-warning-100);
  color: var(--status-warning-700);
}

.badge--danger {
  background: var(--status-danger-100);
  color: var(--status-danger-700);
}

.badge--info {
  background: var(--status-info-100);
  color: var(--status-info-700);
}

/* ============================================================================
   11. UTILITY CLASSES
   ============================================================================ */

/* Display */
.block { display: block; }
.inline-block { display: inline-block; }
.inline { display: inline; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none; }

/* Flexbox */
.flex-row { flex-direction: row; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }

.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.items-stretch { align-items: stretch; }

.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }

.flex-1 { flex: 1; }
.flex-auto { flex: auto; }
.flex-none { flex: none; }

/* Gap */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }
.gap-10 { gap: var(--space-10); }
.gap-12 { gap: var(--space-12); }

/* Spacing - Margin */
.m-0 { margin: 0; }
.m-1 { margin: var(--space-1); }
.m-2 { margin: var(--space-2); }
.m-3 { margin: var(--space-3); }
.m-4 { margin: var(--space-4); }
.m-6 { margin: var(--space-6); }
.m-8 { margin: 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-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mt-12 { margin-top: var(--space-12); }

.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-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mb-12 { margin-bottom: var(--space-12); }

.ml-0 { margin-left: 0; }
.ml-1 { margin-left: var(--space-1); }
.ml-2 { margin-left: var(--space-2); }
.ml-3 { margin-left: var(--space-3); }
.ml-4 { margin-left: var(--space-4); }
.ml-auto { margin-left: auto; }

.mr-0 { margin-right: 0; }
.mr-1 { margin-right: var(--space-1); }
.mr-2 { margin-right: var(--space-2); }
.mr-3 { margin-right: var(--space-3); }
.mr-4 { margin-right: var(--space-4); }
.mr-auto { margin-right: auto; }

.mx-auto { margin-left: auto; margin-right: auto; }

/* Spacing - Padding */
.p-0 { padding: 0; }
.p-1 { padding: var(--space-1); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

.pt-0 { padding-top: 0; }
.pt-2 { padding-top: var(--space-2); }
.pt-4 { padding-top: var(--space-4); }
.pt-6 { padding-top: var(--space-6); }
.pt-8 { padding-top: var(--space-8); }

.pb-0 { padding-bottom: 0; }
.pb-2 { padding-bottom: var(--space-2); }
.pb-4 { padding-bottom: var(--space-4); }
.pb-6 { padding-bottom: var(--space-6); }
.pb-8 { padding-bottom: var(--space-8); }

.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.px-6 { padding-left: var(--space-6); padding-right: var(--space-6); }

.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.py-6 { padding-top: var(--space-6); padding-bottom: var(--space-6); }

/* Width & Height */
.w-full { width: 100%; }
.w-auto { width: auto; }
.h-full { height: 100%; }
.h-auto { height: auto; }

/* Border */
.border { border: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.border-l { border-left: 1px solid var(--border); }
.border-r { border-right: 1px solid var(--border); }

.rounded { border-radius: var(--radius-md); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }

/* Shadow */
.shadow-xs { box-shadow: var(--shadow-xs); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-none { box-shadow: none; }

/* Opacity */
.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }
.opacity-100 { opacity: 1; }

/* Cursor */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }
.cursor-default { cursor: default; }

/* Overflow */
.overflow-auto { overflow: auto; }
.overflow-hidden { overflow: hidden; }
.overflow-scroll { overflow: scroll; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

/* ============================================================================
   SYSTEM CODE INPUT & ANIMATION
   ============================================================================ */

/* Code input container (input + regenerate button) */
.code-input-container {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  max-width: 240px;
}

/* Special input styling for code field */
.input--code {
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  text-transform: uppercase;
  font-family: 'SF Mono', 'Monaco', 'Consolas', 'Courier New', monospace;
  letter-spacing: 0.25em;
  flex: 1;
  min-width: 0;
}

/* Disabled state during animation */
.input--code:disabled {
  opacity: 0.7;
  cursor: wait;
}

/* Icon button (for regenerate) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-1);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-icon:hover:not(:disabled) {
  background: var(--bg-elev-2);
  border-color: var(--border-strong);
}

.btn-icon:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-icon:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================================
   12. RESPONSIVE
   ============================================================================ */

@media (max-width: 1200px) {
  .container {
    max-width: 100%;
  }
}

@media (max-width: 768px) {
  /* Adjust spacing for mobile */
  .container {
    padding: 0 var(--space-4);
  }

  .section {
    padding: var(--space-8) 0;
  }

  /* Stack form grids on mobile */
  .form-grid,
  .form-grid--3,
  .form-grid--4 {
    grid-template-columns: 1fr;
  }

  /* Adjust card padding */
  .card {
    padding: var(--space-4);
  }

  /* Header adjustments */
  .header__inner {
    padding: var(--space-3) var(--space-4);
  }

  .header__nav {
    gap: var(--space-3);
  }

  /* Responsive typography */
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }

  /* Table horizontal scroll */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Responsive utilities */
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .hide-desktop {
    display: none !important;
  }
}

/* ============================================================================
   ACTIVITY PANEL
   ============================================================================ */

.activity-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.activity-panel__header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.activity-panel__title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
}

.activity-panel__tabs {
  display: flex;
  gap: var(--space-1);
}

.activity-panel__tab {
  padding: var(--space-2) var(--space-4);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.activity-panel__tab:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

.activity-panel__tab--active {
  background: var(--primary);
  color: var(--white);
}

.activity-panel__tab--active:hover {
  background: var(--primary-dark);
  color: var(--white);
}

.activity-panel__content {
  flex: 1;
  min-height: 0; /* Required for flex overflow to work */
  overflow-y: auto;
  padding: var(--space-4);
}

.activity-panel__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.activity-panel__empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
}

.activity-panel__load-more {
  width: 100%;
  margin-bottom: var(--space-4);
}

/* Activity items */
.activity-item {
  padding: var(--space-3);
  background: var(--bg-page);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.activity-item--field_change,
.activity-item--created,
.activity-item--deleted {
  background: transparent;
  border: none;
  padding: var(--space-2) 0;
  border-left: 2px solid var(--border);
  padding-left: var(--space-3);
  margin-left: var(--space-2);
}

.activity-item__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.activity-item__author {
  font-weight: var(--font-medium);
  color: var(--text-strong);
}

.activity-item__action-text {
  color: var(--text-muted);
}

.activity-item__time {
  color: var(--text-subtle);
  font-size: var(--text-xs);
  margin-left: auto;
}

.activity-item__edited {
  font-style: italic;
}

.activity-item__content {
  font-size: var(--text-base);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.activity-item__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
}

.activity-item__like {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-xs);
  transition: all var(--duration-fast);
}

.activity-item__like:hover {
  background: var(--bg-elev-2);
  color: var(--status-danger-600);
}

.activity-item__like--liked {
  color: var(--status-danger-600);
}

.activity-item__like-count {
  font-weight: var(--font-medium);
}

.activity-item__action {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
  padding: var(--space-1);
}

.activity-item__action:hover {
  color: var(--text);
  text-decoration: underline;
}

.activity-item__action--danger:hover {
  color: var(--status-danger-600);
}

/* Field changes */
.activity-item__changes {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-sm);
}

.activity-item__change {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
}

.activity-item__change-field {
  font-weight: var(--font-medium);
  color: var(--text);
  min-width: 80px;
}

.activity-item__change-old {
  color: var(--text-muted);
  text-decoration: line-through;
}

.activity-item__change-arrow {
  color: var(--text-subtle);
}

.activity-item__change-new {
  color: var(--text);
}

/* Comment form */
.activity-panel__form {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.activity-comment-form__input {
  width: 100%;
  padding: var(--space-3);
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  resize: vertical;
  min-height: 60px;
}

.activity-comment-form__input::placeholder {
  color: var(--text-muted);
}

.activity-comment-form__input:focus {
  outline: none;
  border-color: var(--accent-primary-500);
  box-shadow: 0 0 0 3px rgba(0, 156, 182, 0.1);
}

.activity-comment-form__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-2);
}

/* Mention autocomplete */
.activity-panel__form {
  position: relative;
}

.mention-autocomplete {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: max-content;
  min-width: 200px;
  max-width: 280px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  margin-bottom: var(--space-2);
  z-index: 100;
  display: none;
}

.mention-autocomplete--visible {
  display: block;
}

.mention-autocomplete__item {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.mention-autocomplete__item:hover,
.mention-autocomplete__item--selected {
  background: var(--bg-secondary);
}

.mention-autocomplete__name {
  font-weight: 500;
}

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

.mention-autocomplete__empty {
  padding: var(--space-2) var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ============================================================================
   External panel styles (customer conversation)
   ============================================================================ */

/* External panel background tint for visual differentiation */
.activity-panel--external {
  background: linear-gradient(135deg, rgba(0, 156, 182, 0.03) 0%, rgba(0, 156, 182, 0.06) 100%), var(--bg-elev-1);
}

.activity-panel__content--external {
  background: rgba(0, 156, 182, 0.02);
}

/* External tab button styling */
.activity-panel__tab--external {
  background: var(--accent-primary-500);
}

.activity-panel__tab--external:hover {
  background: var(--accent-primary-600);
}

/* External message items */
.external-item {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.external-item--customer {
  background: var(--bg-page);
  border-left: 3px solid var(--text-muted);
}

.external-item--staff {
  background: rgba(0, 156, 182, 0.08);
  border-left: 3px solid var(--accent-primary-500);
}

.external-item--event {
  background: transparent;
  border: none;
  padding: var(--space-2) 0;
  border-left: 2px solid var(--border);
  padding-left: var(--space-3);
  margin-left: var(--space-2);
}

.external-item__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.external-item__author {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--font-medium);
}

.external-item__time {
  font-size: var(--text-xs);
}

.external-item__content {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.external-item__event {
  display: flex;
  gap: var(--space-2);
}

/* External recipient display */
.external-recipient {
  background: var(--bg-page);
  border: 1px solid var(--accent-primary-200);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.external-recipient__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.external-recipient__name {
  font-weight: var(--font-medium);
}

.external-recipient__email {
  color: var(--text-muted);
}

/* External comment form */
.activity-panel__form--external {
  background: rgba(0, 156, 182, 0.04);
  border-top: 1px solid var(--accent-primary-200);
}

.external-comment-form__input {
  width: 100%;
  padding: var(--space-3);
  background: var(--bg-page);
  color: var(--text);
  border: 1px solid var(--accent-primary-200);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  resize: vertical;
  min-height: 80px;
}

.external-comment-form__input::placeholder {
  color: var(--text-muted);
}

.external-comment-form__input:focus {
  outline: none;
  border-color: var(--accent-primary-500);
  box-shadow: 0 0 0 3px rgba(0, 156, 182, 0.15);
}

.external-comment-form__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3);
  gap: var(--space-3);
}

/* External warning message */
.external-warning {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent-primary-600);
  font-size: var(--text-sm);
}

.external-warning svg {
  flex-shrink: 0;
  color: var(--accent-primary-500);
}

/* External send button */
.btn--external {
  background: var(--accent-primary-500);
  color: var(--white);
  border: none;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: background var(--transition-fast);
  white-space: nowrap;
}

.btn--external:hover {
  background: var(--accent-primary-600);
}

.btn--external:active {
  background: var(--accent-primary-700);
}

/* Activity panel mobile layout - form at top, newest first */
@media (max-width: 1023px) {
  /* Move form to top */
  .activity-panel__form {
    order: -1;
    border-top: none;
    border-bottom: 1px solid var(--border);
  }

  /* Make content a flex container to reorder children */
  .activity-panel__content {
    display: flex;
    flex-direction: column;
  }

  /* Reverse activity list (newest first) */
  .activity-panel__list {
    display: flex;
    flex-direction: column-reverse;
  }

  /* Move "Load earlier" button to bottom */
  .activity-panel__load-more {
    order: 1;
    margin-top: var(--space-4);
  }
}

/* Layout with activity panel
   On desktop: main content scrolls with page, activity panel is fixed on the right
   On mobile: panel drops below main content

   Fixed panel positioning calculation:
   - Container is max 1400px centered, so right edge of container from viewport right is:
     max(0, (100vw - 1400px) / 2) + container padding
   - Panel width is 380px
   - We use CSS variables to make this maintainable */
.page-with-activity {
  --panel-width: 380px;
  --panel-gap: var(--space-6);
  display: block;
}

.page-with-activity__main {
  /* On mobile, full width */
}

.page-with-activity__activity {
  /* On mobile, flows naturally below content */
  margin-top: var(--space-6);
  max-height: 500px;
  display: flex;
  flex-direction: column;
}

@media (min-width: 1024px) {
  .page-with-activity {
    /* Reserve space on right for fixed panel */
    padding-right: calc(var(--panel-width) + var(--panel-gap));
  }

  .page-with-activity__main {
    min-width: 0;
  }

  .page-with-activity__activity {
    position: fixed;
    top: 80px; /* Header height + extra spacing */
    /* Position from right: container padding when viewport <= container max-width,
       otherwise account for centred container */
    right: max(var(--space-6), calc((100vw - 1400px) / 2 + var(--space-6)));
    width: var(--panel-width);
    height: calc(100vh - 80px - var(--space-6));
    max-height: none;
    margin-top: 0;
    z-index: 50; /* Above page content, below header/modals */
  }

  /* Centre footer relative to main content pane, not full width */
  .container:has(.page-with-activity) ~ .footer {
    padding-right: calc(380px + var(--space-6));
  }
}

/* ============================================================================
   TICKET DETAIL LAYOUT
   On desktop: left sidebar for ticket details, fixed activity panel on right
   On mobile: stacked layout with panel below main content
   ============================================================================ */

.ticket-layout {
  --panel-width: 380px;
  --panel-gap: var(--space-6);
  display: block;
}

.ticket-layout__main {
  /* On mobile, full width, stacked vertically */
}

.ticket-layout__panel {
  /* On mobile, flows below content */
  margin-top: var(--space-6);
  max-height: 500px;
  display: flex;
  flex-direction: column;
}

.ticket-layout__panel > .activity-panel,
.ticket-layout__panel > .activity-panel--external {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 1024px) {
  .ticket-layout {
    /* Reserve space on right for fixed panel */
    padding-right: calc(var(--panel-width) + var(--panel-gap));
  }

  .ticket-layout__main {
    /* Main content is naturally positioned */
  }

  .ticket-layout__panel {
    position: fixed;
    top: 80px; /* Header height + extra spacing */
    /* Position from right: container padding when viewport <= container max-width,
       otherwise account for centred container */
    right: max(var(--space-6), calc((100vw - 1400px) / 2 + var(--space-6)));
    width: var(--panel-width);
    height: calc(100vh - 80px - var(--space-6));
    max-height: none;
    margin-top: 0;
    z-index: 50; /* Above page content, below header/modals */
  }
}

/* Detail list for ticket metadata */
.detail-list {
  margin: 0;
}

.detail-list__item {
  display: flex;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

.detail-list__item:last-child {
  border-bottom: none;
}

.detail-list__item dt {
  width: 100px;
  flex-shrink: 0;
  font-weight: 500;
  color: var(--text-muted);
}

.detail-list__item dd {
  margin: 0;
}

/* ============================================================================
   HOME PAGE LAYOUT
   ============================================================================ */

.home-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

@media (min-width: 1024px) {
  .home-layout {
    grid-template-columns: 1fr 400px;
  }

  .home-layout__main {
    min-width: 0;
  }

  .home-layout__feed {
    position: sticky;
    top: var(--space-4);
    height: calc(100vh - var(--space-8));
    max-height: 800px;
  }
}

/* Mobile: Feed first */
@media (max-width: 1023px) {
  .home-layout__feed {
    order: -1;
  }
}

/* ============================================================================
   ACTIVITY FEED (Home page global feed)
   ============================================================================ */

.activity-feed {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.activity-feed__header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.activity-feed__title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  margin: 0;
}

.activity-feed__content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

.activity-feed__empty {
  text-align: center;
  padding: var(--space-8);
}

.activity-feed__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Activity feed items */
.activity-feed-item {
  padding: var(--space-3);
  background: var(--bg-page);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.activity-feed-item__context {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.activity-feed-item__entity {
  font-weight: var(--font-medium);
  color: var(--link);
  text-decoration: none;
}

.activity-feed-item__entity:hover {
  text-decoration: underline;
}

.activity-feed-item__entity-type {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.activity-feed-item__entity-type::before {
  content: "·";
  margin-right: var(--space-2);
}

.activity-feed-item__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1);
  font-size: var(--text-sm);
}

.activity-feed-item__author {
  font-weight: var(--font-medium);
  color: var(--text);
}

.activity-feed-item__action {
  color: var(--text-muted);
}

.activity-feed-item__time {
  color: var(--text-subtle);
  font-size: var(--text-xs);
  margin-left: auto;
}

.activity-feed-item__content {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text);
  white-space: pre-wrap;
}

.activity-feed-item__changes {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
}

.activity-feed-item__change {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.activity-feed-item__change-field {
  font-weight: var(--font-medium);
  color: var(--text-muted);
  min-width: 80px;
}

.activity-feed-item__change-old {
  color: var(--text-subtle);
  text-decoration: line-through;
}

.activity-feed-item__change-arrow {
  color: var(--text-subtle);
}

.activity-feed-item__change-new {
  color: var(--text);
}

/* Print styles */
@media print {
  .header,
  .footer,
  .btn,
  .no-print {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .card {
    border: 1px solid #ccc;
    box-shadow: none;
  }
}
