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

/* ════════════════════════════════════════════
   DESIGN TOKENS — dark mode default
   ════════════════════════════════════════════ */
:root {
  --sidebar-w: 232px;
  --sidebar-w-sm: 58px;
  --globalbar-h: 48px;

  /* Sidebar always stays brand-dark in both modes */
  --sidebar-bg: #1a0808;
  --sidebar-hover: rgba(239,68,68,0.1);
  --sidebar-active-bg: rgba(220,38,38,0.18);
  --sidebar-active-border: #f87171;
  --sidebar-text: #9ca3af;

  /* App chrome */
  --primary: #dc2626;
  --primary-hover: #b91c1c;
  --bg: #0d1117;
  --card: #161b22;
  --card-raised: #1c2128;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --border: #30363d;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #dc2626;

  color-scheme: dark;
}

/* ════════════════════════════════════════════
   LIGHT MODE OVERRIDES
   ════════════════════════════════════════════ */
html[data-theme="light"] {
  /* Sidebar keeps brand-dark look */
  --sidebar-bg: #1a0808;
  --sidebar-hover: rgba(239,68,68,0.13);
  --sidebar-active-bg: rgba(220,38,38,0.22);
  --sidebar-active-border: #f87171;
  --sidebar-text: #c4a0a0;

  /* App chrome goes light */
  --primary: #dc2626;
  --primary-hover: #b91c1c;
  --bg: #f0f2f5;
  --card: #ffffff;
  --card-raised: #f3f4f6;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #d1d5db;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;

  color-scheme: light;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: width 0.22s cubic-bezier(.4,0,.2,1);
  overflow-x: hidden;
  overflow-y: visible;
}

.sidebar-logo {
  padding: 4px 10px 4px 16px;
  height: 68px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

.logo-text-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  transition: opacity 0.15s, width 0.22s;
}

.logo-name {
  display: block;
  font-size: 14.5px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.logo-sub {
  display: block;
  font-size: 9.5px;
  font-weight: 500;
  color: var(--sidebar-text);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
  white-space: nowrap;
}

.nav-toggle-btn {
  width: 28px;
  height: 28px;
  min-width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.07);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--sidebar-text);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.nav-toggle-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }
.nav-toggle-btn svg { transition: transform 0.22s cubic-bezier(.4,0,.2,1); }

/* ── Collapsed state ── */
html.nav-collapsed .sidebar { width: var(--sidebar-w-sm); }
html.nav-collapsed .main   { margin-left: var(--sidebar-w-sm); }
html.nav-collapsed .logo-text-wrap { opacity: 0; width: 0; flex: none; overflow: hidden; }
html.nav-collapsed .nav-toggle-btn svg { transform: rotate(180deg); }
html.nav-collapsed .nav-text { display: none; }
html.nav-collapsed .nav-badge { display: none; }
html.nav-collapsed .nav-section { display: none; }
html.nav-collapsed .nav-link {
  justify-content: center;
  padding: 10px 0;
}
html.nav-collapsed .nav-icon { width: var(--sidebar-w-sm); justify-content: center; }
html.nav-collapsed .sidebar-user { display: none; }
html.nav-collapsed .sidebar-footer { padding: 12px 0; align-items: center; justify-content: center; }
html.nav-collapsed .nav-divider { margin: 6px 8px; }
html.nav-collapsed .theme-toggle-label { display: none !important; }
html.nav-collapsed .theme-toggle-btn {
  padding: 8px;
  width: 36px;
  margin: 0 auto 8px;
  justify-content: center;
}

/* keep toggle button centered and visible when collapsed */
html.nav-collapsed .sidebar-logo {
  padding: 0;
  justify-content: center;
  gap: 0;
}
html.nav-collapsed .sidebar-fp-logo { display: none; }
html.nav-collapsed .sidebar-patch-logo { display: none; }

/* Sidebar logo image */
.sidebar-fp-logo {
  flex: 1;
  min-width: 0;
  max-height: 51px;
  width: auto;
  object-fit: contain;
  object-position: left center;
}

.sidebar-patch-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 50%;
}

/* Tooltip labels in collapsed mode — use CSS vars so they adapt to light mode */
html.nav-collapsed .nav-link { position: relative; }
html.nav-collapsed .nav-link::after {
  content: attr(data-title);
  position: absolute;
  left: calc(var(--sidebar-w-sm) + 4px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 200;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
html.nav-collapsed .nav-link:hover::after { opacity: 1; }
html[data-theme="light"].nav-collapsed .nav-link::after {
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.sidebar-nav {
  flex: 1;
  padding: 10px 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-section {
  padding: 12px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.28);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active {
  background: var(--sidebar-active-bg);
  border-left-color: var(--sidebar-active-border);
  color: #fff;
  font-weight: 700;
}

.nav-icon { width: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-text { flex: 1; }

.nav-badge {
  margin-left: auto;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  line-height: 1.6;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 6px 20px;
}

.nav-sub-link {
  padding: 6px 20px 6px 36px;
  font-size: 13px;
  font-weight: 400;
  opacity: 0.85;
}
.nav-sub-link:hover { opacity: 1; }
.nav-sub-link.active { opacity: 1; font-weight: 600; }
html.nav-collapsed .nav-sub-link { padding: 6px 0; justify-content: center; }

/* ── Sidebar footer ── */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.sidebar-user {
  font-size: 13px;
  color: var(--sidebar-text);
  margin-top: 8px;
}
.sidebar-user strong {
  display: block;
  color: #fff;
  font-size: 14px;
  margin-bottom: 1px;
}

/* ── Theme toggle button (sidebar) ── */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px;
  cursor: pointer;
  color: var(--sidebar-text);
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,0.13); color: #fff; }

/* Moon visible in dark, hidden in light */
.theme-icon-moon { display: block; flex-shrink: 0; }
.theme-icon-sun  { display: none;  flex-shrink: 0; }
html[data-theme="light"] .theme-icon-moon { display: none; }
html[data-theme="light"] .theme-icon-sun  { display: block; }

/* Labels swap with theme */
.theme-label-dark  { display: inline; }
.theme-label-light { display: none; }
html[data-theme="light"] .theme-label-dark  { display: none; }
html[data-theme="light"] .theme-label-light { display: inline; }

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.22s cubic-bezier(.4,0,.2,1);
}

/* ── Global bar ── */
.globalbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  padding: 0 20px;
  height: var(--globalbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 60;
  flex-shrink: 0;
}

.globalbar-search {
  flex: 1;
  max-width: 480px;
  position: relative;
  display: flex;
  align-items: center;
}

.globalbar-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.globalbar-search-form { flex: 1; }

.globalbar-search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px 7px 32px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.globalbar-search-input::placeholder { color: var(--text-muted); }
.globalbar-search-input:focus {
  background: var(--card-raised);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.15);
}
html[data-theme="light"] .globalbar-search-input:focus { background: #fff; }

/* ── Search Dropdown ── */
.search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 999;
  overflow: hidden;
}
.search-dropdown.active { display: block; }
html[data-theme="light"] .search-dropdown { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }

.search-drop-section { padding: 4px 0; }
.search-drop-section + .search-drop-section { border-top: 1px solid var(--border); }

.search-drop-label {
  padding: 6px 14px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.search-drop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  transition: background 0.1s;
}
.search-drop-item:hover { background: var(--card-raised); }

.search-drop-main { flex: 1; min-width: 0; }
.search-drop-main > div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-drop-item-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-drop-footer {
  display: block;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  transition: background 0.1s;
}
.search-drop-footer:hover { background: var(--card-raised); }

.search-drop-empty {
  padding: 16px 14px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Globalbar right ── */
.globalbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Data Utilities dropdown ── */
.util-menu { position: relative; }

.util-trigger-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  background: var(--card-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.util-trigger-btn:hover { background: var(--border); color: var(--text); }
.util-trigger-btn[aria-expanded="true"] { color: var(--text); background: var(--border); }
.util-chevron { transition: transform 0.18s; opacity: 0.7; }
.util-trigger-btn[aria-expanded="true"] .util-chevron { transform: rotate(180deg); }

.util-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  min-width: 178px;
  z-index: 1000;
  overflow: hidden;
}
html[data-theme="light"] .util-dropdown { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
.util-dropdown.open { display: block; }

.util-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.1s;
}
.util-dropdown a:hover { background: var(--card-raised); }
.util-dropdown a + a { border-top: 1px solid var(--border); }
.util-dropdown svg { color: var(--text-muted); flex-shrink: 0; }

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

.user-chip-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 4px 6px 4px 10px;
  transition: background 0.15s, border-color 0.15s;
}
.user-chip-btn:hover { background: var(--card-raised); border-color: var(--border); }
.user-chip-btn[aria-expanded="true"] { background: var(--card-raised); border-color: var(--border); }

.user-chip-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-initial {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  min-width: 210px;
  z-index: 1000;
  overflow: hidden;
}
html[data-theme="light"] .user-dropdown { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
.user-dropdown.open { display: block; }

.user-dropdown-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--card-raised);
}
.user-dropdown-name { font-size: 14px; font-weight: 700; color: var(--text); }
.user-dropdown-role { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.user-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.1s;
}
.user-dropdown a:hover { background: var(--card-raised); }
.user-dropdown a + a { border-top: 1px solid var(--border); }
.user-dropdown a svg { color: var(--text-muted); flex-shrink: 0; }
.user-dropdown a.sign-out { color: #f87171; }
.user-dropdown a.sign-out svg { color: #f87171; }
html[data-theme="light"] .user-dropdown a.sign-out { color: #dc2626; }
html[data-theme="light"] .user-dropdown a.sign-out svg { color: #dc2626; }

/* ── Notification bell ── */
.notif-menu { position: relative; }

.notif-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--card-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.notif-btn:hover { background: var(--border); color: var(--text); }

.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 17px;
  height: 17px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  pointer-events: none;
}

.notif-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-width: calc(100vw - 24px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
  z-index: 200;
  overflow: hidden;
}
html[data-theme="light"] .notif-dropdown { box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
.notif-dropdown.open { display: block; }

.notif-drop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
}

.notif-dismiss-all-btn {
  font-size: 11px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 4px;
  transition: background 0.1s, color 0.1s;
}
.notif-dismiss-all-btn:hover { background: var(--border); color: var(--text); }

.notif-list { max-height: 400px; overflow-y: auto; }

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

.notif-item {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.notif-item:last-child { border-bottom: none; }

.notif-item-link {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 11px 10px 11px 16px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
  transition: background 0.1s;
}
.notif-item-link:hover { background: var(--card-raised); }

.notif-item-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notif-item-body {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notif-item-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}

.notif-item-dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  flex-shrink: 0;
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.notif-item-dismiss:hover { background: var(--card-raised); color: var(--text); }

/* ── Page topbar ── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: var(--globalbar-h);
  z-index: 50;
}

.topbar-title { font-size: 22px; font-weight: 800; color: var(--text); }

.content { padding: 28px; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 24px;
  margin-bottom: 22px;
}

.card-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.stat-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}

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

table { width: 100%; border-collapse: collapse; }

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

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 15px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.025); }
html[data-theme="light"] tr:hover td { background: rgba(0,0,0,0.03); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  border: none;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.12s, box-shadow 0.12s, transform 0.08s;
}
.btn:active { transform: scale(0.97); }

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

.btn-secondary {
  background: var(--card-raised);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 5px; }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: auto;
}
html[data-theme="light"] .form-control { background: #fff; }

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.15);
  background: var(--card-raised);
}
html[data-theme="light"] .form-control:focus { background: #fff; }

.form-control::placeholder { color: var(--text-muted); }
.form-control option { background: var(--card); color: var(--text); }
textarea.form-control { resize: vertical; min-height: 80px; font-family: inherit; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}

/* ── Alerts ── */
.alert {
  padding: 13px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 15px;
  font-weight: 500;
}

.alert-error   { background: rgba(220,38,38,0.12);  color: #fca5a5; border: 1px solid rgba(220,38,38,0.3);  }
.alert-success { background: rgba(34,197,94,0.1);   color: #86efac; border: 1px solid rgba(34,197,94,0.25); }
.alert-info    { background: rgba(59,130,246,0.1);  color: #93c5fd; border: 1px solid rgba(59,130,246,0.25);}

html[data-theme="light"] .alert-error   { background: rgba(220,38,38,0.08);  color: #991b1b; border-color: rgba(220,38,38,0.2); }
html[data-theme="light"] .alert-success { background: rgba(34,197,94,0.08);  color: #166534; border-color: rgba(34,197,94,0.2); }
html[data-theme="light"] .alert-info    { background: rgba(59,130,246,0.08); color: #1e40af; border-color: rgba(59,130,246,0.2); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-active          { background: rgba(34,197,94,0.15);  color: #4ade80; }
.badge-out_of_service  { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-decommissioned  { background: rgba(220,38,38,0.12);  color: #f87171; }
.badge-lost            { background: rgba(139,92,246,0.15); color: #c4b5fd; }
.badge-destroyed       { background: rgba(100,116,139,0.15);color: #9ca3af; }

html[data-theme="light"] .badge-active          { background: rgba(22,163,74,0.12);  color: #166534; }
html[data-theme="light"] .badge-out_of_service  { background: rgba(217,119,6,0.12);  color: #92400e; }
html[data-theme="light"] .badge-decommissioned  { background: rgba(220,38,38,0.1);   color: #991b1b; }
html[data-theme="light"] .badge-lost            { background: rgba(109,40,217,0.12); color: #5b21b6; }
html[data-theme="light"] .badge-destroyed       { background: rgba(100,116,139,0.12);color: #475569; }

/* ── Apparatus status badges ── */
.badge-apparatus-in_service     { background: rgba(34,197,94,0.15);  color: #4ade80; }
.badge-apparatus-reserve        { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-apparatus-out_of_service { background: rgba(220,38,38,0.12);  color: #f87171; }
.badge-apparatus-retired        { background: rgba(100,116,139,0.12);color: #94a3b8; }
.badge-apparatus-type           { background: rgba(59,130,246,0.12); color: #93c5fd; }

html[data-theme="light"] .badge-apparatus-in_service     { background: rgba(22,163,74,0.12);   color: #166534; }
html[data-theme="light"] .badge-apparatus-out_of_service { background: rgba(220,38,38,0.1);    color: #991b1b; }
html[data-theme="light"] .badge-apparatus-retired        { background: rgba(100,116,139,0.12); color: #475569; }
html[data-theme="light"] .badge-apparatus-type           { background: rgba(37,99,235,0.12);   color: #1e40af; }

/* ── Asset category badges ── */
.badge-category-portable_radio   { background: rgba(59,130,246,0.15);  color: #93c5fd; }
.badge-category-mobile_radio     { background: rgba(34,197,94,0.15);   color: #4ade80; }
.badge-category-mdt              { background: rgba(139,92,246,0.15);  color: #c4b5fd; }
.badge-category-router           { background: rgba(249,115,22,0.15);  color: #fb923c; }
.badge-category-tablet           { background: rgba(14,165,233,0.15);  color: #38bdf8; }
.badge-category-lightbar         { background: rgba(234,179,8,0.15);   color: #facc15; }
.badge-category-siren_controller { background: rgba(239,68,68,0.15);   color: #f87171; }
.badge-category-other            { background: rgba(100,116,139,0.15); color: #94a3b8; }

html[data-theme="light"] .badge-category-portable_radio   { background: rgba(37,99,235,0.12);  color: #1e40af; }
html[data-theme="light"] .badge-category-mobile_radio     { background: rgba(22,163,74,0.12);  color: #166534; }
html[data-theme="light"] .badge-category-mdt              { background: rgba(109,40,217,0.12); color: #5b21b6; }
html[data-theme="light"] .badge-category-router           { background: rgba(234,88,12,0.12);  color: #9a3412; }
html[data-theme="light"] .badge-category-tablet           { background: rgba(2,132,199,0.12);  color: #075985; }
html[data-theme="light"] .badge-category-lightbar         { background: rgba(161,98,7,0.12);   color: #713f12; }
html[data-theme="light"] .badge-category-siren_controller { background: rgba(220,38,38,0.1);   color: #991b1b; }
html[data-theme="light"] .badge-category-other            { background: rgba(100,116,139,0.12);color: #475569; }

/* ── Breadcrumb ── */
.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ── Action row ── */
.action-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ── Responsive grid utilities ── */
.grid-cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-cols-7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; }

/* ── Login page (always dark — no theme switching) ── */
.login-page {
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1px 2fr;
  background: #000;
}

/* ── Left panel: patch ── */
.login-left {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #2a0505 0%, #0d0202 60%, #000 100%);
  padding: 48px 32px;
}

.login-patch-main {
  width: 70%;
  max-width: 320px;
  min-width: 140px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 8px 40px rgba(0,0,0,0.8));
}

/* ── Vertical divider ── */
.login-vdivider {
  background: rgba(255,255,255,0.12);
  width: 1px;
  min-height: 100vh;
}

/* ── Right panel: form ── */
.login-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top right, #1a0303 0%, #0d0202 50%, #000 100%);
  padding: 48px 40px;
}

.login-dept-header { text-align: center; margin-bottom: 32px; }

.login-dept-name {
  font-size: clamp(22px, 3.2vw, 46px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #8B6914 0%, #D4AF37 25%, #FAF0A0 50%, #D4AF37 75%, #8B6914 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  filter: drop-shadow(0 2px 8px rgba(212,175,55,0.4));
}

.login-station-info {
  margin-top: 8px;
  font-size: clamp(11px, 1.4vw, 16px);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #7A5C10 0%, #C49A28 30%, #E8D87A 50%, #C49A28 70%, #7A5C10 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 1px 4px rgba(196,154,40,0.4));
}

.login-divider {
  width: 180px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #D4AF37, transparent);
  margin: 20px auto;
  opacity: 0.6;
}

.login-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-top: 3px solid #dc2626;
  border-radius: 14px;
  padding: 36px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.7);
}

/* Login always uses dark form controls */
.login-box .form-control {
  background: #0d1117;
  color: #e6edf3;
  border-color: #30363d;
}
.login-box .form-control:focus {
  background: #1c2128;
  border-color: #dc2626;
}
.login-box .form-label { color: #e6edf3; }

.login-logo { text-align: center; margin-bottom: 28px; }

.login-logo-icon {
  margin: 0 auto 14px;
  width: 56px;
  height: 56px;
  background: rgba(220,38,38,0.12);
  border: 1px solid rgba(220,38,38,0.3);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-app-name { font-size: 24px; font-weight: 800; color: #e6edf3; letter-spacing: -0.02em; margin-bottom: 4px; }
.login-app-sub { font-size: 14px; color: #8b949e; }

.login-fp-logo {
  display: block;
  margin: 24px auto 0;
  max-width: 200px;
  max-height: 80px;
  width: auto;
  object-fit: contain;
  opacity: 0.9;
}

/* ── Mobile: collapse to single-column ── */
@media (max-width: 700px) {
  .login-page {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .login-left,
  .login-vdivider {
    display: none;
  }
  .login-right {
    min-height: 100vh;
    padding: 40px 20px;
    background: radial-gradient(ellipse at top, #2a0505 0%, #0d0202 60%, #000 100%);
  }
  .login-dept-name  { font-size: clamp(26px, 6vw, 40px); }
  .login-station-info { font-size: clamp(12px, 3vw, 16px); }
}

/* ── Touch Log ── */
.log-entry {
  border-left: 3px solid var(--primary);
  padding: 14px 18px;
  background: var(--card);
  border-radius: 0 8px 8px 0;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-left-color: var(--primary);
}

.log-entry-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.log-entry-type { font-weight: 700; font-size: 15px; }
.log-entry-meta { font-size: 13px; color: var(--text-muted); text-align: right; line-height: 1.5; }
.log-entry-desc { font-size: 15px; color: var(--text); margin-bottom: 6px; white-space: pre-line; }
.log-entry-parts { font-size: 13px; color: var(--text-muted); }

/* ── Dashboard recent ── */
.recent-list { list-style: none; }

.recent-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.recent-item:last-child { border-bottom: none; }

.recent-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(220,38,38,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.recent-content { flex: 1; min-width: 0; }
.recent-title { font-size: 15px; font-weight: 600; color: var(--text); }
.recent-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── LID copy ── */
.lid-copy:hover { opacity: 0.75; }

.lid-copied {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-raised);
  color: #4ade80;
  font-size: 14px;
  font-family: inherit;
  font-weight: 700;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.lid-copied.show { opacity: 1; }
html[data-theme="light"] .lid-copied { color: #166534; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}

.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  width: 100%;
  max-width: 420px;
  padding: 24px;
}
html[data-theme="light"] .modal-box { box-shadow: 0 8px 32px rgba(0,0,0,0.15); }

.modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }

/* ── Portal Dashboard module grid ── */
.module-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 28px;
}

.module-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.module-card-placeholder {
  opacity: 0.55;
  background: rgba(255,255,255,0.015);
}
html[data-theme="light"] .module-card-placeholder { background: rgba(0,0,0,0.015); }

.module-card-header { display: flex; align-items: flex-start; gap: 14px; }

.module-card-icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.module-card-title { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.module-card-sub   { font-size: 13px; color: var(--text-muted); }

.module-badge {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.module-badge-active  { background: rgba(34,197,94,0.15);  color: #4ade80; }
.module-badge-coming  { background: rgba(100,116,139,0.15); color: #94a3b8; }
html[data-theme="light"] .module-badge-active  { background: rgba(22,163,74,0.12);  color: #166534; }
html[data-theme="light"] .module-badge-coming  { background: rgba(100,116,139,0.12);color: #475569; }

.module-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.module-stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}

.module-stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}

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

.module-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Apparatus Card Grid ── */
.apparatus-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.apparatus-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid #dc2626;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.apparatus-card:hover {
  border-color: rgba(220,38,38,0.4);
  box-shadow: 0 4px 20px rgba(220,38,38,0.1);
}
html[data-theme="light"] .apparatus-card:hover {
  box-shadow: 0 4px 16px rgba(220,38,38,0.08);
}

.apparatus-card-header {
  padding: 18px 20px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.apparatus-card-icon {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: rgba(220,38,38,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--primary);
}

.apparatus-card-name {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 4px;
}

.apparatus-card-body {
  padding: 14px 20px;
  flex: 1;
  display: grid;
  gap: 8px;
}

.apparatus-detail {
  display: flex;
  gap: 8px;
  font-size: 14px;
}

.apparatus-detail-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  min-width: 72px;
  padding-top: 1px;
}

.apparatus-detail-value { color: var(--text); font-weight: 500; }

.apparatus-card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.apparatus-equipment-count {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ── Forced change-password overlay ── */
.forced-pw-overlay {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.forced-pw-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
}

html[data-theme="light"] .forced-pw-card {
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
}

.forced-pw-header {
  text-align: center;
  margin-bottom: 24px;
}

.forced-pw-icon {
  width: 56px;
  height: 56px;
  background: rgba(220,38,38,0.12);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--primary);
}

.forced-pw-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.forced-pw-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.forced-pw-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.forced-pw-hint strong { color: var(--text); }
.forced-pw-hint svg { flex-shrink: 0; color: var(--warning); }

.forced-pw-submit {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
  padding: 10px;
  font-size: 15px;
}

.forced-pw-footer {
  text-align: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.forced-pw-signout {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}
.forced-pw-signout:hover { color: var(--text); text-decoration: underline; }

/* ── Mobile menu button (hamburger) ── */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.mobile-menu-btn:hover { background: var(--card-raised); color: var(--text); }

/* ── Sidebar backdrop (mobile overlay) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
  backdrop-filter: blur(2px);
}
html.mobile-nav-open .sidebar-backdrop { display: block; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .two-col { grid-template-columns: 1fr !important; }
}

@media (max-width: 900px) {
  .module-grid { grid-template-columns: 1fr; }
  .module-stats { grid-template-columns: repeat(2, 1fr); }
  .apparatus-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* Sidebar hidden by default on mobile; desktop nav-collapsed has no effect here */
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
    transition: transform 0.25s cubic-bezier(.4,0,.2,1), width 0.22s cubic-bezier(.4,0,.2,1);
  }
  html.nav-collapsed .sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
  /* Mobile-nav-open class shows the sidebar as an overlay */
  html.mobile-nav-open .sidebar { transform: translateX(0); width: var(--sidebar-w); }

  .main { margin-left: 0 !important; }

  .mobile-menu-btn { display: flex; }

  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .user-chip-name { display: none; }

  /* Shrink globalbar items on mobile */
  .globalbar { padding: 0 12px; gap: 8px; }
  .globalbar-search { max-width: none; }
  .log-drive-label { display: none; }
  .log-drive-btn { margin-right: 0 !important; }

  /* Hide Data Utilities label on mobile, keep icon */
  .util-trigger-label { display: none; }
  .util-trigger-btn .util-chevron { display: none; }

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

  /* Content padding reduction on mobile */
  .content { padding: 16px 12px; }

  /* Topbar: wrap title + buttons on narrow screens */
  .topbar {
    flex-wrap: wrap;
    padding: 10px 12px;
    min-height: auto;
    gap: 10px;
  }
  .topbar-title { font-size: 19px; }

  /* Cards full-width on mobile */
  .card[style*="max-width"] { max-width: 100% !important; }

  /* Forced password card tighter on mobile */
  .forced-pw-card { padding: 28px 20px 24px; }

  /* Responsive grid utilities collapse */
  .grid-cols-2 { grid-template-columns: 1fr; }
  .grid-cols-3 { grid-template-columns: 1fr 1fr; }
  .grid-cols-7 { grid-template-columns: repeat(4, 1fr); }

  /* Prevent inline max-width on inputs from overflowing the viewport */
  .form-control { max-width: 100% !important; }

  /* two-col layouts that use fixed pixel left column */
  .two-col { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .module-stats { grid-template-columns: 1fr; }

  /* Stack globalbar-right items */
  .globalbar-right { gap: 6px; }

  /* Hide Data Utilities button entirely on very small screens */
  .util-menu { display: none; }

  /* Responsive grid utilities — further collapse on small phones */
  .grid-cols-3 { grid-template-columns: 1fr; }
  .grid-cols-7 { grid-template-columns: repeat(3, 1fr); }

  .topbar-title { font-size: 17px; }
}
