/* ============================================================
   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"] {
  --primary:       #2eb86a;
  --primary-dark:  #1a6b3a;
  --primary-light: #0d2b1a;
  --surface:       #1e2330;
  --surface-2:     #252b3b;
  --surface-3:     #2d3448;
  --border:        #374151;
  --text:          #e5e7eb;
  --text-muted:    #9ca3af;
  --text-light:    #6b7280;
}

/* ── 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: -4px; right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.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;
}

/* ── 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; }

/* 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-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; }

/* ── 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-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.notif-item:hover { background: var(--surface-3); }
.notif-item.unread { background: var(--primary-light); }
.notif-item.unread:hover { background: var(--accent-light); }

.notif-title { font-size: .8rem; font-weight: 700; margin-bottom: 2px; }
.notif-msg   { font-size: .77rem; color: var(--text-muted); }
.notif-time  { font-size: .68rem; color: var(--text-light); margin-top: 4px; }

/* ── 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;
}

/* ═══════════════════════════════════════════════════════════════
   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-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;
}
