/* ============================================================
   CDDP - City Digital Data Platform  |  Style Sheet
   ============================================================ */

:root {
  --nav-h: 60px;
  --primary: #1a56db;
  --primary-dark: #1244b0;
  --accent: #0ea5e9;
  --bg-dark: #0f172a;
  --bg-panel: rgba(15, 23, 42, 0.95);
  --bg-panel-light: rgba(255,255,255,0.97);
  --text-light: #f1f5f9;
  --text-muted: #94a3b8;
  --border: rgba(255,255,255,0.1);
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --transition: 0.25s ease;
}

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

html, body {
  height: 100%;
  font-family: 'Sarabun', sans-serif;
  font-size: 15px;
  background: #1a1a2e;
  overflow: hidden;
}

/* ── TOP NAV ────────────────────────────────────────────── */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 1000;
  backdrop-filter: blur(8px);
}

.topnav__brand { display: flex; align-items: center; gap: 12px; }

.topnav__logo {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px;
  flex-shrink: 0;
}

.topnav__title { display: flex; flex-direction: column; }
.topnav__title-main { color: var(--text-light); font-weight: 700; font-size: 15px; line-height: 1.2; }
.topnav__title-sub  { color: var(--text-muted); font-size: 12px; }

.topnav__actions { display: flex; align-items: center; gap: 12px; }

/* Map style switcher */
.map-style-switcher { display: flex; gap: 4px; background: rgba(255,255,255,0.07); border-radius: 8px; padding: 3px; }

.map-style-btn {
  background: none; border: none; color: var(--text-muted);
  width: 34px; height: 34px; border-radius: 6px; cursor: pointer;
  font-size: 14px; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.map-style-btn:hover  { background: rgba(255,255,255,0.1); color: var(--text-light); }
.map-style-btn.active { background: var(--primary); color: #fff; }

/* Alert bell */
.alert-wrapper { position: relative; }

.alert-btn {
  background: rgba(255,255,255,0.07); border: none;
  width: 40px; height: 40px; border-radius: 10px;
  color: var(--text-muted); font-size: 17px;
  cursor: pointer; position: relative;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.alert-btn:hover { background: rgba(255,255,255,0.15); color: var(--text-light); }
.alert-btn.has-alerts { color: #f59e0b; }

.alert-badge {
  position: absolute; top: 4px; right: 4px;
  background: #ef4444; color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
  display: none;
}
.alert-badge.visible { display: flex; }

.alert-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 340px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none; z-index: 2000;
  overflow: hidden;
}
.alert-dropdown.open { display: block; }

.alert-dropdown__header {
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  color: var(--text-light); font-weight: 600; font-size: 14px;
}

.alert-clear-btn {
  background: none; border: none; color: var(--accent);
  font-size: 12px; cursor: pointer; font-family: 'Sarabun', sans-serif;
}
.alert-clear-btn:hover { text-decoration: underline; }

.alert-dropdown__list { max-height: 360px; overflow-y: auto; }

.alert-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: var(--transition);
}
.alert-item:hover { background: rgba(255,255,255,0.05); }
.alert-item:last-child { border-bottom: none; }

.alert-item__title { color: var(--text-light); font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.alert-item__msg   { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
.alert-item__time  { color: #475569; font-size: 11px; }

.alert-item__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  margin-right: 10px; float: left; margin-top: 2px;
  font-size: 13px;
}
.alert-item__icon.flood   { background: rgba(59,130,246,0.2); color: #3b82f6; }
.alert-item__icon.cctv    { background: rgba(239,68,68,0.2);  color: #ef4444; }
.alert-item__icon.general { background: rgba(245,158,11,0.2); color: #f59e0b; }

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

/* ── MAP ────────────────────────────────────────────────── */
#map {
  position: fixed;
  top: var(--nav-h); left: 0; right: 0; bottom: 0;
  z-index: 1;
}

/* ── FILTER TOGGLE BUTTON ───────────────────────────────── */
.filter-toggle-btn {
  position: fixed;
  top: calc(var(--nav-h) + 14px);
  left: 14px;
  z-index: 500;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-light);
  border-radius: 10px;
  padding: 9px 14px;
  display: flex; align-items: center; gap: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.filter-toggle-btn:hover { background: rgba(26,86,219,0.8); border-color: var(--primary); }
.filter-toggle-btn.active { background: var(--primary); border-color: var(--primary-dark); }

/* ── FILTER PANEL ───────────────────────────────────────── */
.filter-panel {
  position: fixed;
  top: calc(var(--nav-h) + 10px);
  left: 14px;
  width: 290px;
  max-height: calc(100vh - var(--nav-h) - 20px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 490;
  display: flex; flex-direction: column;
  transform: translateX(-320px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}
.filter-panel.visible {
  transform: translateX(0);
  opacity: 1;
}

.filter-panel__header {
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.filter-panel__header h3 { color: var(--text-light); font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }

.filter-panel__close {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 4px;
  border-radius: 6px; transition: var(--transition);
}
.filter-panel__close:hover { background: rgba(255,255,255,0.1); color: var(--text-light); }

.filter-panel__body { overflow-y: auto; flex: 1; padding: 10px; }

/* ── ACCORDION ──────────────────────────────────────────── */
.accordion { display: flex; flex-direction: column; gap: 6px; }

.acc-block { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }

.acc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; cursor: pointer;
  background: rgba(255,255,255,0.03);
  transition: var(--transition);
  user-select: none;
}
.acc-header:hover { background: rgba(255,255,255,0.07); }
.acc-header.open  { background: rgba(26,86,219,0.12); border-bottom: 1px solid var(--border); }

.acc-header__left { display: flex; align-items: center; gap: 9px; flex: 1; }

.acc-header__icon {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff;
}
.acc-header__label { color: var(--text-light); font-size: 13px; font-weight: 600; }

.acc-badge {
  background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}

.acc-arrow {
  color: var(--text-muted); font-size: 11px;
  transition: transform 0.25s ease;
}
.acc-header.open .acc-arrow { transform: rotate(180deg); color: var(--accent); }

.acc-body {
  display: none;
  flex-direction: column; gap: 5px;
  padding: 8px;
  background: rgba(0,0,0,0.15);
}
.acc-body.open { display: flex; }

.subcategory-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
}

.subcategory-item__left { display: flex; align-items: center; gap: 8px; flex: 1; }
.subcategory-item__dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.subcategory-item__label { color: var(--text-light); font-size: 13px; flex: 1; }
.subcategory-item__note  { color: var(--text-muted); font-size: 11px; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  inset: 0; border-radius: 11px;
  background: #334155;
  transition: var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px; border-radius: 50%;
  left: 3px; bottom: 3px;
  background: #94a3b8;
  transition: var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); background: #fff; }

/* ── MAP LEGEND ─────────────────────────────────────────── */
.map-legend {
  position: fixed;
  bottom: 24px; right: 14px;
  min-width: 200px; max-width: 240px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 490;
  overflow: hidden;
  display: none;
}
.map-legend.visible { display: block; }

.map-legend__header {
  padding: 10px 14px;
  background: rgba(255,255,255,0.06);
  border-bottom: 1px solid var(--border);
  color: var(--text-light); font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}

.map-legend__body { padding: 10px 12px; max-height: 300px; overflow-y: auto; }

.legend-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0;
  color: var(--text-light); font-size: 12px;
}
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; border: 2px solid rgba(255,255,255,0.3); }
.legend-line { width: 20px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.legend-poly { width: 20px; height: 12px; border-radius: 3px; flex-shrink: 0; opacity: 0.8; }

/* ── CCTV MODAL ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 3000;
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%; max-width: 700px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.modal-box__header {
  padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  color: var(--text-light); font-weight: 700; font-size: 15px;
}

.modal-close-btn {
  background: rgba(255,255,255,0.08); border: none;
  color: var(--text-muted); width: 32px; height: 32px;
  border-radius: 8px; cursor: pointer; font-size: 15px;
  transition: var(--transition); display: flex; align-items: center; justify-content: center;
}
.modal-close-btn:hover { background: rgba(239,68,68,0.2); color: #ef4444; }

.modal-box__body { padding: 18px; overflow-y: auto; }

.cctv-video-wrapper {
  position: relative; background: #000;
  border-radius: 8px; overflow: hidden;
  aspect-ratio: 16/9;
}
.cctv-video-wrapper video { width: 100%; height: 100%; object-fit: cover; }

.cctv-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: var(--text-muted);
}
.cctv-overlay i { font-size: 48px; margin-bottom: 12px; color: #475569; }
.cctv-overlay p { font-size: 16px; font-weight: 600; color: var(--text-light); margin-bottom: 4px; }
.cctv-overlay small { font-size: 12px; }

.cctv-info {
  margin-top: 14px;
  display: flex; flex-wrap: wrap; gap: 10px;
}
.cctv-info-tag {
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px;
  color: var(--text-muted); font-size: 12px;
  display: flex; align-items: center; gap: 5px;
}
.cctv-info-tag i { color: var(--accent); }

/* ── MAP MARKER CUSTOM ──────────────────────────────────── */
.custom-marker {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  color: #fff; font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
}

/* City Area Polygon label */
.city-label {
  background: none; border: none; box-shadow: none;
}
.city-label-inner {
  background: rgba(26,86,219,0.85);
  color: #fff; font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 20px;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.3);
}

/* ── SCROLLBAR ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ── LEAFLET OVERRIDES ──────────────────────────────────── */
.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  overflow: hidden;
  margin-left: 14px !important;
  margin-bottom: 14px !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
  background: var(--bg-dark) !important;
  color: var(--text-light) !important;
  border: none !important;
  font-size: 16px !important;
}
.leaflet-control-zoom a:hover { background: rgba(26,86,219,0.6) !important; }

/* ── ALERT ITEM UPDATES ──────────────────────────────────── */
.alert-item--linked { cursor: pointer; }
.alert-item__content { flex: 1; overflow: hidden; }
.alert-item { display: flex; align-items: flex-start; gap: 10px; }
.alert-item__icon { flex-shrink: 0; margin: 0; float: none; }
.alert-item__map-link {
  flex-shrink: 0; color: var(--accent); font-size: 14px;
  display: flex; align-items: center; padding: 4px;
  opacity: 0.7; transition: var(--transition);
}
.alert-item--linked:hover .alert-item__map-link { opacity: 1; }

/* ── TABLE VIEW BUTTON ───────────────────────────────────── */
.table-view-btn {
  background: rgba(255,255,255,0.07); border: 1px solid var(--border);
  color: var(--text-muted);
  height: 40px; border-radius: 10px;
  padding: 0 14px;
  display: flex; align-items: center; gap: 7px;
  font-family: 'Sarabun', sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.table-view-btn:hover { background: rgba(26,86,219,0.3); color: var(--text-light); border-color: var(--primary); }

/* ── TABLE MODAL ────────────────────────────────────────── */
.modal-box--wide {
  max-width: 960px;
  width: 96%;
}
.table-modal-title { display: flex; align-items: center; gap: 8px; color: var(--text-light); font-size: 15px; font-weight: 700; }
.table-modal-controls { display: flex; align-items: center; gap: 8px; }
.table-select {
  background: rgba(255,255,255,0.07); border: 1px solid var(--border);
  color: var(--text-light); border-radius: 8px;
  padding: 6px 10px; font-family: 'Sarabun', sans-serif; font-size: 13px;
  cursor: pointer; outline: none;
}
.table-select option { background: #1e293b; color: var(--text-light); }

.table-modal-body { padding: 0 !important; display: flex; flex-direction: column; }
.table-wrapper { overflow: auto; flex: 1; }

.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px; font-family: 'Sarabun', sans-serif;
}
.data-table thead tr { background: rgba(255,255,255,0.06); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
.data-table th {
  padding: 11px 14px; text-align: left;
  color: var(--text-muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.05); vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.04); }
.data-table tbody tr:last-child td { border-bottom: none; }

.td-num    { color: var(--text-muted); font-size: 12px; width: 36px; }
.td-name   { color: var(--text-light); font-weight: 600; }
.td-detail { color: var(--text-muted); max-width: 220px; }
.td-coord  { color: #475569; font-size: 11px; white-space: nowrap; }

.cat-chip, .sub-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 500;
  border: 1px solid; white-space: nowrap;
}
.sub-chip { border: none; border-radius: 4px; }

.tbl-map-btn {
  background: rgba(14,165,233,0.15); border: 1px solid rgba(14,165,233,0.3);
  color: var(--accent); width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; font-size: 13px; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.tbl-map-btn:hover { background: rgba(14,165,233,0.3); }

.table-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px;
  flex-shrink: 0;
}

/* ── SUBCATEGORY PIN COUNT ───────────────────────────────── */
.sub-pin-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 18px; padding: 0 5px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; font-size: 10px; font-weight: 700;
  color: var(--text-muted); margin-left: 5px; vertical-align: middle;
  line-height: 1;
}

/* ── USER MENU ───────────────────────────────────────────── */
.user-menu-wrap { position: relative; }
.user-menu-btn {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 7px 12px; color: var(--text-light);
  font-family: 'Sarabun', sans-serif; font-size: 13px; cursor: pointer;
  transition: background var(--transition);
}
.user-menu-btn:hover { background: rgba(255,255,255,0.1); }
.user-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); min-width: 180px;
  box-shadow: var(--shadow); z-index: 2000; overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-dropdown__info { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.user-dropdown__name { font-size: 14px; font-weight: 600; color: var(--text-light); }
.user-dropdown__role { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.user-dropdown__logout {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; color: #fca5a5; font-size: 13px;
  text-decoration: none; transition: background var(--transition);
}
.user-dropdown__logout:hover { background: rgba(239,68,68,0.1); }

/* ── SUBMIT FLOAT BUTTON ─────────────────────────────────── */
.submit-float-btn {
  position: fixed; bottom: 90px; right: 20px; z-index: 900;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg,#ef4444,#f97316);
  border: none; border-radius: 24px; padding: 12px 18px;
  color: #fff; font-family: 'Sarabun', sans-serif;
  font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 20px rgba(239,68,68,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
.submit-float-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(239,68,68,0.5); }

/* ── ADMIN FORM ELEMENTS (used in modal) ─────────────────── */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; color: #cbd5e1; margin-bottom: 6px; }
.form-row--2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.admin-input {
  width: 100%; padding: 9px 12px;
  background: rgba(15,23,42,0.7); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; color: #f1f5f9;
  font-family: 'Sarabun', sans-serif; font-size: 14px; outline: none;
  transition: border-color 0.2s;
}
.admin-input:focus { border-color: #1a56db; }
textarea.admin-input { resize: vertical; min-height: 70px; }
select.admin-input { appearance: none; }
.form-error {
  background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5; border-radius: 8px; padding: 10px 14px; font-size: 13px;
  margin-bottom: 12px;
}
.btn-primary {
  padding: 10px 20px; background: linear-gradient(135deg,#1a56db,#0ea5e9);
  border: none; border-radius: 8px; color: #fff;
  font-family: 'Sarabun', sans-serif; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  padding: 10px 20px; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 8px; color: #94a3b8;
  font-family: 'Sarabun', sans-serif; font-size: 14px; cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .topnav__title-main { font-size: 13px; }
  .table-view-btn span { display: none; }
  .filter-panel { width: calc(100vw - 28px); left: 14px; }
  .map-legend { right: 14px; max-width: calc(100vw - 28px); }
  .modal-box--wide { width: 100%; max-height: 100dvh; border-radius: 0; }
  .table-modal-controls { gap: 4px; }
  .table-select { font-size: 12px; padding: 5px 7px; }
}
