:root {
  --primary: #0a2540;
  --primary-light: #1a3a5c;
  --accent: #1e6bb8;
  --accent-soft: #e8f1fa;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #1a2332;
  --text-muted: #6b7a90;
  --border: #dce3ee;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --success: #198754;
  --danger: #dc3545;
  --warning: #ffc107;
  --shadow: 0 2px 12px rgba(10, 37, 64, 0.08);
  --radius: 12px;
}

[data-theme="dark"] {
  --primary: #0d2137;
  --primary-light: #16324f;
  --accent: #4da3ff;
  --accent-soft: #1a2d45;
  --bg: #0b1522;
  --surface: #122033;
  --text: #e8eef6;
  --text-muted: #8fa0b5;
  --border: #243447;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #0a4d8c; }
[data-theme="dark"] a:hover { color: #9fd0ff; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary) 0%, #071a2e 100%);
  color: #fff;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040; /* above overlay (1030), below Bootstrap modal (1055) */
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  -webkit-overflow-scrolling: touch;
}

.sidebar-brand {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .75rem;
}

.sidebar-brand .logo,
.brand-logo-img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}
.sidebar-brand .logo {
  background: linear-gradient(135deg, #2b7cd3, #0d4a8a);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .9rem;
  color: #fff;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin: 0 auto;
  box-shadow: 0 8px 24px rgba(10, 37, 64, 0.25);
}

.sidebar-brand h1 {
  font-size: .95rem;
  margin: 0;
  line-height: 1.25;
  font-weight: 600;
}

.sidebar-brand small {
  display: block;
  opacity: .65;
  font-size: .7rem;
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem .75rem;
}

.nav-section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .45;
  padding: .75rem .75rem .35rem;
  margin-top: .25rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: rgba(255,255,255,.78);
  padding: .65rem .85rem;
  border-radius: 10px;
  margin-bottom: 2px;
  font-size: .9rem;
  transition: .15s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.sidebar-nav a.active {
  background: rgba(30, 107, 184, .45);
  box-shadow: inset 3px 0 0 #4da3ff;
}

.sidebar-nav .bi { font-size: 1.1rem; opacity: .9; }

.sidebar-logout {
  margin-top: .35rem !important;
  padding-top: .35rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-logout-btn {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: 100%;
  color: #ffb4b4;
  background: transparent;
  border: 0;
  padding: .65rem .85rem;
  border-radius: 10px;
  font-size: .9rem;
  text-align: left;
  cursor: pointer;
  transition: .15s;
}
.sidebar-logout-btn:hover {
  background: rgba(220, 53, 69, .2);
  color: #fff;
}
.sidebar-logout-btn .bi { font-size: 1.1rem; }

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1025; /* below mobile sidebar overlay/drawer so menu can cover content */
  box-shadow: var(--shadow);
}

.topbar-left { display: flex; align-items: center; gap: .75rem; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.content { padding: 1.25rem; flex: 1; }

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

.page-header h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
  height: 100%;
  transition: transform .15s, box-shadow .15s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(10,37,64,.12);
}

.stat-card .label {
  color: var(--text-muted);
  font-size: .82rem;
  font-weight: 500;
  margin-bottom: .35rem;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--primary);
}

[data-theme="dark"] .stat-card .value { color: #8ec5ff; }

.stat-card .icon-wrap {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.25rem;
}

.stat-card.total .icon-wrap { background: #e8f1fa; color: #1e6bb8; }
.stat-card.done .icon-wrap { background: #e6f6ed; color: #198754; }
.stat-card.ongoing .icon-wrap { background: #e7f1ff; color: #0d6efd; }
.stat-card.problem .icon-wrap { background: #fde8ea; color: #dc3545; }

/* Avoid Bootstrap .progress conflict — never use class "progress" on stat-card */
.stat-card.ongoing {
  display: block;
  height: 100%;
  overflow: visible;
  background: var(--surface);
}

[data-theme="dark"] .stat-card.total .icon-wrap { background: #1a2d45; }
[data-theme="dark"] .stat-card.done .icon-wrap { background: #143528; }
[data-theme="dark"] .stat-card.ongoing .icon-wrap { background: #152a45; }
[data-theme="dark"] .stat-card.problem .icon-wrap { background: #3a1a20; }

.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card-panel .card-head {
  padding: .9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-panel .card-body { padding: 1.15rem; }

.table {
  --bs-table-color: var(--text);
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--border);
  --bs-table-striped-bg: var(--accent-soft);
  --bs-table-striped-color: var(--text);
  --bs-table-hover-bg: var(--accent-soft);
  --bs-table-hover-color: var(--text);
  color: var(--text);
  background-color: transparent;
}
.table > :not(caption) > * > * {
  color: var(--text);
  background-color: transparent;
  border-bottom-color: var(--border);
}
.table thead th {
  background: var(--accent-soft) !important;
  color: var(--text) !important;
  font-weight: 600;
  font-size: .82rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td, .table th { vertical-align: middle; border-color: var(--border); color: var(--text); }
.table-hover tbody tr:hover > * { background: var(--accent-soft); color: var(--text); }
.table a { color: var(--accent); }
.table code { color: var(--text); background: var(--accent-soft); padding: .1rem .35rem; border-radius: 4px; }
.table .fw-semibold { color: var(--text); }
.table .small, .table .text-muted { color: var(--text-muted) !important; }

[data-theme="dark"] .table,
[data-theme="dark"] .table > :not(caption) > * > * {
  --bs-table-color: #e8eef6;
  --bs-table-hover-color: #ffffff;
  color: #e8eef6;
}
[data-theme="dark"] .table a { color: #8ec5ff; }
[data-theme="dark"] .table a:hover { color: #c5e2ff; }
[data-theme="dark"] .table code { color: #e8eef6; background: #1a2d45; }
[data-theme="dark"] .text-muted { color: #9aabc0 !important; }
[data-theme="dark"] .card-panel,
[data-theme="dark"] .card-panel .card-body,
[data-theme="dark"] .card-panel .card-head {
  color: var(--text);
}

.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: #185a9e;
  --bs-btn-hover-border-color: #185a9e;
}

.btn-outline-primary {
  --bs-btn-color: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
}

.form-control, .form-select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-radius: 10px;
}
.form-control:focus, .form-select:focus {
  background: var(--surface);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 .2rem rgba(30,107,184,.15);
}
.form-label { font-weight: 500; font-size: .88rem; color: var(--text-muted); }

.badge { font-weight: 500; }

.search-box {
  position: relative;
  min-width: 220px;
}
.search-box input {
  padding-left: 2.2rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.search-box .bi-search {
  position: absolute;
  left: .85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.global-search-results {
  position: absolute;
  top: 110%;
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1050;
  max-height: 320px;
  overflow-y: auto;
  display: none;
}
.global-search-results.show { display: block; }
.global-search-results a {
  display: block;
  padding: .65rem 1rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.global-search-results a:hover { background: var(--accent-soft); }

#map, .map-box {
  height: 420px;
  border-radius: var(--radius);
  z-index: 1;
  border: 1px solid var(--border);
}

.map-full { height: calc(100vh - var(--topbar-h) - 140px); min-height: 480px; }

.progress { height: 8px; border-radius: 999px; background: var(--border); }
.progress-bar { background: linear-gradient(90deg, #1e6bb8, #4da3ff); }

.timeline {
  position: relative;
  padding-left: 1.5rem;
}
.timeline::before {
  content: '';
  position: absolute;
  left: .4rem; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding-bottom: 1.25rem;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.22rem; top: .35rem;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--accent);
}
.timeline-item .time {
  font-size: .75rem;
  color: var(--text-muted);
}

.gallery img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(30,107,184,.25), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(10,37,64,.35), transparent 50%),
    linear-gradient(135deg, #0a2540 0%, #0d3a66 50%, #071a2e 100%);
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  color: var(--text);
}

.login-card .brand {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-card .brand .logo {
  width: 56px; height: 56px;
  margin: 0 auto .75rem;
  border-radius: 14px;
  background: linear-gradient(135deg, #2b7cd3, #0a2540);
  display: grid; place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
}
.login-card .brand .login-logo {
  margin: 0 auto .75rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .65rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: .85rem;
}
.user-chip .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: .75rem;
  font-weight: 700;
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.sidebar-toggle {
  display: none;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.12);
  color: #fff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

body.sidebar-open {
  overflow: hidden;
}
body.sidebar-open .sidebar-nav {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.alert { border-radius: 10px; }

.modal-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-header, .modal-footer {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}
.modal-body { background: var(--surface); color: var(--text); }
.modal-backdrop { z-index: 1050; }
.modal { z-index: 1055; }
.modal-title { color: var(--text); }
.modal .form-control,
.modal .form-select {
  background: var(--bg) !important;
  color: var(--text) !important;
  border-color: var(--border);
}
.modal .form-label { color: var(--text-muted); }
.modal .btn-close {
  filter: none;
}
[data-theme="dark"] .modal .btn-close {
  filter: invert(1) grayscale(100%);
  opacity: .75;
}
[data-theme="dark"] .modal-content {
  background: #152536 !important;
  border-color: #2a3f55;
}
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer,
[data-theme="dark"] .modal-body {
  background: #152536;
  color: #e8eef6;
}

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.leaflet-popup-content {
  margin: 12px 14px;
  min-width: 160px;
  color: #1a2332;
}
.leaflet-popup-content .map-popup-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 12px;
  background: #1e6bb8;
  color: #fff !important;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none !important;
}
.leaflet-popup-content .map-popup-btn:hover {
  background: #155a9c;
  color: #fff !important;
}

.pagination .page-link {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.pagination .page-item.active .page-link {
  background: var(--accent);
  border-color: var(--accent);
}

.file-list a {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: .5rem;
  color: var(--text);
}
.file-list a:hover { background: var(--accent-soft); }

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(30, 107, 184, .25) !important;
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--accent) !important;
  color: #fff !important;
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translate3d(-105%, 0, 0);
    -webkit-transform: translate3d(-105%, 0, 0);
    width: min(var(--sidebar-w), 86vw);
    max-width: 320px;
    z-index: 1040;
    box-shadow: 8px 0 28px rgba(0, 0, 0, .28);
  }
  .sidebar.open {
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
  }
  .main-wrap { margin-left: 0; }
  .topbar { z-index: 1025; }
  .sidebar-toggle {
    display: inline-grid !important;
    place-items: center;
    min-width: 42px;
    min-height: 42px;
    position: relative;
    z-index: 1026;
  }
  .sidebar-close { display: inline-flex; }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 1030; /* below sidebar (1040), above page content */
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar-overlay.show {
    display: block;
  }
  .search-box { min-width: 140px; max-width: 180px; }
  #map, .map-box { height: 300px; }
  .map-full { height: 55vh; min-height: 320px; }

  /* Larger touch targets in mobile menu */
  .sidebar-nav a {
    min-height: 44px;
    padding: .75rem .9rem;
  }
}

@media (max-width: 575.98px) {
  .content { padding: .85rem; }
  .stat-card .value { font-size: 1.4rem; }
  .page-header h2 { font-size: 1.15rem; }
  .table-responsive { font-size: .85rem; }
}
