/* Modern admin UI layer — loaded only on /admin pages, layered on top of
   style.css. Scoped here (rather than edited into style.css) so the
   field-staff capture form's look is untouched. */

:root {
  --admin-surface: #ffffff;
  --admin-bg: #f4f6f8;
  --admin-border: #e4e9ee;
  --admin-muted: #64748b;
  --admin-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --admin-shadow-md: 0 8px 20px rgba(16, 24, 40, 0.08);
  --admin-radius: 0.85rem;
  --admin-radius-sm: 0.55rem;

  --bs-border-radius: 0.55rem;
  --bs-border-radius-sm: 0.45rem;
  --bs-border-radius-lg: 0.85rem;
}

body {
  background-color: var(--admin-bg);
}

/* ---------- Top navbar ---------- */
.admin-navbar {
  background: var(--admin-surface);
  border-bottom: 1px solid var(--admin-border);
  box-shadow: var(--admin-shadow-sm);
  position: sticky;
  top: 0;
  z-index: 1030;
}

/* This <nav> also wears Bootstrap's .navbar/.navbar-expand-lg classes for
   the built-in collapse/hamburger behavior below the lg breakpoint — these
   overrides neutralize Bootstrap's own spacing defaults on those classes so
   all spacing still comes from the rules below, unchanged from before. */
.admin-navbar.navbar {
  padding: 0;
}

.admin-navbar-inner {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0.65rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* Logo + hamburger are grouped in their own always-on-one-line flex row,
   pinned to opposite edges via space-between on a dedicated wrapper —
   rather than relying on .admin-navbar-inner's own space-between across
   all its children, which would only coincidentally keep them apart for as
   long as nothing else changes their number/order. On desktop this wrapper
   holds only the (still-visible) logo, since Bootstrap hides the toggler
   at the .navbar-expand-lg breakpoint; the collapse content then shares
   the row with it via .admin-navbar-inner's own flex layout, unchanged
   from before. */
.admin-navbar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

@media (min-width: 992px) {
  .admin-navbar-header {
    width: auto;
  }
}

.admin-navbar-brand.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  font-size: inherit;
  text-decoration: none;
}

.admin-navbar-brand .brand-logo {
  max-width: none;
  height: 32px;
  width: auto;
}

.navbar-toggler {
  border-color: var(--admin-border);
  border-radius: var(--admin-radius-sm);
  padding: 0.4rem 0.65rem;
  background-color: var(--admin-bg);
  line-height: 1;
  transition: background-color 0.15s ease;
}

.navbar-toggler:hover {
  background-color: rgba(27, 138, 90, 0.08);
}

.navbar-toggler:focus {
  box-shadow: 0 0 0 0.2rem rgba(27, 138, 90, 0.25);
}

.navbar-toggler-icon {
  width: 1.3em;
  height: 1.3em;
}

/* Bootstrap's .navbar-collapse takes over full width once toggled open
   below the lg breakpoint — let the nav items stack into a tappable list
   instead of staying a cramped wrapped row on a narrow screen. */
.navbar-collapse {
  flex-basis: 100%;
}

.admin-navbar-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* Desktop/tablet (uncollapsed) nav: right-align the menu against the brand,
   rather than letting it hug the left edge right after the logo. Scoped to
   this breakpoint only — the mobile stacked menu below still lays out
   top-to-bottom via flex-direction: column, where justify-content would
   instead affect vertical position, not horizontal alignment. */
@media (min-width: 992px) {
  .admin-navbar-nav {
    justify-content: flex-end;
    flex: 1 1 auto;
  }
}

@media (max-width: 991.98px) {
  .admin-navbar-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    padding: 0.75rem 0 0.25rem;
  }

  .admin-navbar-nav .admin-nav-link {
    border-radius: var(--admin-radius-sm);
    width: 100%;
    /* Slightly taller than the desktop pill so each row is a comfortable
       tap target once the menu is a stacked list instead of an inline row. */
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }

  .admin-navbar-nav .dropdown {
    width: 100%;
  }

  .admin-navbar-nav .admin-nav-dropdown-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-navbar-nav .dropdown-menu {
    width: 100%;
    box-shadow: none;
    border: none;
    padding-left: 0.75rem;
  }
}

/* Thin visual divider between menu groups (e.g. before Settings/Profile) —
   only meaningful in the mobile stacked list, where every item runs
   together in one column; on the desktop pill row the grouping is already
   obvious from each dropdown being its own separate button. */
.admin-nav-sep {
  display: none;
}

@media (max-width: 991.98px) {
  .admin-nav-sep {
    display: block;
    border: none;
    border-top: 1px solid var(--admin-border);
    margin: 0.4rem 0.25rem;
  }
}

.admin-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  color: var(--admin-muted);
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.admin-nav-link:hover {
  background-color: rgba(27, 138, 90, 0.08);
  color: var(--brand-primary-dark);
}

.admin-nav-link.active {
  background-color: var(--brand-primary);
  color: #fff;
}

/* Reports dropdown toggle is a <button> wearing .admin-nav-link — reset the
   browser button chrome so it matches the plain <a> nav links exactly. */
.admin-nav-dropdown-toggle {
  background: none;
  border: none;
  font: inherit;
}

.admin-navbar-nav .dropdown-menu {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius-sm);
  box-shadow: var(--admin-shadow-md);
  padding: 0.4rem;
  min-width: 190px;
  margin-top: 0.4rem;
}

.admin-navbar-nav .dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: var(--admin-radius-sm);
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--admin-muted);
}

.admin-navbar-nav .dropdown-item:hover {
  background-color: rgba(27, 138, 90, 0.08);
  color: var(--brand-primary-dark);
}

.admin-navbar-nav .dropdown-item.active {
  background-color: var(--brand-primary);
  color: #fff;
}

/* Log Out inside the Profile dropdown — same red treatment the standalone
   Log Out link used before it moved into this dropdown. */
.admin-navbar-nav .dropdown-item.dropdown-item-danger {
  color: #b42318;
}

.admin-navbar-nav .dropdown-item.dropdown-item-danger:hover {
  background-color: rgba(180, 35, 24, 0.08);
  color: #b42318;
}

/* ---------- Page container ---------- */
/* Offset to sit beside the fixed left sidebar (see "Sidebar layout" block at
   the end of this file). margin-left tracks the sidebar width and collapses
   with it; on mobile the sidebar is an off-canvas drawer so the offset drops
   to 0 and a top bar takes over. */
.admin-content {
  max-width: 1500px;
  margin-left: var(--sidebar-width);
  margin-right: auto;
  padding: 1.75rem 2rem 3rem;
  transition: margin-left 0.18s ease;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* Opt-in modifier for a page whose header action button should sit level
   with the heading text itself, rather than the default flex-end (which
   baselines it against the subtitle paragraph below the heading). */
.page-header-align-top {
  align-items: flex-start;
}

.page-header h1 {
  font-weight: 800;
  color: var(--brand-text);
  margin-bottom: 0.2rem;
}

.page-header p {
  color: var(--admin-muted);
  margin-bottom: 0;
}

/* ---------- Stat cards ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow-sm);
  padding: 1.15rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-card-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.stat-card-icon.icon-brand   { background: rgba(27, 138, 90, 0.12); color: var(--brand-primary-dark); }
.stat-card-icon.icon-success { background: rgba(40, 167, 69, 0.14); color: #1e7e34; }
.stat-card-icon.icon-warning { background: rgba(245, 166, 35, 0.16); color: #b5730a; }
.stat-card-icon.icon-info    { background: rgba(13, 110, 253, 0.12); color: #0b5ed7; }
.stat-card-icon.icon-danger  { background: rgba(220, 53, 69, 0.12); color: #dc3545; }

.stat-card-value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--brand-text);
}

.stat-card-label {
  font-size: 0.78rem;
  color: var(--admin-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

/* A stat card rendered as a link (dashboard drill-through). */
a.stat-card {
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
a.stat-card:hover {
  box-shadow: var(--admin-shadow-md);
  transform: translateY(-2px);
}

/* Dashboard momentum strip (Today / This week / This month). */
.dash-momentum {
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--admin-border);
}
.dash-momentum-item { display: flex; flex-direction: column; }
.dash-momentum-value {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--brand-text);
}
.dash-momentum-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--admin-muted);
  font-weight: 700;
}

/* Dashboard recent-activity list. */
.activity-list { display: flex; flex-direction: column; }
.activity-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--admin-border);
  align-items: baseline;
}
.activity-item:last-child { border-bottom: 0; }
.activity-when {
  color: var(--admin-muted);
  font-size: 0.76rem;
  white-space: nowrap;
  min-width: 92px;
}
.activity-text { font-size: 0.88rem; }
.activity-who { font-weight: 700; }

/* ---------- Cards & tables ---------- */
.admin-content .card {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow-sm);
  overflow: hidden;
}

.admin-content .card-header {
  background: var(--admin-surface);
  color: var(--brand-text);
  font-weight: 700;
  border-bottom: 1px solid var(--admin-border);
}

table.admin-table thead tr:first-child th {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--admin-muted);
  background: #f8fafc;
  border-bottom: 2px solid var(--admin-border);
  white-space: nowrap;
}

table.admin-table tbody tr:hover {
  background-color: rgba(27, 138, 90, 0.045);
}

table.admin-table td.actions-cell,
table.admin-table td.photo-cell {
  vertical-align: middle;
}

/* DataTables chrome */
.dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius-sm);
  padding: 0.3rem 0.6rem;
}

.dataTables_wrapper .dataTables_length select {
  border-radius: var(--admin-radius-sm);
}

/* ---------- Analysis: horizontal stacked bar chart ---------- */
/* Status colors are the dataviz skill's fixed, pre-validated pair —
   good = completed, critical = not completed. Never re-themed. */
:root {
  --status-good: #0ca30c;
  --status-critical: #d03b3b;
}

.hbar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--admin-muted);
}

.hbar-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.hbar-legend-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

.hbar-legend-swatch.good     { background: var(--status-good); }
.hbar-legend-swatch.critical { background: var(--status-critical); }

.hbar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.75rem;
}

.hbar-row {
  display: grid;
  grid-template-columns: minmax(90px, 160px) 1fr 56px;
  align-items: center;
  gap: 0.85rem;
}

.hbar-label {
  font-size: 0.85rem;
  color: var(--brand-text);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hbar-track {
  display: flex;
  align-items: center;
  height: 20px;
  border-radius: 0 4px 4px 0;
  overflow: hidden;
  background: var(--admin-bg);
}

.hbar-seg {
  height: 100%;
}

.hbar-seg.good {
  background: var(--status-good);
  margin-right: 2px;
}

.hbar-seg.critical {
  background: var(--status-critical);
}

/* Single-series bars (e.g. date-range completion counts) use the brand hue —
   no status pairing, so no legend per the dataviz skill's single-series rule. */
.hbar-seg.brand {
  background: var(--brand-primary);
}

.hbar-value {
  font-size: 0.8rem;
  color: var(--admin-muted);
  font-variant-numeric: tabular-nums;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--brand-primary) !important;
  border-color: var(--brand-primary) !important;
  color: #fff !important;
}

/* Pill sub-nav (Customer–Contractor Allotment Unassigned/Assigned, Portal & QC
   analytics, invoice subnav) in the brand colour instead of Bootstrap's blue. */
.nav-pills .nav-link {
  color: var(--brand-primary-dark);
}
.nav-pills .nav-link.active,
.nav-pills .show > .nav-link {
  background-color: var(--brand-primary);
  color: #fff;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: var(--admin-radius-sm) !important;
}

.dt-buttons .btn {
  border-radius: var(--admin-radius-sm);
}

/* ---------- Badges / pills ---------- */
.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.pill-badge.pill-yes { background: #d9f2df; color: #1e7e34; }
.pill-badge.pill-no  { background: #fbdede; color: #b42318; }

/* ---------- Auth (login) card ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--admin-bg) 0%, #eef2f0 100%);
  padding: 1.5rem;
}

.auth-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow-md);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

.auth-card-header {
  padding: 1.75rem 1.75rem 0.5rem;
  text-align: center;
}

.auth-card-body {
  padding: 1.5rem 1.75rem 1.9rem;
}

/* ---------- View-installation modal ---------- */
.view-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1.5rem;
}

@media (max-width: 576px) {
  .view-fields-grid {
    grid-template-columns: 1fr;
  }
}

.view-field {
  border-bottom: 1px solid var(--admin-border);
  padding-bottom: 0.35rem;
  font-size: 0.88rem;
}

.view-field-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--admin-muted);
  font-weight: 700;
}

.view-field-value {
  word-break: break-word;
}

.view-photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}

.view-photo-card {
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius-sm);
  padding: 0.6rem;
  text-align: center;
}

.view-photo-card img {
  max-width: 100%;
  max-height: 110px;
  object-fit: cover;
  border-radius: var(--admin-radius-sm);
  margin-bottom: 0.4rem;
}

.view-photo-card .view-photo-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-text);
}

.view-photo-card .view-photo-link {
  display: block;
  font-size: 0.7rem;
  word-break: break-all;
  margin-top: 0.2rem;
}

/* ---------- Idle session timeout warning ---------- */
.idle-timeout-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.idle-timeout-box {
  background: var(--admin-surface);
  border-radius: var(--admin-radius-sm);
  box-shadow: var(--admin-shadow-md);
  padding: 1.75rem 2rem;
  max-width: 360px;
  text-align: center;
}

/* Command palette (Ctrl+K / Cmd+K) — assets/js/command-palette.js */
.cmdk-trigger-btn {
  color: rgba(255, 255, 255, 0.85);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--admin-radius-sm);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}
.cmdk-trigger-btn:hover { color: #fff; border-color: rgba(255, 255, 255, 0.6); }

.cmdk-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  z-index: 2100;
}
.cmdk-box {
  background: var(--admin-surface);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow-md);
  width: 100%;
  max-width: 560px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cmdk-input {
  border: none;
  border-bottom: 1px solid var(--admin-border);
  border-radius: 0;
  padding: 0.9rem 1rem;
  font-size: 1rem;
}
.cmdk-input:focus { box-shadow: none; }
.cmdk-results { overflow-y: auto; padding: 0.4rem; }
.cmdk-group-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--admin-muted);
  padding: 0.5rem 0.6rem 0.2rem;
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--admin-radius-sm);
  text-decoration: none;
  color: var(--brand-text, #22303c);
}
.cmdk-item:hover, .cmdk-item:first-child { background: var(--admin-bg); }
.cmdk-item-primary { flex: 1 1 auto; }
.cmdk-item-secondary { color: var(--admin-muted); font-size: 0.85rem; }
.cmdk-empty { padding: 0.75rem 0.6rem; color: var(--admin-muted); font-size: 0.9rem; }

/* ============================================================================
   Sidebar layout — shared by the admin panel (admin/_nav.php) and the field
   area (FieldUser/_nav.php). A fixed left sidebar with the logo pinned on top
   and a vertical menu below; collapses to an icon-only rail on desktop
   (persisted), and becomes an off-canvas drawer with a top bar on mobile.
   ========================================================================== */
:root {
  --sidebar-width: 16.5rem;
  --sidebar-rail: 4.6rem;
  --topbar-h: 3.5rem;
  --sidebar-bg: #ffffff;
  --sidebar-border: var(--admin-border);
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: var(--admin-shadow-sm);
  display: flex;
  flex-direction: column;
  z-index: 1045;
  transition: width 0.18s ease, transform 0.2s ease;
}

.app-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--sidebar-border);
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  overflow: hidden;
  text-decoration: none;
}

.app-sidebar-brand .brand-logo {
  height: 34px;
  width: auto;
  max-width: 100%;
}

.app-sidebar-collapse {
  background: none;
  border: none;
  color: var(--admin-muted);
  border-radius: var(--admin-radius-sm);
  padding: 0.3rem 0.45rem;
  line-height: 1;
  cursor: pointer;
  flex: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar-collapse:hover {
  background: rgba(27, 138, 90, 0.08);
  color: var(--brand-primary-dark);
}

.app-sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.app-sidebar-foot {
  padding: 0.5rem 0.6rem 0.85rem;
  border-top: 1px solid var(--sidebar-border);
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: var(--admin-radius-sm);
  color: var(--admin-muted);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-nav-link > i:first-child {
  font-size: 1.05rem;
  width: 1.35rem;
  text-align: center;
  flex: none;
}

.app-nav-link:hover {
  background: rgba(27, 138, 90, 0.08);
  color: var(--brand-primary-dark);
}

.app-nav-link.active {
  background: var(--brand-primary);
  color: #fff;
}

.app-nav-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--admin-muted);
  font-weight: 700;
  opacity: 0.7;
  padding: 0.8rem 0.7rem 0.25rem;
  white-space: nowrap;
}

.app-sidebar-user {
  font-size: 0.8rem;
  color: var(--admin-muted);
  padding: 0.35rem 0.7rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-nav-search kbd {
  margin-left: auto;
  font-size: 0.68rem;
  background: var(--admin-bg);
  color: var(--admin-muted);
  border: 1px solid var(--admin-border);
  border-radius: 0.35rem;
  padding: 0.05rem 0.3rem;
}

/* Collapsible groups (Reports / Import / Settings) */
.app-nav-group-toggle .app-nav-caret {
  margin-left: auto;
  font-size: 0.8rem;
  transition: transform 0.18s ease;
}

.app-nav-group.open > .app-nav-group-toggle .app-nav-caret {
  transform: rotate(180deg);
}

.app-nav-submenu {
  display: none;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.15rem 0 0.25rem 0.35rem;
  margin: 0.1rem 0 0.1rem 0.85rem;
  border-left: 1px solid var(--sidebar-border);
}

.app-nav-group.open > .app-nav-submenu {
  display: flex;
}

.app-subnav-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--admin-radius-sm);
  color: var(--admin-muted);
  font-weight: 600;
  font-size: 0.84rem;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-subnav-link > i:first-child {
  font-size: 0.95rem;
  width: 1.1rem;
  text-align: center;
  flex: none;
}

.app-subnav-link:hover {
  background: rgba(27, 138, 90, 0.08);
  color: var(--brand-primary-dark);
}

.app-subnav-link.active {
  background: var(--brand-primary);
  color: #fff;
}

.app-nav-danger,
.app-nav-danger:hover {
  color: #b42318;
}

.app-nav-danger:hover {
  background: rgba(180, 35, 24, 0.08);
}

/* ---- Collapsed icon rail (desktop only) ---- */
@media (min-width: 992px) {
  body.sb-collapsed .app-sidebar {
    width: var(--sidebar-rail);
  }
  body.sb-collapsed .app-sidebar .app-nav-link > span,
  body.sb-collapsed .app-sidebar .app-nav-label,
  body.sb-collapsed .app-sidebar .app-nav-caret,
  body.sb-collapsed .app-sidebar .app-nav-search kbd,
  body.sb-collapsed .app-sidebar .app-sidebar-user,
  body.sb-collapsed .app-sidebar .app-sidebar-brand,
  body.sb-collapsed .app-sidebar .app-nav-submenu {
    display: none !important;
  }
  body.sb-collapsed .app-sidebar .app-nav-link,
  body.sb-collapsed .app-sidebar .app-subnav-link {
    justify-content: center;
    gap: 0;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  body.sb-collapsed .app-sidebar-head {
    justify-content: center;
  }
  body.sb-collapsed .app-sidebar-collapse .bi {
    transform: rotate(180deg);
  }
  body.sb-collapsed .admin-content {
    margin-left: var(--sidebar-rail);
  }
}

/* ---- Mobile: off-canvas drawer + top bar ---- */
.app-topbar {
  display: none;
}
.app-sidebar-backdrop {
  display: none;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  body.sb-open .app-sidebar {
    transform: translateX(0);
    box-shadow: var(--admin-shadow-md);
  }
  .admin-content {
    margin-left: 0;
    padding-top: calc(var(--topbar-h) + 1rem);
  }
  .app-topbar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    box-shadow: var(--admin-shadow-sm);
    z-index: 1035;
    padding: 0 0.9rem;
  }
  .app-topbar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
  }
  .app-topbar-brand .brand-logo {
    height: 28px;
    width: auto;
    max-width: 100%;
  }
  .app-topbar-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--brand-text, #17322c);
    line-height: 1;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
  }
  body.sb-open .app-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.4);
    z-index: 1040;
  }
}

/*
 * DCR / OTP documentation flags on the Installations table.
 *
 * Colour-coded so a supervisor can eyeball completeness straight down the
 * column rather than reading every cell. The green is the legacy's exact value
 * (installations.php:131, td.status-yes); the red matches its .submitted-no
 * (installations.php:129) rather than a new colour, so the two tables agree.
 *
 * The legacy only greens "Yes" and leaves "No" plain — the red is an addition
 * on request. A NULL cell is left uncoloured deliberately: "not recorded" is
 * not "No", and painting it red would assert something the data doesn't say.
 *
 * !important, as in the legacy: Bootstrap's .table-hover and .table-striped set
 * a background on the cell via a box-shadow/background-color that would
 * otherwise win on alternate rows and on hover, making the flag flicker in and
 * out as the mouse moves.
 */
table td.status-yes { background-color: #d9f2df !important; }
table td.status-no  { background-color: #fbdede !important; }

/*
 * Skip-to-content link. Visually hidden until it receives keyboard focus, when
 * it drops into the top-left above the fixed sidebar/topbar — the first Tab
 * stop on every admin page, letting keyboard and screen-reader users jump the
 * navigation and land on <main id="main-content">.
 */
.app-skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 2000;
  padding: 0.5rem 0.9rem;
  background: var(--brand-primary, #0d6efd);
  color: #fff;
  border-radius: 0.375rem;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.app-skip-link:focus { color: #fff; }

/* The main region is a focus target for the skip link; never show a focus ring on it. */
#main-content:focus { outline: none; }

/*
 * Frozen header row on every data table.
 *
 * Bootstrap's .table-responsive sets overflow-x:auto, which makes it a scroll
 * container on BOTH axes — so a plain sticky <thead> pins to that wrapper (which
 * doesn't scroll vertically) instead of the window, and appears to do nothing.
 * Giving the wrapper a max-height turns it into the vertical scroll region, and
 * the sticky header then stays put while its rows scroll beneath it.
 *
 * Short tables sit under the cap and never scroll, so they look unchanged.
 * Screen only — printing keeps the full, unclipped table. Tune the 70vh cap (or
 * scope this to a class) if a particular page wants whole-page scrolling back.
 */
@media screen {
  .table-responsive {
    max-height: 70vh;
  }
  .table-responsive > table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 3;
    /* Opaque, so rows scrolling underneath don't bleed through the header. */
    background-color: var(--admin-surface);
  }
}
