/* ─── InspectoQMS Design System ─────────────────────────────────────────── */

/* CSS custom properties — dark mode is the default */
:root {
  /* Backgrounds */
  --bg:           #0b0f1a;
  --bg-elevated:  #111827;
  --bg-raised:    #1a2233;
  --sidebar-bg:   #0d1321;

  /* Interactive states (sidebar) */
  --nav-hover:    rgba(255, 255, 255, 0.05);
  --nav-active:   rgba(59, 130, 246, 0.14);
  --nav-active-border: #3b82f6;

  /* Borders */
  --border:       rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* Card/input aliases (used by several page-level templates) */
  --card-bg:      var(--bg-elevated);
  --card-border:  var(--border);
  --input-bg:     var(--bg-raised);

  /* Text */
  --text-primary:   rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted:     rgba(255, 255, 255, 0.32);

  /* Brand / accent */
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim:   rgba(59, 130, 246, 0.15);

  /* Semantic colors */
  --success:      #10b981;
  --success-dim:  rgba(16, 185, 129, 0.12);
  --warning:      #f59e0b;
  --warning-dim:  rgba(245, 158, 11, 0.12);
  --danger:       #ef4444;
  --danger-dim:   rgba(239, 68, 68, 0.12);
  --info:         #06b6d4;
  --info-dim:     rgba(6, 182, 212, 0.12);

  /* Shadows */
  --shadow:     0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 4px 10px -5px rgba(0, 0, 0, 0.5);

  /* Layout */
  --sidebar-width:  240px;
  --topbar-height:  56px;
  --content-max:    1400px;

  /* Radius */
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Code", "Consolas", "Fira Code", monospace;
  --font-size-base: 14px;
}

/* Light theme overrides (applied via JS toggle on <html data-theme="light">) */
[data-theme="light"] {
  --bg:           #f1f5f9;
  --bg-elevated:  #ffffff;
  --bg-raised:    #f8fafc;
  --sidebar-bg:   #1e293b;       /* sidebar stays dark */

  --nav-hover:    rgba(255, 255, 255, 0.06);
  --nav-active:   rgba(255, 255, 255, 0.12);

  --border:        rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);

  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  --shadow:    0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);
}


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

html { font-size: var(--font-size-base); -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

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

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

input, textarea, select, button { font-family: inherit; font-size: inherit; }


/* ─── App Shell ──────────────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Main area: topbar + content */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ─── Global Search ──────────────────────────────────────────────────────── */
.topbar-search {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 34px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 32px 0 32px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.search-kbd {
  position: absolute;
  right: 8px;
  font-size: 10px;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 5px;
  pointer-events: none;
  line-height: 16px;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 0;
}

.sr-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 8px 12px 3px;
}

.sr-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  text-decoration: none;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.1s;
}

.sr-item:hover,
.sr-item--active {
  background: var(--nav-hover);
}

.sr-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-raised);
  border-radius: 6px;
  font-size: 13px;
  color: var(--accent);
  flex-shrink: 0;
}

.sr-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sr-label {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.sr-empty {
  padding: 16px 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* Light mode overrides */
[data-theme="light"] .search-input {
  background: #f8fafc;
}

[data-theme="light"] .search-dropdown {
  background: #ffffff;
}

/* Content */
.content {
  flex: 1;
  padding: 28px 32px;
  max-width: var(--content-max);
  width: 100%;
}

/* Auth layout (login page — no sidebar) */
.auth-wrapper {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}


/* ─── Sidebar Components ─────────────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand-icon {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand-icon i {
  color: #fff;
  font-size: 13px;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-brand-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-brand-tagline {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 0 16px;
}

.nav-section {
  margin-bottom: 4px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 16px 4px;
}

/* Collapsible nav sections */
.nav-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 4px;
  cursor: pointer;
  user-select: none;
  border-radius: 0;
  transition: color 0.15s;
}

.nav-section-toggle:hover {
  color: var(--text-secondary);
}

.nav-section-toggle .nav-section-label {
  padding: 0;
  margin: 0;
}

.nav-section-chevron {
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.nav-section-toggle.collapsed .nav-section-chevron {
  transform: rotate(-90deg);
}

.nav-section-items {
  overflow: hidden;
  max-height: 600px;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  opacity: 1;
}

.nav-section-items.collapsed {
  max-height: 0;
  opacity: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 450;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  border-left: 2px solid transparent;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--nav-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--nav-active);
  color: var(--accent);
  border-left-color: var(--nav-active-border);
  font-weight: 500;
}

.nav-item i {
  width: 16px;
  text-align: center;
  font-size: 13px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active i,
.nav-item:hover i {
  opacity: 1;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: capitalize;
}


/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}


/* ─── KPI / Stat Cards ────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
}

.stat-value.accent   { color: var(--accent); }
.stat-value.success  { color: var(--success); }
.stat-value.warning  { color: var(--warning); }
.stat-value.danger   { color: var(--danger); }

.stat-meta {
  font-size: 12px;
  color: var(--text-secondary);
}


/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--nav-hover);
  color: var(--text-primary);
}

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { padding: 7px; width: 32px; height: 32px; }


/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

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

.form-control {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-control::placeholder { color: var(--text-muted); }

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

select.form-control {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.form-error {
  font-size: 11px;
  color: var(--danger);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 8px;
}

/* Checkbox */
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-check-label {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}


/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

tr:last-child td { border-bottom: none; }

tbody tr:hover td {
  background: var(--nav-hover);
  color: var(--text-primary);
}

.table-link {
  color: var(--accent);
  font-weight: 500;
}

.table-link:hover { color: var(--accent-hover); }

.table-empty {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}


/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-success  { background: var(--success-dim); color: var(--success); }
.badge-warning  { background: var(--warning-dim); color: var(--warning); }
.badge-danger   { background: var(--danger-dim);  color: var(--danger); }
.badge-info     { background: var(--info-dim);    color: var(--info); }
.badge-accent   { background: var(--accent-dim);  color: var(--accent); }
.badge-muted    { background: var(--bg-raised);   color: var(--text-muted); border: 1px solid var(--border); }


/* ─── Alerts / Flash messages ────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  border-left: 3px solid;
}

.alert-success  { background: var(--success-dim); border-color: var(--success); color: var(--success); }
.alert-warning  { background: var(--warning-dim); border-color: var(--warning); color: var(--warning); }
.alert-danger, .alert-error  { background: var(--danger-dim);  border-color: var(--danger);  color: var(--danger); }
.alert-info     { background: var(--info-dim);    border-color: var(--info);    color: var(--info); }

.alert-text { color: var(--text-primary); }

.flash-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}


/* ─── Page Header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-header-text p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.page-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}


/* ─── Utilities ──────────────────────────────────────────────────────────── */
.text-primary    { color: var(--text-primary) !important; }
.text-secondary  { color: var(--text-secondary) !important; }
.text-muted      { color: var(--text-muted) !important; }
.text-accent     { color: var(--accent) !important; }
.text-success    { color: var(--success) !important; }
.text-warning    { color: var(--warning) !important; }
.text-danger     { color: var(--danger) !important; }

.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.text-sm  { font-size: 12px; }
.text-xs  { font-size: 11px; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mt-4 { margin-top: 28px; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.mb-4 { margin-bottom: 28px; }

.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 20px; }

.d-flex   { display: flex; }
.d-grid   { display: grid; }
.d-none   { display: none !important; }
.d-block  { display: block !important; }

.align-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

.w-full { width: 100%; }

.mono { font-family: var(--font-mono); font-size: 12px; }

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

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


/* ─── Topbar icon buttons ────────────────────────────────────────────────── */
.topbar-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.topbar-btn:hover {
  background: var(--nav-hover);
  color: var(--text-primary);
}

/* User pill in topbar */
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}

.user-pill:hover {
  background: var(--nav-hover);
}

.user-pill-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
}

.user-pill-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

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

.user-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: #1e2a3a;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,.5), 0 2px 8px rgba(0,0,0,.3);
  z-index: 200;
  overflow: hidden;
  color: rgba(255,255,255,0.9);
}

.user-dropdown-menu.open {
  display: block;
}

.user-dropdown-header {
  padding: 12px 16px 10px;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  transition: background .12s;
}

.user-dropdown-item i {
  width: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.user-dropdown-item:hover {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
}

.user-dropdown-item--danger {
  color: var(--danger);
}

.user-dropdown-item--danger i {
  color: var(--danger);
}

.user-dropdown-item--danger:hover {
  background: rgba(239,68,68,.08);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.vdivider {
  width: 1px;
  height: 20px;
  background: var(--border);
}


/* ─── Auth page specific ─────────────────────────────────────────────────── */
.auth-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  text-align: center;
  margin-bottom: 32px;
}

.auth-brand-icon {
  width: 48px;
  height: 48px;
  background: var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.auth-brand-icon i {
  color: #fff;
  font-size: 20px;
}

.auth-brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.auth-brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}


/* ─── Sidebar toggle button (hamburger) ──────────────────────────────────── */
.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.sidebar-toggle:hover {
  background: var(--nav-hover);
  color: var(--text-primary);
}

/* ─── Sidebar overlay ────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

/* Tablet and mobile — sidebar becomes a drawer */
@media (max-width: 1024px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 300;
  }

  .sidebar.open { transform: translateX(0); }

  .app-main { margin-left: 0; }
}

/* Tablet — moderate adjustments */
@media (max-width: 900px) {
  .content { padding: 20px 20px; }

  .page-header-actions { flex-wrap: wrap; }

  .chart-grid { grid-template-columns: 1fr !important; }
}

/* Mobile */
@media (max-width: 640px) {
  /* Topbar */
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-search { display: none; }
  .user-pill-name { display: none; }
  .page-title { font-size: 14px; }

  /* Content */
  .content { padding: 14px 12px; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-text h1 { font-size: 18px; }
  .page-header-actions { width: 100%; flex-wrap: wrap; }

  /* Forms */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  /* Stats and KPIs */
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .kpi-card { min-width: calc(50% - 8px); }

  /* Charts */
  .chart-grid { grid-template-columns: 1fr !important; }

  /* Tables — ensure scroll */
  .table-wrapper { -webkit-overflow-scrolling: touch; }

  /* Inline 2-col and 3-col grids used in detail pages */
  .responsive-grid { grid-template-columns: 1fr !important; }
}

/* Small mobile */
@media (max-width: 400px) {
  .kpi-card { min-width: 100%; }
  .stat-grid { grid-template-columns: 1fr; }
  .btn { font-size: 12px; padding: 6px 10px; }
}


/* ─── KPI cards (metrics page) ───────────────────────────────────────────── */
.kpi-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-card {
  flex: 1;
  min-width: 120px;
  padding: 16px 20px;
  text-align: center;
  transition: box-shadow 0.15s, transform 0.15s;
}

a.kpi-card:hover {
  box-shadow: 0 0 0 2px var(--primary);
  transform: translateY(-1px);
  cursor: pointer;
}

/* ─── Toggle switch ─────────────────────────────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 5px;
  line-height: 1.4;
}
