/* ==========================================================================
   CAQA QMS: Design System
   A restrained, professional palette. Light and dark themes share one set of
   custom properties; every text/background pair used for copy meets WCAG 2.2
   AA (4.5:1). Component reference: docs/ui-guide.md.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Type */
  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: Consolas, 'Cascadia Mono', 'SF Mono', Menlo, monospace;

  /* Neutral scale */
  --bg: #ffffff;
  --bg-subtle: #f8f9fa;
  --bg-muted: #f1f3f5;
  --surface: #ffffff;
  --surface-hover: #f1f3f5;
  --border: #e3e6ea;
  --border-strong: #c9cfd6;

  /* Text (all >= 4.5:1 on --bg and --bg-subtle) */
  --text: #1a1d21;
  --text-secondary: #4b5563;
  --text-muted: #5f6b7a;
  --text-on-accent: #ffffff;

  /* Accent: --accent is for text/icons, --accent-solid for filled buttons */
  --accent: #1d4ed8;
  --accent-solid: #2563eb;
  --accent-solid-hover: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-subtle: #eff6ff;
  --accent-border: #bfdbfe;

  /* Semantic: text colours are readable on white and on their subtle tint */
  --success: #047857;
  --success-subtle: #ecfdf5;
  --success-border: #a7f3d0;
  --warning: #a16207;
  --warning-subtle: #fffbeb;
  --warning-border: #fde68a;
  --danger: #b91c1c;
  --danger-solid: #b91c1c;
  --danger-solid-hover: #991b1b;
  --danger-subtle: #fef2f2;
  --danger-border: #fecaca;
  --info: #0e7490;
  --info-subtle: #ecfeff;
  --info-border: #a5f3fc;

  --focus: #1d4ed8;
  --focus-halo: rgba(37, 99, 235, 0.25);

  /* Layout */
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 60px;
  --header-h: 56px;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --target: 24px; /* WCAG 2.2 minimum target size */
}

/* Dark theme tokens (shared by the system preference and the explicit toggle) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117;
    --bg-subtle: #161b22;
    --bg-muted: #1c2128;
    --surface: #161b22;
    --surface-hover: #1c2128;
    --border: #2d333b;
    --border-strong: #444c56;
    --text: #e6edf3;
    --text-secondary: #a3adb8;
    --text-muted: #8b949e;
    --text-on-accent: #ffffff;
    --accent: #7ab3ff;
    --accent-solid: #2563eb;
    --accent-solid-hover: #1d4ed8;
    --accent-hover: #a5cbff;
    --accent-subtle: #0d2847;
    --accent-border: #1e40af;
    --success: #4ade80;
    --success-subtle: #0d2e26;
    --success-border: #155e4a;
    --warning: #fbbf24;
    --warning-subtle: #2e2410;
    --warning-border: #78550e;
    --danger: #f87171;
    --danger-solid: #b91c1c;
    --danger-solid-hover: #991b1b;
    --danger-subtle: #2e1212;
    --danger-border: #7f1d1d;
    --info: #22d3ee;
    --info-subtle: #0d2e35;
    --info-border: #155e75;
    --focus: #93c5fd;
    --focus-halo: rgba(147, 197, 253, 0.35);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-subtle: #161b22;
  --bg-muted: #1c2128;
  --surface: #161b22;
  --surface-hover: #1c2128;
  --border: #2d333b;
  --border-strong: #444c56;
  --text: #e6edf3;
  --text-secondary: #a3adb8;
  --text-muted: #8b949e;
  --text-on-accent: #ffffff;
  --accent: #7ab3ff;
  --accent-solid: #2563eb;
  --accent-solid-hover: #1d4ed8;
  --accent-hover: #a5cbff;
  --accent-subtle: #0d2847;
  --accent-border: #1e40af;
  --success: #4ade80;
  --success-subtle: #0d2e26;
  --success-border: #155e4a;
  --warning: #fbbf24;
  --warning-subtle: #2e2410;
  --warning-border: #78550e;
  --danger: #f87171;
  --danger-solid: #b91c1c;
  --danger-solid-hover: #991b1b;
  --danger-subtle: #2e1212;
  --danger-border: #7f1d1d;
  --info: #22d3ee;
  --info-subtle: #0d2e35;
  --info-border: #155e75;
  --focus: #93c5fd;
  --focus-halo: rgba(147, 197, 253, 0.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button { font-family: inherit; cursor: pointer; color: inherit; }
[hidden] { display: none !important; }
img, svg { max-width: 100%; }
svg.icon { flex-shrink: 0; }

/* ---- Accessibility primitives ---- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; top: -100px; left: 12px;
  z-index: 1000;
  background: var(--accent-solid); color: var(--text-on-accent);
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; color: var(--text-on-accent); outline: 2px solid var(--text-on-accent); outline-offset: 2px; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-halo);
  border-radius: 3px;
}
main:focus-visible { outline: none; box-shadow: none; }
.nav-item:focus-visible, .btn:focus-visible, .topbar-btn:focus-visible { outline-offset: 1px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Minimum target size */
.btn, .topbar-btn, .icon-btn, .nav-item, .tab, .filter-chip-remove,
.pagination-pages a, .cmdk-item, .form-checkbox, .sort-link {
  min-width: var(--target);
  min-height: var(--target);
}

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.2s ease, transform 0.2s ease;
  overflow: hidden;
  z-index: 40;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-org-text,
.sidebar.collapsed .sidebar-logo-text { display: none; }

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand-link { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-height: var(--target); }
.sidebar-brand-link:hover { text-decoration: none; color: var(--text); }
.sidebar-close { display: none; }
.sidebar-logo {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent-solid), #7c3aed);
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sidebar-logo-text { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; white-space: nowrap; }
.sidebar-logo-text span { color: var(--accent); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 16px 12px 6px;
}
.sidebar.collapsed .nav-section-label { text-align: center; padding-left: 0; padding-right: 0; font-size: 9px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 1px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-subtle); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
}
.sidebar-org { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: var(--radius-sm); }
.sidebar-org-avatar {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: var(--bg-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--text-secondary);
  flex-shrink: 0;
}
.sidebar-org-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.sidebar-org-sub { font-size: 11px; color: var(--text-muted); }

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 35; }

/* Main area */
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.menu-btn { display: none; }
/* .topbar-search is both the palette trigger button in the topbar and the legacy
   search container (div + input) still used by module list pages. */
.topbar-search { flex: 1; max-width: 480px; position: relative; }
.topbar-search input {
  width: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px 7px 34px;
  font-size: 13px;
  color: var(--text);
  min-height: 34px;
  transition: border-color 0.12s;
}
.topbar-search input:focus { border-color: var(--focus); }
.topbar-search input::placeholder { color: var(--text-muted); }
button.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px 7px 34px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: left;
  min-height: 34px;
  transition: border-color 0.12s;
}
button.topbar-search:hover { border-color: var(--border-strong); color: var(--text-secondary); }
.topbar-search-text { flex: 1; }
.topbar-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); width: 16px; height: 16px;
  pointer-events: none;
}
.topbar-search kbd, .cmdk kbd {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 10.5px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.topbar-spacer { flex: 1; }
.topbar-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-secondary);
  font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.12s;
  text-decoration: none;
}
.topbar-btn:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.topbar-btn-text { display: none; }
.topbar-user { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.topbar-user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-solid), #7c3aed);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-moon { display: inline; }
[data-theme="dark"] .theme-icon-sun { display: none; }

.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center;
  padding: 4px;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.content { padding: 24px 28px; max-width: 1400px; width: 100%; }
.content-full { padding: 0; }

/* Plain (logged-out) pages */
.plain-page { display: flex; flex-direction: column; min-height: 100vh; }
.plain-header { height: var(--header-h); display: flex; align-items: center; padding: 0 24px; border-bottom: 1px solid var(--border); }
.plain-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px 20px; }

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.page-subtitle { font-size: 13.5px; color: var(--text-secondary); margin: 3px 0 0; }
.page-header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 10px; flex-wrap: wrap; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin: 0; }

/* ---- Breadcrumb ---- */
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.breadcrumb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.breadcrumb-item + .breadcrumb-item::before { content: '/'; opacity: 0.5; margin-right: 6px; }
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb-sep { opacity: 0.5; }
.breadcrumb-current { color: var(--text); font-weight: 500; }
/* legacy inline breadcrumb markup (a / span / span) */
.breadcrumb > a, .breadcrumb > span { display: inline; }
.breadcrumb > .breadcrumb-sep { margin: 0 6px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
  background: transparent;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent-solid); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-solid-hover); color: var(--text-on-accent); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger-solid); color: #fff; }
.btn-danger:hover { background: var(--danger-solid-hover); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-lg { padding: 10px 18px; font-size: 14.5px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.inline-form { display: inline; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0; }
.card-body { padding: 18px; }
.card-body-tight { padding: 0; }

/* ---- Stat cards (legacy) and widget tiles ---- */
.stat-grid, .widget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card, .widget-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.12s, box-shadow 0.12s;
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
}
.stat-card:hover, a.widget-tile:hover { border-color: var(--accent-border); box-shadow: var(--shadow-sm); text-decoration: none; color: inherit; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value, .widget-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.1; }
.stat-trend { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }
.stat-icon { width: 32px; height: 32px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }

.widget-tile { border-left: 4px solid var(--border-strong); }
.widget-tile.tone-ok { border-left-color: var(--success); }
.widget-tile.tone-warn { border-left-color: var(--warning); }
.widget-tile.tone-critical { border-left-color: var(--danger); }
.widget-tile.tone-neutral { border-left-color: var(--border-strong); }
.widget-unavailable { background: var(--bg-subtle); color: var(--text-secondary); }
.widget-unavailable .widget-value { font-size: 18px; color: var(--text-muted); }
.widget-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.widget-title { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin: 0; line-height: 1.4; }
.widget-hint { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; }
.attention-strip { margin-bottom: 24px; }
.attention-strip .widget-tile { background: var(--bg-subtle); }
.widget-section { margin-bottom: 8px; }

/* ---- Calendar strip ---- */
.calendar-list { list-style: none; margin: 0; padding: 0; display: flex; overflow-x: auto; gap: 0; }
.calendar-item {
  flex: 0 0 auto; min-width: 200px; max-width: 280px;
  padding: 14px 16px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
  border-top: 3px solid var(--border-strong);
}
.calendar-item:last-child { border-right: none; }
.calendar-item.tone-ok { border-top-color: var(--success); }
.calendar-item.tone-warn { border-top-color: var(--warning); }
.calendar-item.tone-critical { border-top-color: var(--danger); }
.calendar-date { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); font-weight: 600; }
.calendar-label a { color: var(--text); font-weight: 500; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table tbody td, .data-table tbody th { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; text-align: left; }
.data-table tbody th { font-weight: 500; }
.data-table tbody tr { transition: background 0.08s; }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td, .data-table tbody tr:last-child th { border-bottom: none; }
.data-table a { color: var(--text); font-weight: 500; }
.data-table a:hover { color: var(--accent); }
.data-table .text-right { text-align: right; }

.data-table.compact thead th { padding: 7px 12px; font-size: 11px; }
.data-table.compact tbody td, .data-table.compact tbody th { padding: 6px 12px; }
.data-table.compact { font-size: 12.5px; }

/* Sortable header: link inside th so it is keyboard operable */
th.sortable { user-select: none; }
th.sortable .sort-link { color: inherit; font-weight: inherit; display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; }
th.sortable .sort-link:hover { color: var(--text); text-decoration: none; }
th[aria-sort="ascending"] .sort-indicator::after { content: '\2191'; }
th[aria-sort="descending"] .sort-indicator::after { content: '\2193'; }
th[aria-sort="none"] .sort-indicator::after { content: '\2195'; opacity: 0.45; }
th.sorted-asc::after { content: ' \2191'; }
th.sorted-desc::after { content: ' \2193'; }
th.sortable[aria-sort].sorted-asc::after, th.sortable[aria-sort].sorted-desc::after { content: none; }

/* ---- Badges and chips (text always carries the meaning) ---- */
.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-success, .chip-ok      { background: var(--success-subtle); color: var(--success); border-color: var(--success-border); }
.badge-warning, .chip-warn    { background: var(--warning-subtle); color: var(--warning); border-color: var(--warning-border); }
.badge-danger, .chip-critical { background: var(--danger-subtle);  color: var(--danger);  border-color: var(--danger-border); }
.badge-info, .chip-info       { background: var(--info-subtle);    color: var(--info);    border-color: var(--info-border); }
.badge-neutral, .chip-neutral { background: var(--bg-muted); color: var(--text-secondary); border-color: var(--border); }
.badge-accent                 { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent-border); }

/* Status dot: decorative only; always pair with text */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-dot.success { background: var(--success); }
.status-dot.warning { background: var(--warning); }
.status-dot.danger  { background: var(--danger); }
.status-dot.neutral { background: var(--text-muted); }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 5px; }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-label .hint { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.vetis-tag { font-family: var(--font-mono); font-size: 10.5px; background: var(--bg-muted); color: var(--text-muted); padding: 1px 5px; border-radius: 3px; margin-left: 6px; }
.form-label .new-tag { font-size: 10px; background: var(--success-subtle); color: var(--success); padding: 1px 6px; border-radius: 3px; margin-left: 6px; font-weight: 600; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  min-height: 36px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--focus); }
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }
.form-input.error, .form-select.error, .form-textarea.error, [aria-invalid="true"] { border-color: var(--danger); }
.form-error { font-size: 12.5px; color: var(--danger); margin-top: 4px; font-weight: 500; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-checkbox { width: 18px; height: 18px; min-width: 18px; min-height: 18px; margin: 3px; accent-color: var(--accent-solid); }
.form-check-label { font-size: 13.5px; }
.form-fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 18px; min-width: 0; }
.form-legend { font-size: 13px; font-weight: 600; padding: 0 6px; }

.error-summary {
  border: 1px solid var(--danger); border-left-width: 4px;
  background: var(--danger-subtle);
  border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 18px;
}
.error-summary-title { font-size: 14px; font-weight: 600; margin: 0 0 6px; color: var(--danger); }
.error-summary-list { margin: 0; padding-left: 18px; font-size: 13.5px; }
.error-summary-list a { color: var(--danger); text-decoration: underline; font-weight: 500; }

/* ---- Filter bar ---- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.filter-search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.filter-input { padding-left: 34px; }
.filter-select { width: auto; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  padding: 3px 8px 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.filter-chip button, .filter-chip-remove {
  background: none; border: none; color: inherit; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
}
.filter-chip button:hover, .filter-chip-remove:hover { background: var(--accent-border); text-decoration: none; }

/* ---- Tabs ---- */
.tabs { margin-bottom: 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs-list { list-style: none; margin: 0; padding: 0; display: flex; gap: 2px; }
.tabs[role="tablist"] { display: flex; gap: 2px; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; margin-bottom: -1px;
  border: 1px solid transparent; border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-secondary); font-size: 13.5px; font-weight: 500;
  background: transparent; white-space: nowrap; text-decoration: none;
}
.tab:hover { color: var(--text); background: var(--surface-hover); text-decoration: none; }
.tab.active, .tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-count { padding: 0 6px; font-size: 11px; }
.tabpanel { padding-top: 4px; }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  background: var(--bg-muted);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.empty-state h2, .empty-state h3, .empty-state-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.empty-state p { font-size: 13.5px; margin: 0 0 16px; max-width: 420px; margin-left: auto; margin-right: auto; color: var(--text-secondary); }

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  gap: 12px;
  flex-wrap: wrap;
}
.pagination-info { color: var(--text-muted); }
.pagination-pages { display: flex; gap: 2px; list-style: none; margin: 0; padding: 0; }
.pagination-pages a, .pagination-pages span {
  min-width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  padding: 0 8px;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.pagination-pages a:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.pagination-pages .current { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent-border); font-weight: 600; }

/* ---- Timeline (status events) ---- */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute; left: -24px; top: 4px;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px var(--border);
}
.timeline-dot.success { background: var(--success); box-shadow: 0 0 0 2px var(--success-border); }
.timeline-dot.info { background: var(--accent); box-shadow: 0 0 0 2px var(--accent-border); }
.timeline-dot.warning { background: var(--warning); box-shadow: 0 0 0 2px var(--warning-border); }
.timeline-dot.neutral { background: var(--text-muted); }
.timeline-date { font-size: 12px; color: var(--text-muted); }
.timeline-title { font-size: 13.5px; font-weight: 600; margin: 2px 0 2px; }
.timeline-note { font-size: 12.5px; color: var(--text-secondary); }

/* ---- Wizard ---- */
.wizard-steps { display: flex; align-items: center; gap: 0; margin-bottom: 28px; overflow-x: auto; }
.wizard-step { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.wizard-step-num {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  background: var(--bg-muted); color: var(--text-muted);
  border: 1px solid var(--border); flex-shrink: 0;
}
.wizard-step.active .wizard-step-num { background: var(--accent-solid); color: #fff; border-color: var(--accent-solid); }
.wizard-step.active { color: var(--text); }
.wizard-step.done .wizard-step-num { background: var(--success); color: #fff; border-color: var(--success); }
.wizard-step.done { color: var(--text-secondary); }
.wizard-step-line { width: 32px; height: 2px; background: var(--border); margin: 0 6px; flex-shrink: 0; }
.wizard-step.done + .wizard-step-line { background: var(--success); }

/* ---- Command palette ---- */
.cmdk-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 0;
}
.cmdk {
  width: 100%; max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.cmdk-input-wrap { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.cmdk-input-wrap svg { color: var(--text-muted); flex-shrink: 0; }
.cmdk-input { flex: 1; border: none; background: transparent; font-size: 15px; color: var(--text); font-family: inherit; min-height: 28px; }
.cmdk-input:focus-visible { outline: none; box-shadow: none; }
.cmdk-input::placeholder { color: var(--text-muted); }
.cmdk-results { max-height: 380px; overflow-y: auto; padding: 6px; }
.cmdk-group-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 10px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); }
.cmdk-item:hover, .cmdk-item[aria-selected="true"] { background: var(--accent-subtle); color: var(--accent); }
.cmdk-item-icon { color: var(--text-muted); flex-shrink: 0; }
.cmdk-item[aria-selected="true"] .cmdk-item-icon { color: var(--accent); }
.cmdk-item-label { font-size: 13.5px; font-weight: 500; }
.cmdk-item-hint { font-size: 11.5px; color: var(--text-muted); margin-left: auto; }
.cmdk-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13.5px; margin: 0; }

/* ---- Dialog ---- */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  padding: 20px 22px;
  width: min(92vw, 520px);
  box-shadow: var(--shadow-lg);
}
dialog.modal-sm { width: min(92vw, 420px); }
dialog.modal-lg { width: min(92vw, 760px); }
dialog.modal::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-title { font-size: 16px; font-weight: 600; margin: 0; }
.modal-desc { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 14px; }
.modal-body { font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---- Skeleton loader ---- */
.skeleton { background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-subtle) 50%, var(--bg-muted) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---- Toast and flash ---- */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; z-index: 200; max-width: min(92vw, 420px);
  animation: slideUp 0.2s;
}
.toast.toast-ok { border-left-color: var(--success); }
.toast.toast-warn { border-left-color: var(--warning); }
.toast.toast-critical { border-left-color: var(--danger); }
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); border-left-width: 4px;
  background: var(--bg-subtle); font-size: 13.5px;
}
.flash-kind { font-weight: 600; }
.flash-text { flex: 1; }
.flash-ok { border-left-color: var(--success); background: var(--success-subtle); }
.flash-ok .flash-kind { color: var(--success); }
.flash-warn { border-left-color: var(--warning); background: var(--warning-subtle); }
.flash-warn .flash-kind { color: var(--warning); }
.flash-critical { border-left-color: var(--danger); background: var(--danger-subtle); }
.flash-critical .flash-kind { color: var(--danger); }
.flash-info { border-left-color: var(--info); background: var(--info-subtle); }
.flash-info .flash-kind { color: var(--info); }
.flash-dismiss { margin: -4px -4px -4px 0; }

/* ---- Error pages ---- */
.error-page { max-width: 560px; margin: 6vh auto; text-align: center; }
.error-code { font-family: var(--font-mono); font-size: 56px; font-weight: 700; color: var(--border-strong); margin: 0 0 4px; line-height: 1; }
.error-title { font-size: 24px; font-weight: 700; margin: 0 0 10px; letter-spacing: -0.02em; }
.error-message { color: var(--text-secondary); font-size: 14.5px; margin: 0 0 18px; }
.error-page .error-summary { text-align: left; }
.error-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---- Utility ---- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 13px; } .text-xs { font-size: 12px; } .text-lg { font-size: 16px; }
.font-medium { font-weight: 500; } .font-semibold { font-weight: 600; } .font-bold { font-weight: 700; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.text-center { text-align: center; }
.font-mono { font-family: var(--font-mono); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.hidden { display: none; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 1100px) {
  .topbar-btn-text { display: inline; }
}

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .topbar-user-name { display: none; }
}

/* Under 900px the sidebar becomes an off-canvas drawer opened by the menu button. */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    height: 100vh; height: 100dvh;
    width: min(84vw, 300px) !important;
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .sidebar-org-text,
  .sidebar.collapsed .sidebar-logo-text { display: initial; }
  .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 8px 12px; }
  .sidebar.collapsed .nav-section-label { text-align: left; padding: 16px 12px 6px; font-size: 11px; }
  .sidebar-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .collapse-btn { display: none; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .grid-2, .grid-3, .responsive-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header-actions { justify-content: flex-start; }
  .stat-grid, .widget-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .topbar-search { max-width: none; }
  .topbar-search kbd { display: none; }
}

@media (max-width: 600px) {
  .stat-grid, .widget-grid { grid-template-columns: 1fr; }
  .topbar-search-text { font-size: 12.5px; }
  .filter-search { max-width: none; }
  .pagination { flex-direction: column; align-items: flex-start; }
  dialog.modal { padding: 16px; }
}

/* Legacy breakpoint kept for templates that still target it */
@media (max-width: 768px) {
  .sidebar.mobile-open { transform: translateX(0); }
}

@media (prefers-contrast: more) {
  :root { --border: #8b95a1; --border-strong: #4b5563; }
  .btn-secondary, .form-input, .form-select, .form-textarea { border-width: 2px; }
}

@media print {
  .sidebar, .topbar, .skip-link, .cmdk-overlay, .toast, .flash-stack, .no-print, .page-header-actions, .filter-bar, .pagination { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card, .widget-tile { break-inside: avoid; }
}

.list-plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
