/* ============================================
   ISO 9001 QMS — Design System
   Additive Manufacturing Quality Management
   ============================================ */

/* ---------- Typography ----------
   The Google Fonts @import that used to live here was removed (§9.10 / §4.2).
   It sent every user's IP address to a third party on every page load, it
   blocked first render behind a cross-origin request, and it made the app fail
   in an air-gapped shop — which is a realistic deployment for a machine shop.

   The stack below resolves entirely on-device. The brand typeface (Geist, as
   used on the main site) will be self-hosted as part of the UI revamp; see
   BRAND.md. Nothing here reaches the network. */

/* ---------- CSS Custom Properties ---------- */
:root {
  color-scheme: light;
  accent-color: var(--brand-primary);

  /* Brand Colors — Light Theme */
  --brand-primary: #4f46e5;
  --brand-primary-light: #6366f1;
  --brand-primary-dark: #3730a3;
  --brand-primary-glow: rgba(79, 70, 229, 0.15);
  --brand-secondary: #0891b2;
  --brand-accent: #d97706;

  /* Semantic Colors — Light Theme */
  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-info: #3b82f6;
  --color-info-bg: #eff6ff;

  /* Surface Colors — Light Theme */
  --bg-base: #f8fafc;
  --bg-surface-1: #ffffff;
  --bg-surface-2: #f1f5f9;
  --bg-surface-3: #e2e8f0;
  --bg-elevated: #ffffff;
  --bg-hover: rgba(79, 70, 229, 0.04);
  --bg-active: rgba(79, 70, 229, 0.08);

  /* Glass — Light Theme */
  --glass-bg: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(79, 70, 229, 0.08);
  --glass-blur: 16px;

  /* Text — Light Theme */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --text-inverse: #ffffff;

  /* Borders — Light Theme */
  --border-subtle: rgba(0, 0, 0, 0.03);
  --border-default: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.12);
  --border-focus: var(--brand-primary);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

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

  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.3125rem;
  --text-2xl: 1.625rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;

  /* Shadows — Light Theme */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 10px 30px rgba(79, 70, 229, 0.06);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Sidebar & Layout */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 68px;
  --topbar-height: 64px;

  /* Scrollbar & Overlay */
  --scrollbar-thumb: rgba(0, 0, 0, 0.12);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.2);
  --overlay-bg: rgba(15, 23, 42, 0.3);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");

  /* Risk Cells */
  --risk-low-bg: rgba(16, 185, 129, 0.12);
  --risk-low-text: #065f46;
  --risk-med-bg: rgba(245, 158, 11, 0.12);
  --risk-med-text: #92400e;
  --risk-high-bg: rgba(239, 68, 68, 0.12);
  --risk-high-text: #991b1b;
  --risk-crit-bg: rgba(239, 68, 68, 0.25);
  --risk-crit-text: #7f1d1d;
}

/* ---------- Dark Theme Overrides ---------- */
.dark-theme {
  color-scheme: dark;

  /* Brand Colors — Dark Theme */
  --brand-primary: #6366f1;
  --brand-primary-light: #818cf8;
  --brand-primary-dark: #4f46e5;
  --brand-primary-glow: rgba(99, 102, 241, 0.35);
  --brand-secondary: #06b6d4;
  --brand-accent: #f59e0b;

  /* Semantic Colors — Dark Theme */
  --color-success: #10b981;
  --color-success-bg: rgba(16, 185, 129, 0.12);
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.12);
  --color-danger: #ef4444;
  --color-danger-bg: rgba(239, 68, 68, 0.12);
  --color-info: #3b82f6;
  --color-info-bg: rgba(59, 130, 246, 0.12);

  /* Surface Colors — Dark Theme */
  --bg-base: #0a0a1a;
  --bg-surface-1: #111128;
  --bg-surface-2: #1a1a3e;
  --bg-surface-3: #222255;
  --bg-elevated: #252560;
  --bg-hover: rgba(99, 102, 241, 0.08);
  --bg-active: rgba(99, 102, 241, 0.15);

  /* Glass — Dark Theme */
  --glass-bg: rgba(17, 17, 40, 0.65);
  --glass-border: rgba(99, 102, 241, 0.18);
  --glass-blur: 20px;

  /* Text — Dark Theme */
  --text-primary: #f0f0ff;
  --text-secondary: #a0a0c8;
  --text-tertiary: #6b6b99;
  --text-inverse: #0a0a1a;

  /* Borders — Dark Theme */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);

  /* Shadows — Dark Theme */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 40px var(--brand-primary-glow);

  /* Scrollbar & Overlay */
  --scrollbar-thumb: rgba(255, 255, 255, 0.12);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);
  --overlay-bg: rgba(0, 0, 0, 0.6);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0c8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");

  /* Risk Cells */
  --risk-low-bg: rgba(16, 185, 129, 0.25);
  --risk-low-text: var(--color-success);
  --risk-med-bg: rgba(245, 158, 11, 0.25);
  --risk-med-text: var(--color-warning);
  --risk-high-bg: rgba(239, 68, 68, 0.25);
  --risk-high-text: var(--color-danger);
  --risk-crit-bg: rgba(239, 68, 68, 0.5);
  --risk-crit-text: #ff8080;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-base);
  background-image: radial-gradient(var(--border-default) 1px, transparent 1px);
  background-size: 24px 24px;
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  height: 100dvh; /* mobile browsers size 100vh to the max viewport (address bar hidden),
                     clipping the bottom of the page behind the bar when it's showing */
}

a {
  color: var(--brand-primary-light);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--brand-primary); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ---------- App Layout ---------- */
.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-base), min-width var(--transition-base);
  z-index: 100;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  font-weight: 800;
  color: white;
  box-shadow: var(--shadow-glow);
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}
.sidebar-brand-text span:first-child {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}
.sidebar-brand-text span:last-child {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  letter-spacing: 0.3px;
}

.sidebar.collapsed .sidebar-brand-text { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) var(--space-sm);
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: var(--space-md) var(--space-sm) var(--space-xs);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-section-label {
  font-size: 0;
  padding: var(--space-sm) 0;
  text-align: center;
}
.sidebar.collapsed .sidebar-section-label::after {
  content: '•••';
  font-size: var(--text-xs);
  display: block;
  text-align: center;
  color: var(--text-tertiary);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  margin-bottom: 2px;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateX(4px);
}
.nav-item.active {
  background: var(--bg-active);
  color: var(--brand-primary);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 50%;
  background: linear-gradient(180deg, var(--brand-primary), var(--brand-secondary));
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
}

.nav-item-label {
  font-size: var(--text-sm);
  font-weight: 500;
}
.sidebar.collapsed .nav-item-label { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: var(--space-sm); }

.nav-item-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: white;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}
.sidebar.collapsed .nav-item-badge { display: none; }

.sidebar-toggle {
  padding: var(--space-md);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
}
.sidebar-toggle button {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-xs);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  font-size: var(--text-lg);
}
.sidebar-toggle button:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ---------- Main Content Area ---------- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ---------- Top Bar ---------- */
.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  z-index: 50;
}

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

.topbar-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}
.topbar-breadcrumb span { color: var(--text-secondary); }

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

/* Search Bar */
.search-bar {
  position: relative;
  width: 280px;
}
.search-bar input {
  width: 100%;
  padding: var(--space-sm) var(--space-md) var(--space-sm) 36px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
  outline: none;
}
.search-bar input::placeholder { color: var(--text-tertiary); }
.search-bar input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-glow);
  background: var(--bg-surface-3);
}
.search-bar-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  pointer-events: none;
}

/* Top Bar Buttons */
.topbar-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  transition: all var(--transition-fast);
  position: relative;
}
.topbar-btn:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary-light);
  background: var(--bg-hover);
}
.topbar-btn .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: var(--color-danger);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-base);
}

/* ---------- Notification Dropdown ---------- */
.notif-wrapper {
  position: relative;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 370px;
  max-height: 440px;
  background: var(--bg-surface-1);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 250;
  display: flex;
  flex-direction: column;
  animation: notifSlideIn 0.2s ease-out;
}
.notif-dropdown.hidden { display: none; }

@keyframes notifSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.notif-dropdown-header {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.notif-dropdown-title {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--text-primary);
  letter-spacing: 0.02em;
}
.notif-dropdown-body {
  overflow-y: auto;
  padding: var(--space-xs);
  flex: 1;
}
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
}
.notif-item:hover {
  background: var(--bg-surface-2);
}
.notif-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.notif-item-dot.danger  { background: var(--color-danger); }
.notif-item-dot.warning { background: var(--color-warning); }
.notif-item-dot.info    { background: var(--color-info); }
.notif-item-content {
  flex: 1;
  min-width: 0;
}
.notif-item-text {
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: 1.4;
}
.notif-item-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}
.notif-item-dismiss {
  flex-shrink: 0;
  align-self: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.notif-item-dismiss:hover {
  background: var(--color-success-bg, rgba(34,197,94,0.12));
  color: var(--color-success, #16a34a);
  border-color: var(--color-success, #16a34a);
}
.notif-empty {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--text-tertiary);
}
.notif-empty-icon {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-xs);
}
.notif-empty-text {
  font-size: var(--text-sm);
}

/* ---------- Content Area ---------- */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-xl);
}

/* ---------- Glass Card ---------- */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition-base);
}
.card:hover {
  border-color: rgba(99, 102, 241, 0.25);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}
.card-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}
.card-subtitle {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
}

/* ---------- KPI Cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.kpi-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--kpi-color, var(--brand-primary)), transparent);
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(99, 102, 241, 0.3);
}

.kpi-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  margin-bottom: var(--space-md);
  background: var(--kpi-bg, var(--bg-surface-2));
  color: var(--kpi-color, var(--brand-primary));
}

.kpi-card-value {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-card-label {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
  font-weight: 500;
}

.kpi-card-trend {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-xs);
  font-weight: 600;
  margin-top: var(--space-sm);
}
.kpi-card-trend.up { color: var(--color-success); }
.kpi-card-trend.down { color: var(--color-danger); }

/* ---------- Tables ---------- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
}

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

thead {
  background: var(--bg-surface-2);
  position: sticky;
  top: 0;
  z-index: 5;
}

th {
  padding: var(--space-md) var(--space-md);
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}
th:hover { color: var(--text-primary); }
th.sorted { color: var(--brand-primary-light); }

td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

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

td.primary-cell {
  color: var(--text-primary);
  font-weight: 500;
}

/* ---------- Status Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-neutral { background: var(--bg-surface-3); color: var(--text-secondary); }
.badge-primary { background: rgba(99, 102, 241, 0.15); color: var(--brand-primary-light); }

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.5;
}
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
  color: white;
  border-color: var(--brand-primary);
  box-shadow: 0 2px 8px var(--brand-primary-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--brand-primary-light), var(--brand-primary));
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--brand-primary-glow);
}

.btn-secondary {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.btn-secondary:hover {
  background: var(--bg-surface-3);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

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

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: var(--color-danger);
  color: white;
}

.btn-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: rgba(16, 185, 129, 0.3);
}
.btn-success:hover {
  background: var(--color-success);
  color: white;
}

.btn-sm { padding: 4px 10px; font-size: var(--text-xs); }
.btn-lg { padding: var(--space-md) var(--space-lg); font-size: var(--text-base); }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-group {
  display: flex;
  gap: var(--space-sm);
}

/* ---------- Forms ---------- */

/*
 * `.form-section` is a <fieldset>, and carried no rule of its own — so every
 * long form drew the user agent's default `2px groove` box in a colour no
 * stylesheet chose (#efefef light, #6b6b6b dark). It ignored the theme, it was
 * the only border on the site not taken from a token, and nested inside the
 * form card it read as a stray outline around the inputs.
 *
 * The grouping is still real and still worth keeping — it is what makes the
 * <legend> mean something to a screen reader — so the box goes and the legend
 * becomes a visible heading instead. `min-width: 0` is not optional: a fieldset
 * defaults to `min-width: min-content`, which stops it shrinking inside a flex
 * or grid parent and lets wide fields push the form wider than the viewport.
 */
.form-section {
  border: 0;
  min-width: 0;
  margin: 0 0 var(--space-xl);
  padding: 0;
}
.form-section:last-of-type {
  margin-bottom: 0;
}
.form-section > legend {
  /* A legend is not in the normal flow while it belongs to a bordered
     fieldset; `float: left` + a full-width sibling clear puts it back, which
     is what lets it act as an ordinary heading above the fields. */
  float: left;
  width: 100%;
  padding: 0;
  margin-bottom: var(--space-md);
  font-size: var(--text-lg);
  font-weight: 650;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.form-section > legend + * {
  clear: both;
}
/* Second and later groups get a hairline above them, so the sections still
   read as separate without each one being boxed in. */
.form-section + .form-section > legend {
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-subtle);
}

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

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}
.form-label .required {
  color: var(--color-danger);
  margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
  outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-glow);
  background: var(--bg-surface-3);
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-tertiary); }

.form-input.error { border-color: var(--color-danger); }
.form-input.success { border-color: var(--color-success); }

.form-select {
  appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.form-select option {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: var(--space-xs);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
}

.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-surface-3);
  border-radius: var(--radius-full);
  transition: var(--transition-fast);
  cursor: pointer;
  border: 1px solid var(--border-default);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: var(--transition-fast);
}
.toggle input:checked + .toggle-slider {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: white;
}

/* File Drop Zone */
.dropzone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl) var(--space-xl);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  background: var(--bg-surface-1);
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--brand-primary);
  background: var(--bg-hover);
  box-shadow: 0 0 20px var(--brand-primary-glow);
}
.dropzone-icon {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-md);
  opacity: 0.4;
}
.dropzone-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.dropzone-text strong {
  color: var(--brand-primary-light);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-surface-1);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-bounce);
}
.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
}
.modal-title {
  font-size: var(--text-xl);
  font-weight: 700;
}
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-surface-2);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  transition: all var(--transition-fast);
}
.modal-close:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.modal-body {
  padding: var(--space-xl);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--border-subtle);
}

/* Wide modal variant */
.modal.modal-wide {
  max-width: 960px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-lg);
}
.tab {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-sans);
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--brand-primary-light);
  border-bottom-color: var(--brand-primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- Stage Pipeline ---------- */
.pipeline {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
  padding-bottom: var(--space-sm);
}

.pipeline-stage {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border-default);
  color: var(--text-tertiary);
  background: var(--bg-surface-1);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.pipeline-stage:hover { border-color: var(--border-strong); color: var(--text-secondary); }
.pipeline-stage.active {
  background: var(--brand-primary);
  color: white;
  border-color: var(--brand-primary);
  box-shadow: 0 2px 8px var(--brand-primary-glow);
}
.pipeline-stage.completed {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: rgba(16, 185, 129, 0.3);
}
.pipeline-stage.failed {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.pipeline-arrow {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  min-width: 16px;
  text-align: center;
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--text-tertiary);
}
.empty-state-icon {
  margin-bottom: var(--space-md);
}
.empty-state-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}
.empty-state-text {
  font-size: var(--text-sm);
  margin-bottom: var(--space-lg);
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Notification Toast ---------- */
.toast-container {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-sm);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-surface-2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 450px;
  animation: slideInRight var(--transition-bounce) forwards;
  backdrop-filter: blur(var(--glass-blur));
}
.toast.toast-exit {
  animation: slideOutRight var(--transition-base) forwards;
}
.toast-success { border-left: 3px solid var(--color-success); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-danger { border-left: 3px solid var(--color-danger); }
.toast-info { border-left: 3px solid var(--color-info); }

.toast-icon { font-size: var(--text-xl); }
.toast-body { flex: 1; }
.toast-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}
.toast-message {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}
.toast-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--space-xs);
  font-size: var(--text-sm);
}

/* ---------- Risk Matrix ---------- */
.risk-overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}
.risk-matrix-grid {
  display: grid;
  grid-template-columns: auto repeat(5, 1fr);
  gap: 3px;
  font-size: var(--text-xs);
  text-align: center;
}

.risk-matrix {
  display: grid;
  grid-template-columns: auto repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr) auto;
  gap: 2px;
  width: 100%;
  max-width: 500px;
}

.risk-matrix-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.risk-matrix-cell:hover { transform: scale(1.05); }
.risk-low { background: var(--risk-low-bg); color: var(--risk-low-text); }
.risk-medium { background: var(--risk-med-bg); color: var(--risk-med-text); }
.risk-high { background: var(--risk-high-bg); color: var(--risk-high-text); }
.risk-critical { background: var(--risk-crit-bg); color: var(--risk-crit-text); }

.risk-matrix-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 600;
}

/* ---------- Activity Feed ---------- */
.activity-feed {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.activity-item {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.activity-item:hover { background: var(--bg-hover); }

.activity-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  margin-top: 6px;
}
.activity-dot.success { background: var(--color-success); }
.activity-dot.warning { background: var(--color-warning); }
.activity-dot.danger { background: var(--color-danger); }
.activity-dot.info { background: var(--color-info); }

.activity-content { flex: 1; }
.activity-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.activity-text strong { color: var(--text-primary); }
.activity-time {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--border-default);
  background: var(--bg-surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.filter-chip:hover { border-color: var(--brand-primary); color: var(--text-primary); }
.filter-chip.active {
  background: var(--bg-active);
  border-color: var(--brand-primary);
  color: var(--brand-primary-light);
}

/* ---------- Section Divider ---------- */
.section-divider {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin: var(--space-xl) 0;
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}
.section-divider span {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ---------- Checklist ---------- */
.checklist {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.checklist-item:hover { background: var(--bg-hover); }
.checklist-item.checked { opacity: 0.5; }
.checklist-item.checked .checklist-text { text-decoration: line-through; }
.checklist-text {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ---------- Animations ---------- */
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animate-fade-in { animation: fadeIn var(--transition-base) forwards; }
.animate-fade-in-up { animation: fadeInUp var(--transition-base) forwards; }
.animate-pulse { animation: pulse 2s infinite; }

/*
  Staggered child animations — deliberately no longer staggered.

  Each child started at `opacity: 0` and faded in over 400ms behind a delay of
  up to 300ms, re-running on every route change and every remote write. The
  effect was a wave of half-visible cards for the best part of a second: a
  screenshot of the dashboard routinely caught two KPI tiles washed out and a
  third missing, which is what it looked like to use as well.

  Two things were wrong with it. The visible one is that it made a static page
  feel like it was still loading. The dangerous one is that `opacity: 0` was
  the *initial* state, so any child past the sixth — or any child whose
  animation was interrupted by a re-render mid-flight — stayed invisible with
  no way back.

  One short fade on the container replaces it. Content is never invisible
  waiting for an animation that may not arrive.
*/
/*
  No entrance animation on the children at all. The first attempt at fixing
  this kept a short fade with `animation-fill-mode: both` — which still applies
  the `from { opacity: 0 }` keyframe *before* the animation starts, so the
  tiles were still transparent at the moment they were rendered. Any fade whose
  start state is invisible has the same hazard; the only version that cannot
  strand content is not having one.

  The container still fades (`.animate-fade-in` on #content), which is enough
  to soften a route change without any individual card being able to get stuck.
*/
.stagger-children > * { animation: none; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-muted { color: var(--text-tertiary); }
.font-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  /*
    This block used to squeeze the sidebar to a 68px rail and hide
    .nav-item-label, .sidebar-section-label and the badges — turning forty
    navigation entries into forty unlabelled glyphs with no tooltip, at every
    window between 768px and 1024px. A user reported, correctly, that it was
    impossible to navigate.

    The rail is gone. Tablets get the same off-canvas drawer phones get (see
    css/brand.css §8.2), which is labelled. Nothing below now hides a label.
  */
  .form-row-3,
  .form-row-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .content { padding: var(--space-md); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row-2,
  .form-row-3,
  .form-row-4 { grid-template-columns: 1fr; }
  .topbar { padding: 0 var(--space-md); }
  .pipeline { flex-wrap: wrap; }

  /* Flex items default to min-width:auto, so a footer with 2-3 buttons whose labels sum wider
     than the modal (common with actions like "Remove from Bay" / "View Full Record") never
     shrinks — it overflows past the card edge instead. Stack full-width on narrow screens. */
  .modal-footer {
    flex-direction: column-reverse;
  }

  /* Stack the risk matrix above the summary and let it use the full width */
  .risk-overview-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  /* Scale the matrix down so all 5×5 cells + labels fit the viewport */
  .risk-matrix-grid {
    gap: 2px;
    font-size: 9px;
    grid-template-columns: minmax(0, auto) repeat(5, minmax(0, 1fr));
  }
  /* Allow the cells to shrink below their intrinsic size on small screens */
  .risk-matrix-grid .risk-matrix-cell {
    font-size: 10px;
    padding: 2px !important;
    min-width: 0;
    border-radius: var(--radius-sm);
  }
}

/* ---------- Firebase Auth & Syncing Overlays ---------- */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-base);
  z-index: 1000;
  display: none;
}
.auth-overlay.active {
  display: block;
}

.auth-split-container {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Left Hero Panel */
.auth-hero-panel {
  position: relative;
  background: linear-gradient(135deg, #0f172a 0%, #030712 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-3xl) var(--space-2xl);
  overflow: hidden;
  z-index: 1;
}

.auth-hero-glow {
  position: absolute;
  top: -20%;
  left: -20%;
  width: 140%;
  height: 140%;
  background: radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.15) 0%, rgba(8, 145, 178, 0.08) 35%, transparent 70%);
  z-index: -1;
  pointer-events: none;
  animation: authGlowPulse 15s ease-in-out infinite alternate;
}

@keyframes authGlowPulse {
  0% { transform: scale(1) rotate(0deg); }
  100% { transform: scale(1.05) rotate(5deg); }
}

.auth-hero-brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.auth-hero-logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  font-weight: 800;
  color: white;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.auth-hero-brand-text {
  display: flex;
  flex-direction: column;
}

.auth-hero-brand-text .brand-name {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.auth-hero-brand-text .brand-tag {
  font-size: var(--text-xs);
  color: #94a3b8;
  opacity: 0.8;
  letter-spacing: 0.5px;
}

/* Slideshow / Carousel */
.auth-hero-carousel {
  position: relative;
  height: 220px;
  margin: auto 0;
}

.carousel-slide {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.8s ease-in-out, visibility 0.8s ease-in-out, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  transform: translateY(10px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.carousel-slide.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.slide-icon {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-md);
}

.slide-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-sm);
  background: linear-gradient(to right, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.slide-text {
  font-size: var(--text-base);
  color: #94a3b8;
  line-height: 1.6;
}

/* Stats Ticker */
.auth-hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: var(--space-xl);
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: 800;
  color: #ffffff;
  background: linear-gradient(135deg, #ffffff 0%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: var(--text-xs);
  color: #64748b;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Right Form Panel */
.auth-form-panel {
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  position: relative;
}

/* Theme Toggle inside login screen */
.auth-theme-toggle {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-1);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  z-index: 10;
  font-size: var(--text-base);
}

.auth-theme-toggle:hover {
  background: var(--bg-surface-2);
  border-color: var(--brand-primary);
  transform: scale(1.05);
}

/* Modern auth card */
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  animation: fadeInUp var(--transition-base) forwards;
}

.auth-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.auth-card .auth-icon {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-3xl);
  color: white;
  margin-bottom: var(--space-sm);
  box-shadow: var(--shadow-glow);
}

.auth-card .auth-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
}

.auth-card .auth-subtitle {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  line-height: 1.5;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.auth-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  display: none;
}

/* Form group input wrapper with icons */
.input-icon-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  pointer-events: none;
}

.input-icon-wrapper .form-input {
  width: 100%;
  padding-left: 38px !important;
}

/* Checkbox and link alignments */
.form-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-sm);
  margin-top: 4px;
  margin-bottom: 8px;
}

.forgot-link {
  color: var(--brand-primary-light);
  cursor: pointer;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.forgot-link:hover {
  color: var(--brand-primary);
  text-decoration: underline;
}

/* Custom Checkbox */
.checkbox-container {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-left: 24px;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkbox-checkmark {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  height: 16px;
  width: 16px;
  background-color: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.checkbox-container:hover input ~ .checkbox-checkmark {
  border-color: var(--brand-primary);
}

.checkbox-container input:checked ~ .checkbox-checkmark {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
}

.checkbox-checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkbox-checkmark:after {
  display: block;
}

.checkbox-container .checkbox-checkmark:after {
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-label {
  color: var(--text-secondary);
}

/* Divider styled */
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  margin: var(--space-sm) 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
}

.auth-divider::before {
  margin-right: .5em;
}

.auth-divider::after {
  margin-left: .5em;
}

/* SSO Buttons styling */
.sso-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.btn-sso {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background: var(--bg-surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 10px var(--space-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-sso:hover {
  background: var(--bg-surface-2);
  border-color: var(--brand-primary-light);
  box-shadow: var(--shadow-sm);
}

.sso-icon {
  width: 18px;
  height: 18px;
}

/* Switch styled link */
.auth-switch {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.auth-switch a {
  color: var(--brand-primary);
  font-weight: 600;
  cursor: pointer;
  transition: color var(--transition-fast);
}

.auth-switch a:hover {
  color: var(--brand-primary-light);
  text-decoration: underline;
}

/* Responsive auth adjustments */
@media (max-width: 1024px) {
  .auth-split-container {
    grid-template-columns: 1fr;
  }
  .auth-hero-panel {
    display: none;
  }
}

/* Syncing Overlay */
.syncing-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-base);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}
.syncing-overlay.active {
  display: flex;
}
.syncing-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  max-width: 360px;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.syncing-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}
.syncing-text {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  line-height: 1.5;
}

/* ---------- Sidebar User Widget ---------- */
.sidebar-user {
  padding: var(--space-md);
  border-top: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.01);
  transition: all var(--transition-base);
}
.dark-theme .sidebar-user {
  background: rgba(255, 255, 255, 0.01);
}
.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-primary-glow);
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-sm);
  border: 1px solid var(--glass-border);
}
.sidebar-user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-user-email {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.sidebar-user-role {
  color: var(--text-tertiary);
  font-size: 10px;
  /* Now carries "Operator · jane@company.com" once a name is set, so it has to
     truncate rather than push the sign-out button out of the sidebar. */
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.sidebar-user-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-xs);
}
.btn-signout {
  background: none;
  border: none;
  color: var(--color-danger);
  cursor: pointer;
  padding: 2px 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.btn-signout:hover {
  background: var(--color-danger-bg);
}
.sidebar.collapsed .sidebar-user {
  padding: var(--space-sm) 0;
  align-items: center;
}
.sidebar.collapsed .sidebar-user-details,
.sidebar.collapsed .sidebar-user-actions {
  display: none;
}

/* An alert that tells you something is overdue and cannot be acted on is a
   dead end; each one now leads to the work it is about. */
.activity-item-actionable { cursor: pointer; }
.activity-item-actionable:hover { background: var(--surface-sunken, var(--bg-tertiary)); }

/* ---------- QR Scan Module ---------- */
.qr-video-wrap {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-default);
  background: #000;
}
.qr-video-wrap video,
.qr-video-wrap canvas {
  width: 100% !important;
  border-radius: var(--radius-lg);
}
.qr-live-feedback {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-md) auto 0;
  max-width: 320px;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-success-bg);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-md);
  font-family: monospace;
  font-size: var(--text-sm);
  color: var(--color-success);
  word-break: break-all;
}
.qr-live-feedback.hidden { display: none; }
.qr-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
  animation: qr-pulse 1s infinite;
}
@keyframes qr-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.qr-capture-btn {
  /*
   * Flex, not a block with a <br>. `.qms-icon` is `display: block` — deliberate,
   * for the nav rows — and a block-level SVG ignores `text-align: center`, so it
   * pinned to the left edge of the circle while the label centred underneath it.
   * Centring the icon needs a layout that centres boxes, not text.
   */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin: var(--space-lg) auto 0;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 4px solid var(--bg-surface-1);
  outline: 2px solid var(--brand-primary);
  background: var(--brand-primary);
  color: white;
  font-size: var(--text-xs);
  line-height: 1.4;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.qr-capture-btn .qms-icon { margin-top: 0; }
.qr-capture-btn:disabled {
  background: var(--bg-surface-2);
  outline-color: var(--border-default);
  color: var(--text-tertiary);
  cursor: not-allowed;
}
.qr-capture-btn:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px var(--brand-primary-glow);
}
.qr-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}
.qr-action-grid .btn {
  flex-direction: column;
  padding: var(--space-lg) var(--space-sm);
  line-height: 1.6;
  font-size: var(--text-sm);
}
.qr-content-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  font-size: var(--text-sm);
}

/*
 * The rework moved this module off inline styles. Every screen was built with
 * `style="max-width:480px;margin:0 auto"` and friends repeated inline, which
 * is both unmaintainable and part of what keeps `'unsafe-inline'` in the CSP's
 * style-src.
 */
.qr-screen {
  max-width: 480px;
  margin: 0 auto;
}

/* The hero blocks and action grids are centred; a form inside the same card is
   not — a centred field label reads as a heading and detaches from its input. */
.qr-card { text-align: center; }
.qr-card .form-group,
.qr-card .card-header { text-align: left; }
.qr-card-title { font-size: var(--text-base); }
.qr-hero { padding-bottom: 0; }

.qr-back { margin-bottom: var(--space-sm); }

.qr-primary-btn,
.qr-secondary-btn {
  width: 100%;
  justify-content: center;
  padding: var(--space-md);
  margin-top: var(--space-sm);
}
.qr-primary-btn { font-size: var(--text-lg); margin-top: var(--space-md); }

.qr-footer-actions {
  text-align: center;
  margin-top: var(--space-md);
}

.qr-loading {
  text-align: center;
  padding: var(--space-2xl) 0;
}
.qr-loading .spinner { margin: 0 auto var(--space-md); }

.qr-hint { text-align: center; margin-top: var(--space-sm); }

/*
 * A failed camera start used to be a toast that vanished, on a screen that had
 * already dropped to manual entry — so the reason was gone before you could
 * read it. It is now stated in place, next to the thing you are being asked to
 * do instead, and stays until you act on it.
 */
.qr-error {
  display: flex;
  gap: var(--space-sm);
  text-align: left;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  border: 1px solid var(--status-warning-fg);
  border-radius: var(--radius-md);
  background: var(--color-warning-bg, var(--surface-sunken));
}
.qr-error-icon { color: var(--status-warning-fg); flex: 0 0 auto; display: flex; }
.qr-error-title { font-weight: 650; margin-bottom: 0.15rem; }
.qr-error-text { font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.5; }
.qr-retry { margin-top: var(--space-sm); }

.qr-contents,
.qr-bulk-list { text-align: left; }

.qr-content-row-clickable { cursor: pointer; }
.qr-content-row-clickable:hover { background: var(--surface-sunken, var(--bg-tertiary)); }
/* The name takes the slack; the id never shrinks. On a phone the timestamp is
   longer than the space left over, so rather than squeezing the name into two
   words per line it drops to its own line underneath. */
.qr-content-row { flex-wrap: wrap; }
.qr-content-name { flex: 1 1 8rem; min-width: 0; text-align: left; }
.qr-content-row .badge { flex: 0 0 auto; }
.qr-content-when { flex: 0 0 auto; margin-left: auto; }

@media (max-width: 480px) {
  .qr-content-when {
    flex-basis: 100%;
    margin-left: 0;
    padding-left: calc(var(--space-sm) + 3.5rem);
  }
}
.qr-content-when {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
}
.qr-tick { color: var(--status-success-fg); display: flex; }

/* The action tiles carry an icon above their label, so the label needs to be
   its own element rather than a bare text node after a <br>. */
.qr-action-grid .btn > span { display: block; }

.qr-label-preview { text-align: center; }
.qr-label-name { margin-top: var(--space-sm); font-weight: 700; font-size: var(--text-lg); }
.qr-label-code { color: var(--text-tertiary); font-family: monospace; }


