/* ============================================================
   DS V2 — Main Application Stylesheet
   Bootstrap 5 base + custom tokens + components
   ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────────── */
:root {
  --primary:        #1a6b3a;
  --primary-dark:   #124a28;
  --primary-light:  #e8f5ee;
  --accent:         #2eb86a;
  --accent-light:   #d4f0e2;
  --secondary:      #3d5a80;
  --surface:        #ffffff;
  --surface-2:      #f8fafb;
  --surface-3:      #f0f4f7;
  --border:         #dee2e6;
  --text:           #1a202c;
  --text-muted:     #6b7280;
  --text-light:     #9ca3af;
  --navbar-h:       60px;
  --topbar-h:       60px;
  --radius:         10px;
  --radius-lg:      16px;
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:      0 10px 25px rgba(0,0,0,.1);
  --transition:     0.2s ease;

  /* Status colours */
  --status-draft:        #6c757d;
  --status-submitted:    #0d6efd;
  --status-under_review: #fd7e14;
  --status-approved:     #198754;
  --status-rejected:     #dc3545;
  --status-revised:      #0dcaf0;
}

/* Dark mode */
[data-theme="dark"] {
  /* Custom tokens */
  --primary:       #2eb86a;
  --primary-dark:  #1a6b3a;
  --primary-light: #0d2b1a;
  --surface:       #1e2330;
  --surface-2:     #252b3b;
  --surface-3:     #2d3448;
  --border:        #374151;
  --text:          #e5e7eb;
  --text-muted:    #d1d5db;
  --text-light:    #cbd5e1;

  /* Bootstrap CSS variable overrides — fixes tables, modals, forms, dropdowns */
  --bs-body-bg:                  #252b3b;
  --bs-body-color:               #e5e7eb;
  --bs-heading-color:            #e5e7eb;
  --bs-body-color-rgb:           229, 231, 235;
  --bs-secondary-color:          #d1d5db;
  --bs-secondary-bg:             #252b3b;
  --bs-tertiary-bg:              #2d3448;
  --bs-border-color:             #374151;
  --bs-border-color-translucent: rgba(55, 65, 81, .5);

  /* Table */
  --bs-table-bg:                 transparent;
  --bs-table-color:              #e5e7eb;
  --bs-table-border-color:       #374151;
  --bs-table-striped-bg:         rgba(255, 255, 255, .04);
  --bs-table-striped-color:      #e5e7eb;
  --bs-table-hover-bg:           rgba(255, 255, 255, .06);
  --bs-table-hover-color:        #e5e7eb;
  --bs-table-active-bg:          rgba(255, 255, 255, .08);

  /* Card */
  --bs-card-bg:                  #1e2330;
  --bs-card-border-color:        #374151;
  --bs-card-cap-bg:              #252b3b;

  /* Modal */
  --bs-modal-bg:                 #1e2330;
  --bs-modal-border-color:       #374151;
  --bs-modal-header-border-color:#374151;
  --bs-modal-footer-border-color:#374151;

  /* Dropdown */
  --bs-dropdown-bg:              #252b3b;
  --bs-dropdown-border-color:    #374151;
  --bs-dropdown-link-color:      #e5e7eb;
  --bs-dropdown-link-hover-bg:   #2d3448;
  --bs-dropdown-link-hover-color:#f3f4f6;
  --bs-dropdown-divider-bg:      #374151;
  --bs-dropdown-header-color:    #d1d5db;

  /* List group */
  --bs-list-group-bg:            #1e2330;
  --bs-list-group-color:         #e5e7eb;
  --bs-list-group-border-color:  #374151;
  --bs-list-group-action-hover-bg:#2d3448;
  --bs-list-group-action-hover-color:#f3f4f6;

  /* Form controls */
  --bs-form-control-bg:          #1e2330;
  --bs-form-select-bg:           #1e2330;
  --bs-input-bg:                 #1e2330;
  --bs-input-border-color:       #374151;
  --bs-input-color:              #e5e7eb;
  --bs-input-placeholder-color:  #9ca3af;

  /* Bootstrap 5.3 "subtle" colour utilities */
  --bs-primary-bg-subtle:        #0d2b1a;
  --bs-secondary-bg-subtle:      #2d3448;
  --bs-success-bg-subtle:        rgba(25,135,84,.22);
  --bs-info-bg-subtle:           rgba(13,202,240,.22);
  --bs-warning-bg-subtle:        rgba(255,193,7,.22);
  --bs-danger-bg-subtle:         rgba(220,53,69,.22);
  --bs-light-bg-subtle:          #2d3448;
  --bs-dark-bg-subtle:           #374151;
  --bs-primary-text-emphasis:    #6ee7a0;
  --bs-secondary-text-emphasis:  #d1d5db;
  --bs-success-text-emphasis:    #6ee7a0;
  --bs-info-text-emphasis:       #7decff;
  --bs-warning-text-emphasis:    #fcd34d;
  --bs-danger-text-emphasis:     #fca5a5;
  --bs-light-text-emphasis:      #f3f4f6;
  --bs-dark-text-emphasis:       #e5e7eb;
  --bs-primary-border-subtle:    rgba(25,135,84,.4);
  --bs-success-border-subtle:    rgba(25,135,84,.4);
  --bs-info-border-subtle:       rgba(13,202,240,.4);
  --bs-warning-border-subtle:    rgba(255,193,7,.4);
  --bs-danger-border-subtle:     rgba(220,53,69,.4);

  /* Misc Bootstrap components */
  --bs-offcanvas-bg:             #1e2330;
  --bs-pagination-bg:            #1e2330;
  --bs-pagination-border-color:  #374151;
  --bs-pagination-color:         #e5e7eb;
  --bs-pagination-hover-bg:      #2d3448;
  --bs-pagination-hover-color:   #f3f4f6;
  --bs-pagination-disabled-bg:   #1e2330;
  --bs-pagination-disabled-color:#6b7280;
  --bs-tooltip-bg:               #374151;
  --bs-popover-bg:               #1e2330;
  --bs-popover-border-color:     #374151;
  --bs-popover-header-bg:        #252b3b;
  --bs-popover-body-color:       #e5e7eb;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ── Layout Shell ───────────────────────────────────────────── */
#app-wrapper {
  min-height: 100vh;
}

/* ── Main Content ────────────────────────────────────────────── */
#main-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Navbar overrides ────────────────────────────────────────── */
.navbar {
  box-shadow: var(--shadow);
  border-bottom: 1px solid var(--border);
}

.navbar-brand .brand-logo {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.navbar .icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.navbar .icon-btn:hover {
  background: var(--surface-3);
  color: var(--primary);
}

.navbar .notif-badge {
  position: absolute;
  top: -7px; right: -7px;
  background: #ef4444;
  color: #fff;
  font-size: .72rem;
  line-height: 1;
  font-weight: 800;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid var(--surface);
  box-shadow: 0 4px 10px rgba(0,0,0,.22);
  letter-spacing: .01em;
}

.navbar .icon-btn.has-unread > i {
  color: var(--primary);
}

.navbar .icon-btn.has-new .notif-badge {
  animation: notifPulse 1.25s ease-in-out infinite;
}

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Page Content ─────────────────────────────────────────────── */
#page-content {
  flex: 1;
  padding: 24px;
  padding-top: calc(var(--navbar-h) + 16px);
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.page-breadcrumb {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.breadcrumb-sm {
  font-size: .78rem;
  --bs-breadcrumb-divider-color: var(--text-muted);
  --bs-breadcrumb-item-active-color: var(--text-muted);
  padding: 4px 0;
  background: transparent;
}
.breadcrumb-sm .breadcrumb-item + .breadcrumb-item::before {
  color: var(--text-muted);
}
.breadcrumb-sm a {
  color: var(--primary);
  text-decoration: none;
}
.breadcrumb-sm a:hover {
  text-decoration: underline;
}

.form-label,
.form-check-label,
.form-text,
.text-muted,
small,
.small,
td,
th,
.table,
.dropdown-item,
.dropdown-header,
.card-header,
.card-body,
.modal-title,
.modal-body,
.modal-footer,
.btn-link {
  color: inherit;
}

.form-label,
.form-check-label,
.card-header,
.dropdown-item,
th {
  color: var(--text);
}

.form-text,
.text-muted,
small,
.small,
.dropdown-header,
td,
.table,
.btn-link {
  color: var(--text-muted) !important;
}

[data-theme="dark"] .form-label,
[data-theme="dark"] .form-check-label,
[data-theme="dark"] .card-header,
[data-theme="dark"] .dropdown-item,
[data-theme="dark"] .modal-title,
[data-theme="dark"] th,
[data-theme="dark"] label {
  color: #f8fafc !important;
}

[data-theme="dark"] .form-text,
[data-theme="dark"] .text-muted,
[data-theme="dark"] small,
[data-theme="dark"] .small,
[data-theme="dark"] .page-breadcrumb,
[data-theme="dark"] .breadcrumb-sm .breadcrumb-item.active,
[data-theme="dark"] td,
[data-theme="dark"] .table,
[data-theme="dark"] .dropdown-header,
[data-theme="dark"] .btn-link,
[data-theme="dark"] .stat-card .stat-label,
[data-theme="dark"] .notif-msg,
[data-theme="dark"] .notif-time,
[data-theme="dark"] .drawer-section-label {
  color: var(--text-muted) !important;
}

[data-theme="dark"] .text-dark,
[data-theme="dark"] .text-body,
[data-theme="dark"] .text-secondary,
[data-theme="dark"] .text-black,
[data-theme="dark"] .text-black-50,
[data-theme="dark"] .text-reset,
[data-theme="dark"] .text-body-secondary,
[data-theme="dark"] .text-body-tertiary {
  color: #f8fafc !important;
}

[data-theme="dark"] .table thead th,
[data-theme="dark"] .table tbody td,
[data-theme="dark"] .table tbody tr,
[data-theme="dark"] .card,
[data-theme="dark"] .card-body,
[data-theme="dark"] .modal-content,
[data-theme="dark"] .modal-body,
[data-theme="dark"] .modal-footer,
[data-theme="dark"] .dropdown-menu,
[data-theme="dark"] .dropdown-item,
[data-theme="dark"] .list-group-item,
[data-theme="dark"] .offcanvas,
[data-theme="dark"] .offcanvas-body {
  color: var(--text) !important;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .input-group-text,
[data-theme="dark"] textarea,
[data-theme="dark"] select,
[data-theme="dark"] input {
  color: #f8fafc !important;
}

[data-theme="dark"] .form-control::placeholder,
[data-theme="dark"] textarea::placeholder,
[data-theme="dark"] input::placeholder {
  color: var(--text-light) !important;
  opacity: 1;
}

[data-theme="dark"] .btn-outline-secondary,
[data-theme="dark"] .btn-outline-dark,
[data-theme="dark"] .btn-light {
  color: #f8fafc;
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-body { padding: 20px; }

.global-announcement-wrap {
  margin-top: calc(var(--navbar-h) + 14px);
  animation: announcementBounce .7s cubic-bezier(.22,1,.36,1);
}

.global-announcement {
  position: relative;
  z-index: 999;
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 14px;
  border: 1px solid color-mix(in srgb, var(--announcement-color) 18%, var(--border));
  border-radius: 18px;
  background: color-mix(in srgb, var(--announcement-color) 12%, var(--surface));
  box-shadow:
    0 20px 45px rgba(15, 23, 42, .10),
    0 8px 20px rgba(15, 23, 42, .06);
  overflow: hidden;
}

@keyframes announcementBounce {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(.985);
  }
  55% {
    opacity: 1;
    transform: translateY(4px) scale(1.005);
  }
  78% {
    transform: translateY(-2px) scale(.998);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.global-announcement__rail {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(180deg, var(--announcement-color), color-mix(in srgb, var(--announcement-color) 60%, #ffffff));
}

.global-announcement__icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--announcement-color);
  background: color-mix(in srgb, var(--announcement-color) 14%, #ffffff);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--announcement-color) 16%, transparent);
  font-size: 1.1rem;
}

.global-announcement__content {
  min-width: 0;
  flex: 1 1 auto;
}

.global-announcement__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.global-announcement__chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .05em;
  color: var(--announcement-color);
  background: color-mix(in srgb, var(--announcement-color) 14%, #ffffff);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--announcement-color) 18%, transparent);
}

.global-announcement__eyebrow {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-light);
}

.global-announcement__title {
  font-size: 1.04rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.global-announcement__body {
  margin-top: 6px;
  font-size: .9rem;
  line-height: 1.6;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.global-announcement__actions {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

.global-announcement__btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  transition: all var(--transition);
}

.global-announcement__btn-edit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 700;
  color: var(--announcement-color);
  background: color-mix(in srgb, var(--announcement-color) 10%, #ffffff);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--announcement-color) 22%, transparent);
  white-space: normal;
}

.global-announcement__btn-edit:hover {
  background: color-mix(in srgb, var(--announcement-color) 16%, #ffffff);
}

.global-announcement__btn-close {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
}

.global-announcement__btn-close:hover {
  color: var(--announcement-color);
  background: color-mix(in srgb, var(--announcement-color) 10%, #ffffff);
}

[data-theme="dark"] .global-announcement {
  background: color-mix(in srgb, var(--announcement-color) 14%, #1e2330) !important;
  border-color: color-mix(in srgb, var(--announcement-color) 28%, #374151) !important;
  box-shadow:
    0 24px 55px rgba(0, 0, 0, .40),
    0 10px 24px rgba(0, 0, 0, .25);
}

[data-theme="dark"] .global-announcement__icon {
  background: color-mix(in srgb, var(--announcement-color) 22%, #2d3448) !important;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--announcement-color) 30%, transparent) !important;
}

[data-theme="dark"] .global-announcement__chip {
  background: color-mix(in srgb, var(--announcement-color) 22%, #2d3448) !important;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--announcement-color) 30%, transparent) !important;
}

[data-theme="dark"] .global-announcement__eyebrow { color: #9ca3af !important; }
[data-theme="dark"] .global-announcement__title   { color: #e5e7eb !important; }
[data-theme="dark"] .global-announcement__body    { color: #d1d5db !important; }

[data-theme="dark"] .global-announcement__btn-edit {
  background: color-mix(in srgb, var(--announcement-color) 18%, #2d3448) !important;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--announcement-color) 30%, transparent) !important;
}

[data-theme="dark"] .global-announcement__btn-edit:hover {
  background: color-mix(in srgb, var(--announcement-color) 28%, #2d3448) !important;
}

[data-theme="dark"] .global-announcement__btn-close { color: #9ca3af !important; }
[data-theme="dark"] .global-announcement__btn-close:hover {
  background: color-mix(in srgb, var(--announcement-color) 18%, #2d3448) !important;
  color: var(--announcement-color) !important;
}

/* ── Dark mode component overrides ─────────────────────────── */

/* Table wrapper & Bootstrap table internals */
[data-theme="dark"] .table-wrapper { background: var(--surface); }
/* Reset Bootstrap's --bs-table-bg on every cell, then re-colour each zone */
[data-theme="dark"] .table > :not(caption) > * > * {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
/* Header cells get a distinct darker shade */
[data-theme="dark"] .table thead th,
[data-theme="dark"] .table thead td {
  background-color: var(--surface-3) !important;
  color: var(--text-muted) !important;
  border-color: var(--border) !important;
}
/* Hover row */
[data-theme="dark"] .table tbody tr:hover > td,
[data-theme="dark"] .table tbody tr:hover > th {
  background-color: var(--surface-3) !important;
}
[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: rgba(255,255,255,.04) !important;
}
[data-theme="dark"] .table-bordered,
[data-theme="dark"] .table-bordered > :not(caption) > * > * { border-color: var(--border) !important; }

/* DataTables overrides */
[data-theme="dark"] .dataTables_wrapper { color: var(--text); }
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button { color: var(--text) !important; }
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current,
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { background: var(--primary) !important; color: #fff !important; border-color: var(--primary) !important; }
[data-theme="dark"] .dataTables_wrapper .dataTables_info { color: var(--text-muted); }

/* Cards */
[data-theme="dark"] .card { background: var(--surface) !important; border-color: var(--border) !important; }
[data-theme="dark"] .card-header { background: var(--surface-3) !important; border-color: var(--border) !important; }
[data-theme="dark"] .card-footer { background: var(--surface-3) !important; border-color: var(--border) !important; }

/* Modals */
[data-theme="dark"] .modal-content { background: var(--surface) !important; border-color: var(--border) !important; }
[data-theme="dark"] .modal-header { background: var(--surface-3); border-color: var(--border) !important; }
[data-theme="dark"] .modal-body   { background: var(--surface); }
[data-theme="dark"] .modal-footer { background: var(--surface-3); border-color: var(--border) !important; }

/* Dropdowns */
[data-theme="dark"] .dropdown-menu { background: var(--surface-2) !important; border-color: var(--border) !important; }
[data-theme="dark"] .dropdown-item { color: var(--text) !important; }
[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus { background: var(--surface-3) !important; color: var(--text) !important; }
[data-theme="dark"] .dropdown-divider { border-color: var(--border); }

/* Form inputs */
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .input-group-text,
[data-theme="dark"] textarea,
[data-theme="dark"] select { background-color: var(--surface-2) !important; border-color: var(--border) !important; }
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus { background-color: var(--surface) !important; border-color: var(--primary) !important; }

/* List groups */
[data-theme="dark"] .list-group-item { background: var(--surface); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .list-group-item:hover { background: var(--surface-3); }

/* Pagination */
[data-theme="dark"] .page-item .page-link { background: var(--surface); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .page-item.active .page-link { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-theme="dark"] .page-item.disabled .page-link { background: var(--surface-2); color: var(--text-muted); }

/* Alerts (Bootstrap) */
[data-theme="dark"] .alert { border-color: var(--border); }
[data-theme="dark"] .alert-info    { background: rgba( 13,202,240,.14); color: #7decff; border-color: rgba( 13,202,240,.3); }
[data-theme="dark"] .alert-success { background: rgba( 25,135, 84,.14); color: #6ee7a0; border-color: rgba( 25,135, 84,.3); }
[data-theme="dark"] .alert-warning { background: rgba(253,126, 20,.14); color: #ffc977; border-color: rgba(253,126, 20,.3); }
[data-theme="dark"] .alert-danger  { background: rgba(220, 53, 69,.14); color: #f08080; border-color: rgba(220, 53, 69,.3); }

/* Table load overlay */
[data-theme="dark"] .table-load-overlay,
[data-theme="dark"] [class*="load-overlay"] { background: rgba(30,35,48,.75); }

/* Connectivity badge */
[data-theme="dark"] .connectivity-badge         { background: rgba(25,135,84,.25); color: #6ee7a0; }
[data-theme="dark"] .connectivity-badge.offline { background: rgba(220,53,69,.25); color: #f08080; }

/* User dropdown danger hover */
[data-theme="dark"] .user-dropdown .dropdown-item.text-danger:hover { background: rgba(220,53,69,.18) !important; }

/* Nav drawer danger */
[data-theme="dark"] .drawer-item.danger:hover { background: rgba(220,53,69,.18); }

/* Offcanvas / drawer */
[data-theme="dark"] .offcanvas,
[data-theme="dark"] .offcanvas-body,
[data-theme="dark"] #nav-drawer { background: var(--surface) !important; }

/* Badges (Bootstrap built-in that appear on light bg) */
[data-theme="dark"] .badge.bg-light   { background: var(--surface-3) !important; color: var(--text) !important; }
[data-theme="dark"] .badge.text-dark,
[data-theme="dark"] .badge.text-body  { color: var(--text) !important; }

/* Tabs */
[data-theme="dark"] .nav-tabs { border-color: var(--border); }
[data-theme="dark"] .nav-tabs .nav-link { color: var(--text-muted); }
[data-theme="dark"] .nav-tabs .nav-link:hover { border-color: var(--border); color: var(--text); }
[data-theme="dark"] .nav-tabs .nav-link.active { background: var(--surface); border-color: var(--border) var(--border) var(--surface); color: var(--primary); }
[data-theme="dark"] .tab-content { background: transparent; }

/* Breadcrumb */
[data-theme="dark"] .breadcrumb-sm a { color: var(--primary); }

/* Page headings */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6,
[data-theme="dark"] .h1,
[data-theme="dark"] .h2,
[data-theme="dark"] .h3 {
  color: var(--text) !important;
  --bs-heading-color: var(--text);
}

/* Page-header subtitle ("app description") — brighter than text-muted */
[data-theme="dark"] .page-breadcrumb { color: #c9d0dc !important; }

/* Stat cards — ensure background even for the BS card component */
[data-theme="dark"] .card,
[data-theme="dark"] .card-body { background-color: var(--surface) !important; }

/* Misc utilities with hardcoded light colours */
[data-theme="dark"] .bg-light  { background-color: var(--surface-3) !important; }
[data-theme="dark"] .bg-white  { background-color: var(--surface)   !important; }
[data-theme="dark"] .border    { border-color: var(--border) !important; }
[data-theme="dark"] .text-dark { color: var(--text)   !important; }

/* Force body base in dark mode — prevents Bootstrap body-color bleed */
[data-theme="dark"] body {
  background-color: #252b3b !important;
  color: #e5e7eb !important;
}

/* ─────────────────────────────────────────────────────────────
   HARDCODED CRITICAL OVERRIDES
   Use raw hex values to bypass any CSS-variable cascade issue.
   These always win because they appear last at equal specificity.
   ───────────────────────────────────────────────────────────── */

/* Page header title & subtitle */
[data-theme="dark"] .page-header h1,
[data-theme="dark"] .page-header h2,
[data-theme="dark"] .page-header h3 { color: #e5e7eb !important; }
[data-theme="dark"] .page-header .page-breadcrumb { color: #c9d0dc !important; }

/* App-card (admin module cards) */
[data-theme="dark"] .app-card { background: #1e2330 !important; border-color: #374151 !important; }
[data-theme="dark"] .app-card-title { color: #e5e7eb !important; }
[data-theme="dark"] .app-card-desc  { color: #c9d0dc !important; }

/* Table headers — hardcoded so no variable resolution can fail */
[data-theme="dark"] table.table thead tr th,
[data-theme="dark"] table.table thead tr td {
  background-color: #2d3448 !important;
  color: #c9d0dc !important;
  border-color: #374151 !important;
}

/* Table body cells */
[data-theme="dark"] table.table tbody tr td,
[data-theme="dark"] table.table tbody tr th {
  background-color: #1e2330 !important;
  color: #e5e7eb !important;
  border-color: #374151 !important;
}

/* Table body row hover */
[data-theme="dark"] table.table tbody tr:hover td,
[data-theme="dark"] table.table tbody tr:hover th {
  background-color: #2d3448 !important;
}

/* Table wrapper card background */
[data-theme="dark"] .table-wrapper { background-color: #1e2330 !important; }

/* General stat / Bootstrap cards */
[data-theme="dark"] .card,
[data-theme="dark"] .card > .card-body { background-color: #1e2330 !important; }
[data-theme="dark"] .card > .card-header,
[data-theme="dark"] .card > .card-footer { background-color: #2d3448 !important; }

/* Stat cards */
[data-theme="dark"] .stat-card {
  background-color: #1e2330 !important;
  border-color: #374151 !important;
  box-shadow: 0 1px 4px rgba(0,0,0,.35) !important;
}
[data-theme="dark"] .stat-card .stat-value { color: #e5e7eb !important; }
[data-theme="dark"] .stat-card .stat-label { color: #9ca3af !important; }
[data-theme="dark"] .stat-card .stat-change.up   { color: #6ee7a0 !important; }
[data-theme="dark"] .stat-card .stat-change.down { color: #fca5a5 !important; }

@media (max-width: 991.98px) {
  .global-announcement {
    padding: 14px;
    gap: 12px;
    border-radius: 16px;
  }

  .global-announcement-wrap {
    margin-top: calc(var(--navbar-h) + 10px);
    padding-left: 12px;
    padding-right: 12px;
  }

  .global-announcement__actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 575.98px) {
  .global-announcement-wrap {
    padding-left: 10px;
    padding-right: 10px;
  }

  .global-announcement {
    padding: 12px;
    gap: 10px;
    border-radius: 14px;
  }

  .global-announcement__icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    font-size: 1rem;
  }

  .global-announcement__meta {
    gap: 8px;
    margin-bottom: 4px;
  }

  .global-announcement__chip,
  .global-announcement__eyebrow {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .global-announcement__title {
    font-size: .98rem;
  }

  .global-announcement__body {
    font-size: .84rem;
    line-height: 1.5;
  }

  .global-announcement__actions {
    justify-content: stretch;
  }

  .global-announcement__btn-edit {
    flex: 1 1 100%;
    justify-content: center;
  }

  .global-announcement__btn-close {
    margin-left: auto;
  }
}

/* Stat cards */
.stat-card {
  border-radius: var(--radius-lg);
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* ── Stat icon colour variants ───────────────────────────────────── */
.si-success { background: #e8f5ee; color: #1a6b3a; }
.si-warning  { background: #fef3c7; color: #b45309; }
.si-danger   { background: #fee2e2; color: #991b1b; }
.si-info     { background: #dbeafe; color: #1e40af; }
.si-pending  { background: #fff3cd; color: #856404; }
.si-muted    { background: #f1f5f9; color: #94a3b8; }

[data-theme="dark"] .si-success { background: rgba(25,135,84,.22)   !important; color: #6ee7a0 !important; }
[data-theme="dark"] .si-warning { background: rgba(180,83,9,.28)    !important; color: #fcd34d !important; }
[data-theme="dark"] .si-danger  { background: rgba(153,27,27,.28)   !important; color: #fca5a5 !important; }
[data-theme="dark"] .si-info    { background: rgba(30,64,175,.28)   !important; color: #93c5fd !important; }
[data-theme="dark"] .si-pending { background: rgba(133,100,4,.28)   !important; color: #fcd34d !important; }
[data-theme="dark"] .si-muted   { background: rgba(100,116,139,.22) !important; color: #94a3b8 !important; }

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
  margin: 8px 0 4px;
}

.stat-card .stat-label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-card .stat-change {
  font-size: .75rem;
  font-weight: 600;
  margin-top: 8px;
}

.stat-change.up   { color: #198754; }
.stat-change.down { color: #dc3545; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.table {
  margin: 0;
  border-color: var(--border);
}

.table thead th {
  background: var(--surface-3);
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  padding: 12px 16px;
}

.table tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  border-color: var(--border);
  font-size: .875rem;
}

.table tbody tr:hover { background: var(--surface-3); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-draft        { color: var(--status-draft);        background: #f1f3f5; }
.status-submitted    { color: var(--status-submitted);    background: #dbeafe; }
.status-under_review { color: var(--status-under_review); background: #fff3cd; }
.status-approved     { color: var(--status-approved);     background: #d1fae5; }
.status-rejected     { color: var(--status-rejected);     background: #fee2e2; }
.status-revised      { color: var(--status-revised);      background: #cff4fc; }

[data-theme="dark"] .status-draft        { background: rgba(108, 117, 125, .22); }
[data-theme="dark"] .status-submitted    { background: rgba( 13, 110, 253, .22); }
[data-theme="dark"] .status-under_review { background: rgba(253, 126,  20, .22); }
[data-theme="dark"] .status-approved     { background: rgba( 25, 135,  84, .22); }
[data-theme="dark"] .status-rejected     { background: rgba(220,  53,  69, .22); }
[data-theme="dark"] .status-revised      { background: rgba( 13, 202, 240, .22); }

/* ── Forms ────────────────────────────────────────────────────── */
.form-label {
  font-weight: 600;
  font-size: .825rem;
  color: var(--text);
  margin-bottom: 5px;
}

.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  padding: 9px 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,107,58,.15);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.input-group-text {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .875rem;
}

/* Multi-step form */
.stepper {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.step-item {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.step-circle {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 2px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
  z-index: 1;
}

.step-item.active .step-circle {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.step-item.done .step-circle {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.step-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
  white-space: nowrap;
}

.step-item.active .step-label { color: var(--primary); }

.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 4px;
  margin-bottom: 20px;
  transition: background var(--transition);
}

.step-item.done + .step-item .step-line,
.step-item.done .step-line { background: var(--accent); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  border-radius: 8px;
  font-weight: 600;
  font-size: .875rem;
  padding: 8px 16px;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn-sm { padding: 5px 11px; font-size: .8rem; }
.btn-xs { padding: 3px 8px;  font-size: .72rem; }

/* ── Modals ───────────────────────────────────────────────────── */
.modal-content {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  background: var(--surface);
}

.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
}

.modal-title { font-size: 1rem; font-weight: 700; }

.modal-body { padding: 24px; }
.modal-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}

/* ── Map ─────────────────────────────────────────────────────── */
#inspection-map, .leaflet-container {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 1;
}

/* ── Notifications panel ─────────────────────────────────────── */
.notif-panel {
  position: fixed;
  top: var(--navbar-h);
  right: 0;
  width: 380px;
  max-height: calc(100vh - var(--navbar-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition);
}

.notif-panel.open { transform: translateX(0); }

.notif-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.notif-panel-title {
  display: block;
  font-size: .95rem;
  font-weight: 700;
  line-height: 1.2;
}

.notif-panel-meta {
  margin-top: 4px;
}

.notif-panel-count {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(46, 184, 106, .12);
  color: var(--primary);
  font-size: .72rem;
  font-weight: 700;
}

.notif-panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notif-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.notif-item {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  margin-bottom: 8px;
  background: transparent;
  cursor: pointer;
  transition: background var(--transition);
  text-align: left;
}

.notif-item:hover { background: var(--surface-3); border-color: var(--border); }
.notif-item.unread { background: rgba(46, 184, 106, .12); border-color: rgba(46, 184, 106, .25); }
.notif-item.unread:hover { background: rgba(46, 184, 106, .18); }

.notif-item-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  background: transparent;
  flex: 0 0 10px;
}

.notif-item.unread .notif-item-indicator {
  background: #2eb86a;
  box-shadow: 0 0 0 4px rgba(46, 184, 106, .15);
}

.notif-item-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.notif-item-topline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notif-title {
  font-size: .82rem;
  font-weight: 700;
  line-height: 1.35;
}

.notif-chip {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
}

.notif-msg {
  font-size: .77rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.notif-time {
  font-size: .68rem;
  color: var(--text-light);
}

.notif-state {
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  font-size: .84rem;
  border: 1px dashed var(--border);
  border-radius: 14px;
  margin: 6px;
  padding: 18px;
}

.notif-state.error {
  color: #dc3545;
}

@keyframes notifPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, .28); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ── Offline indicator ───────────────────────────────────────── */
#offline-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #dc3545;
  color: #fff;
  text-align: center;
  font-size: .8rem;
  font-weight: 600;
  padding: 6px 16px;
  z-index: 9999;
  display: none;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

body.offline #offline-bar { display: flex; }

#sync-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fd7e14;
  color: #fff;
  text-align: center;
  font-size: .8rem;
  font-weight: 600;
  padding: 6px 16px;
  z-index: 9998;
  display: none;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

body.syncing #sync-bar { display: flex; }

/* ── Permission matrix ───────────────────────────────────────── */
.perm-matrix {
  width: 100%;
  border-collapse: collapse;
}

.perm-matrix th, .perm-matrix td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-size: .8rem;
  vertical-align: middle;
}

.perm-matrix th { background: var(--surface-3); font-weight: 700; }
.perm-matrix td:first-child { font-weight: 600; }

.perm-check {
  width: 20px; height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
}

.perm-group-header {
  background: var(--primary-light);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--primary);
  padding: 6px 12px;
}

/* ── Login page ──────────────────────────────────────────────── */
#login-page {
  min-height: 100vh;
  display: flex;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary) 100%);
  position: relative;
  overflow: hidden;
}

#login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-card {
  width: 440px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0,0,0,.3);
  padding: 40px;
  position: relative;
  z-index: 1;
}

.login-logo {
  width: 64px; height: 64px;
  background: var(--primary);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 1.8rem;
  color: #fff;
}

/* ── Toasts ───────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--navbar-h) + 12px);
  right: 16px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.app-toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: slideInRight .25s ease;
}

.app-toast .toast-icon { font-size: 1.1rem; margin-top: 1px; flex-shrink: 0; }
.app-toast .toast-body { flex: 1; }
.app-toast .toast-title { font-size: .85rem; font-weight: 700; }
.app-toast .toast-msg { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.app-toast .toast-close { background: none; border: none; padding: 0; color: var(--text-light); cursor: pointer; }

.app-toast.toast-success { border-left: 3px solid #198754; }
.app-toast.toast-error   { border-left: 3px solid #dc3545; }
.app-toast.toast-warning { border-left: 3px solid #fd7e14; }
.app-toast.toast-info    { border-left: 3px solid #0dcaf0; }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Utilities ────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.font-monospace  { font-family: 'Fira Code', 'Consolas', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  z-index: 10;
  backdrop-filter: blur(2px);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 576px) {
  #page-content { padding: 16px; }
  .stat-card    { padding: 14px; }
  .login-card   { padding: 24px; }
}

/* ═══════════════════════════════════════════════════════════════
   REDESIGNED NAVBAR
═══════════════════════════════════════════════════════════════ */
#main-navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 12px rgba(0,0,0,.07);
  height: var(--navbar-h);
  padding: 0 20px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1040;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-hamburger {
  background: none;
  border: none;
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.nav-hamburger:hover { background: var(--surface-3); color: var(--primary); }

#main-navbar .navbar-brand {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; flex-shrink: 0;
  margin-right: 4px;
}
#main-navbar .brand-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1rem; flex-shrink: 0;
}
#main-navbar .brand-name {
  font-weight: 700; font-size: .92rem;
  color: var(--text);
  white-space: nowrap;
}
.nav-divider {
  width: 1px; height: 22px;
  background: var(--border);
  flex-shrink: 0; margin: 0 4px;
}

/* Desktop pill-links */
.desktop-nav {
  display: flex; align-items: center; gap: 2px;
  overflow-x: auto; flex: 1;
  scrollbar-width: none; min-width: 0;
}
.desktop-nav::-webkit-scrollbar { display: none; }

.nav-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: .82rem; font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.nav-pill:hover { background: var(--surface-3); color: var(--text); }
.nav-pill.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.nav-pill i { font-size: .9rem; }
.nav-pill .pill-badge {
  background: #ef4444; color: #fff;
  font-size: .6rem; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; padding: 0 3px;
  display: inline-flex; align-items: center; justify-content: center;
}

/* Admin dropdown in desktop nav */
.nav-pill-dropdown { position: relative; }
.nav-pill-dropdown .nav-pill { cursor: pointer; }
.nav-pill-dropdown .dropdown-menu {
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.13);
  border: 1px solid var(--border);
  padding: 6px; min-width: 200px;
  background: var(--surface);
}
.nav-pill-dropdown .dropdown-item {
  border-radius: 8px; font-size: .83rem;
  padding: 8px 12px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.nav-pill-dropdown .dropdown-item:hover,
.nav-pill-dropdown .dropdown-item.active {
  background: var(--primary-light); color: var(--primary);
}
.nav-pill-dropdown .dropdown-item i { width: 16px; text-align: center; }

/* Right-side action buttons */
.navbar-actions {
  display: flex; align-items: center; gap: 3px;
  flex-shrink: 0; margin-left: auto;
}
.navbar-actions .icon-btn {
  background: none; border: none;
  width: 36px; height: 36px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative;
  color: var(--text-muted); font-size: 1.05rem;
  transition: background .15s, color .15s;
}
.navbar-actions .icon-btn:hover { background: var(--surface-3); color: var(--primary); }
.navbar-actions .icon-btn .notif-badge {
  position: absolute; top: 3px; right: 3px;
  width: 15px; height: 15px;
  background: #ef4444; color: #fff;
  border-radius: 50%; font-size: .55rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}
.connectivity-badge {
  font-size: .68rem; font-weight: 600;
  padding: 3px 8px; border-radius: 20px;
  background: #d1fae5; color: #065f46;
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.connectivity-badge.offline { background: #fee2e2; color: #991b1b; }
.user-avatar {
  width: 33px; height: 33px;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
  cursor: pointer; flex-shrink: 0;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.user-avatar:hover { border-color: var(--primary); }
.user-dropdown .dropdown-menu {
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.13);
  border: 1px solid var(--border);
  padding: 6px; min-width: 200px;
  background: var(--surface);
}
.user-dropdown .dropdown-item {
  border-radius: 8px; font-size: .83rem;
  padding: 8px 12px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.user-dropdown .dropdown-item:hover { background: var(--surface-3); }
.user-dropdown .dropdown-item.text-danger:hover { background: #fee2e2; }
.user-dropdown .dropdown-item i { width: 16px; text-align: center; }
.user-dropdown .dropdown-header {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE NAV DRAWER
═══════════════════════════════════════════════════════════════ */
#nav-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  z-index: 1045;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
#nav-backdrop.open { opacity: 1; pointer-events: all; }

#nav-drawer {
  position: fixed; top: 0; left: 0;
  width: 275px; height: 100vh;
  background: var(--surface);
  z-index: 1046;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .26s cubic-bezier(.4,0,.2,1);
  box-shadow: 8px 0 32px rgba(0,0,0,.16);
  overflow: hidden;
}
#nav-drawer.open { transform: translateX(0); }

.drawer-header {
  background: linear-gradient(135deg, var(--primary) 0%, #124a28 100%);
  padding: 20px 16px 16px;
  display: flex; align-items: center; gap: 10px;
  color: #fff; flex-shrink: 0;
}
.drawer-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.drawer-user-info { flex: 1; min-width: 0; }
.drawer-name { font-weight: 700; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-role { font-size: .7rem; opacity: .8; margin-top: 1px; }
.drawer-close-btn {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 7px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.drawer-close-btn:hover { background: rgba(255,255,255,.28); }

.drawer-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.drawer-section-label {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-light);
  padding: 10px 10px 4px; margin-top: 4px;
}
.drawer-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  font-size: .86rem; font-weight: 500;
  color: var(--text); text-decoration: none;
  transition: background .15s, color .15s; margin-bottom: 1px;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.drawer-item:hover { background: var(--surface-3); color: var(--text); }
.drawer-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.drawer-item.danger { color: #dc3545; }
.drawer-item.danger:hover { background: #fee2e2; }
.drawer-item i { width: 18px; text-align: center; font-size: .95rem; flex-shrink: 0; }
.drawer-item .drawer-badge {
  margin-left: auto; background: #ef4444; color: #fff;
  font-size: .6rem; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
}
.drawer-item.sub { padding-left: 28px; }

.drawer-footer { padding: 8px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════
   NOTIFICATION PANEL (updated for new navbar height)
═══════════════════════════════════════════════════════════════ */
.notif-panel {
  top: var(--navbar-h) !important;
  max-height: calc(100vh - var(--navbar-h)) !important;
}

@media (max-width: 576px) {
  .notif-panel {
    width: 100%;
    border-left: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
   IN-APP CHAT
═══════════════════════════════════════════════════════════════ */
#chat-fab {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem;
  box-shadow: 0 4px 20px rgba(26,107,58,.45);
  z-index: 1031;
  transition: transform .2s, background .2s, box-shadow .2s;
}
#chat-fab:hover { transform: scale(1.08); background: var(--primary-dark); }
#chat-fab.active { background: var(--primary-dark); box-shadow: 0 2px 12px rgba(26,107,58,.35); }
#chat-fab-badge {
  position: absolute; top: -1px; right: -1px;
  background: #ef4444; color: #fff;
  font-size: .58rem; font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}

#chat-sender-preview {
  position: fixed;
  bottom: 88px; right: 82px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  font-size: .78rem;
  max-width: 200px;
  z-index: 1031;
  pointer-events: none;
  animation: cspFadeIn .22s ease;
}
@keyframes cspFadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.csp-name { font-weight: 700; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.csp-msg  { color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 576px) { #chat-sender-preview { bottom: auto; top: 72px; right: 12px; } }

#chat-panel {
  position: fixed;
  bottom: 86px; right: 24px;
  width: 340px; height: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0,0,0,.16);
  z-index: 1030;
  display: flex; flex-direction: column;
  transform: scale(.92) translateY(16px);
  opacity: 0; pointer-events: none;
  transition: all .22s cubic-bezier(.34,1.46,.64,1);
  overflow: hidden;
}
#chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1; pointer-events: all;
}

.chat-panel-header {
  padding: 13px 14px;
  background: linear-gradient(135deg, var(--primary) 0%, #0f5e30 100%);
  color: #fff;
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; border-radius: 18px 18px 0 0;
}
.chat-header-icon {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info .chat-title { font-weight: 700; font-size: .88rem; }
.chat-header-info .chat-online { font-size: .7rem; opacity: .85; margin-top: 1px; }
.chat-close-btn {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 28px; height: 28px; border-radius: 7px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.chat-close-btn:hover { background: rgba(255,255,255,.28); }

.chat-messages-wrap {
  flex: 1; overflow-y: auto; padding: 12px 10px;
  display: flex; flex-direction: column; gap: 6px;
  scroll-behavior: smooth;
}
.chat-messages-wrap::-webkit-scrollbar { width: 4px; }
.chat-messages-wrap::-webkit-scrollbar-track { background: transparent; }
.chat-messages-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-sender { font-size: .67rem; font-weight: 700; color: var(--text-muted); margin-bottom: 2px; padding: 0 4px; }
.chat-bubble {
  padding: 8px 12px;
  border-radius: 14px 14px 14px 4px;
  font-size: .82rem; line-height: 1.45;
  word-break: break-word; color: var(--text);
  background: var(--surface-3);
}
.chat-msg.mine .chat-bubble {
  background: var(--primary); color: #fff;
  border-radius: 14px 14px 4px 14px;
}
.chat-time { font-size: .62rem; color: var(--text-light); margin-top: 3px; padding: 0 4px; }

.chat-day-divider {
  text-align: center; font-size: .65rem; font-weight: 600;
  color: var(--text-light); padding: 4px 0;
  display: flex; align-items: center; gap: 8px;
}
.chat-day-divider::before, .chat-day-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.chat-input-area {
  padding: 10px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); flex-shrink: 0;
}
.chat-input-area textarea {
  flex: 1; border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 12px;
  font-size: .83rem; background: var(--surface-2);
  color: var(--text); outline: none;
  resize: none; max-height: 80px; min-height: 36px;
  line-height: 1.4; font-family: inherit;
  transition: border-color .15s;
}
.chat-input-area textarea:focus { border-color: var(--primary); }
.chat-send-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.chat-send-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.chat-send-btn:disabled { background: var(--border); cursor: not-allowed; transform: none; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); font-size: .82rem; gap: 8px;
  padding: 20px;
}
.chat-empty i { font-size: 2rem; opacity: .4; }

/* ── Chat: inbox / DM screens ──────────────────────────────────── */
.chat-back-btn {
  background: rgba(255,255,255,.2); border: none;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; flex-shrink: 0;
  transition: background .15s; font-size: .85rem;
}
.chat-back-btn:hover { background: rgba(255,255,255,.38); }

.chat-header-icon.user-initial {
  font-size: .72rem; font-weight: 700; letter-spacing: 0;
}

/* Inbox screen */
#chat-inbox-screen {
  flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
#chat-chat-screen {
  flex: 1; flex-direction: column; min-height: 0;
}
.chat-inbox-search {
  padding: 9px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-inbox-search input {
  width: 100%; border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 14px; font-size: .82rem;
  background: var(--surface-2); color: var(--text); outline: none;
  transition: border-color .15s, background .15s;
}
.chat-inbox-search input:focus { border-color: var(--primary); background: var(--surface); }

.chat-user-list {
  flex: 1; overflow-y: auto;
}
.chat-user-list::-webkit-scrollbar { width: 3px; }
.chat-user-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-inbox-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; cursor: pointer;
  transition: background .12s; border-bottom: 1px solid transparent;
}
.chat-inbox-item:hover { background: var(--surface-2); }
.chat-inbox-item:active { background: var(--primary-light); }

.chat-inbox-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
}
.chat-inbox-avatar.team {
  background: linear-gradient(135deg, var(--primary) 0%, #0f5e30 100%);
  color: #fff; font-size: 1rem;
}
.chat-inbox-avatar.user {
  background: var(--primary-light); color: var(--primary);
}

.chat-inbox-info { flex: 1; min-width: 0; }
.chat-inbox-name {
  font-size: .84rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-inbox-sub {
  font-size: .72rem; color: var(--text-muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chat-inbox-badge {
  background: #ef4444; color: #fff;
  font-size: .6rem; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  padding: 0 4px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-inbox-loading {
  padding: 20px; text-align: center; color: var(--text-muted); opacity: .6;
}
.chat-inbox-empty {
  padding: 20px; text-align: center; font-size: .8rem; color: var(--text-muted);
}

@media (max-width: 576px) {
  #chat-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%; height: 72vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }
  #chat-panel.open { transform: translateY(0); }
  #chat-fab { bottom: 16px; right: 16px; }
  #main-navbar { padding: 0 12px; }
  .navbar-actions { gap: 1px; }
  .connectivity-badge { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD IMPROVEMENTS
═══════════════════════════════════════════════════════════════ */
.welcome-banner {
  border-radius: 16px;
  padding: 22px 24px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--primary) 0%, #0f5e30 60%, #1a3a52 100%);
  color: #fff; position: relative; overflow: hidden;
}
.welcome-banner::before {
  content: '';
  position: absolute; top: -30px; right: -30px;
  width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.welcome-banner::after {
  content: '';
  position: absolute; bottom: -40px; right: 80px;
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,.04);
}
.welcome-greeting { font-size: 1.4rem; font-weight: 800; line-height: 1.2; margin-bottom: 4px; }
.welcome-sub { font-size: .82rem; opacity: .82; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.welcome-sub .role-chip {
  background: rgba(255,255,255,.18); padding: 2px 10px;
  border-radius: 20px; font-size: .75rem; font-weight: 600;
}

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 14px 14px;
  cursor: pointer;
  transition: all .2s;
  text-align: center; height: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  position: relative;
  box-shadow: var(--shadow);
}
.app-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(0,0,0,.12);
  border-color: transparent;
}
.app-card-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 1.55rem;
}
.app-card-title { font-weight: 700; font-size: .88rem; color: var(--text); line-height: 1.25; }
.app-card-desc  { font-size: .73rem; color: var(--text-muted); line-height: 1.4; }
.app-card-badge { position: absolute; top: 9px; right: 9px; font-size: .62rem; }

.section-heading {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted);
  margin-bottom: 12px; margin-top: 4px;
  display: flex; align-items: center; gap: 8px;
}
.section-heading::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* Page content top padding matches new navbar height */
#page-content {
  padding-top: calc(var(--navbar-h) + 18px) !important;
}
