/* ═══════════════════════════════════════════════════════════════════
   SmartD — Rainfall Intelligence Platform
   Dual Theme: Dark (default) · Light CI
   Font: Inter + Noto Sans Thai
   ═══════════════════════════════════════════════════════════════════ */

/* ── Dark Theme (default) ─────────────────────────────────────── */
:root {
  --bg:          #07111E;
  --surface-1:   #0C1A2E;
  --surface-2:   #102238;
  --surface-3:   #172D4A;
  --border:      rgba(255,255,255,0.06);
  --border-md:   rgba(255,255,255,0.11);
  --shadow-color: rgba(0,0,0,0.55);

  --text-1: #EDF2FF;
  --text-2: #8BA3C4;
  --text-3: #4A6580;

  --accent:  #1EAAFF;
  --teal:    #00D4C8;
  --green:   #51CF66;
  --amber:   #FAB005;
  --orange:  #FD7E14;
  --red:     #F03E3E;

  /* rainfall level chip bg opacity */
  --chip-alpha: 0.12;

  --map-filter: brightness(0.55) saturate(0.4) hue-rotate(195deg);

  /* toggle */
  --toggle-bg:   #172D4A;
  --toggle-thumb:#1EAAFF;
}

/* ── Light Theme ──────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:          #F0F4FA;
  --surface-1:   #FFFFFF;
  --surface-2:   #F7F9FC;
  --surface-3:   #EDF1F7;
  --border:      rgba(15,30,60,0.08);
  --border-md:   rgba(15,30,60,0.14);
  --shadow-color: rgba(15,40,80,0.12);

  --text-1: #0F1E38;
  --text-2: #4A627E;
  --text-3: #8DA3BE;

  --accent:  #0E8FE0;
  --teal:    #00A89E;
  --green:   #2DA44E;
  --amber:   #D08000;
  --orange:  #C85C00;
  --red:     #C92A2A;

  --chip-alpha: 0.10;

  --map-filter: brightness(1) saturate(0.85) hue-rotate(0deg);

  --toggle-bg:   #D4E4F5;
  --toggle-thumb:#0E8FE0;
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', 'Noto Sans Thai', sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
}

/* ── Layout ───────────────────────────────────────────────────── */
.app-wrapper { display: flex; height: 100vh; overflow: hidden; }

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════════════════════ */
.sidebar {
  width: 288px; min-width: 288px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background .3s, border-color .3s;
}

/* Logo */
.sidebar-logo {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-mark {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--surface-2), var(--surface-3));
  border: 1px solid var(--border-md);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-name    { font-size: 15px; font-weight: 700; color: var(--text-1); letter-spacing: .4px; line-height: 1; }
.logo-tagline { font-size: 10px; color: var(--text-3); margin-top: 3px; letter-spacing: .5px; text-transform: uppercase; }

/* Section */
.sidebar-section { padding: 16px 16px 0; flex-shrink: 0; }
.sidebar-section--grow { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding-bottom: 0; }

.section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-3); margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.section-count {
  background: var(--surface-3); color: var(--text-2);
  border-radius: 20px; padding: 1px 7px;
  font-size: 10px; font-weight: 500; letter-spacing: 0; text-transform: none;
}

/* Stat Grid */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.stat-tile {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px;
  transition: border-color .2s, background .3s;
}
.stat-tile:hover { border-color: var(--border-md); }
.stat-tile--danger { border-color: rgba(240,62,62,.18) !important; background: rgba(240,62,62,.05) !important; }
.stat-tile--warn   { border-color: rgba(253,126,20,.18) !important; background: rgba(253,126,20,.05) !important; }
[data-theme="light"] .stat-tile--danger { background: rgba(201,42,42,.04) !important; }
[data-theme="light"] .stat-tile--warn   { background: rgba(200,92,0,.04) !important; }

.stat-icon {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon--blue   { background: rgba(30,170,255,.12);  color: var(--accent); }
.stat-icon--teal   { background: rgba(0,212,200,.12);   color: var(--teal); }
.stat-icon--red    { background: rgba(240,62,62,.12);   color: var(--red); }
.stat-icon--orange { background: rgba(253,126,20,.12);  color: var(--orange); }
[data-theme="light"] .stat-icon--blue   { background: rgba(14,143,224,.10); }
[data-theme="light"] .stat-icon--teal   { background: rgba(0,168,158,.10); }
[data-theme="light"] .stat-icon--red    { background: rgba(201,42,42,.10); }
[data-theme="light"] .stat-icon--orange { background: rgba(200,92,0,.10); }

.stat-val  { font-size: 20px; font-weight: 700; color: var(--text-1); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-tile--danger .stat-val { color: var(--red); }
.stat-tile--warn   .stat-val { color: var(--orange); }
.stat-lbl  { font-size: 10px; color: var(--text-3); margin-top: 3px; }

/* Legend */
.legend-stack { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.legend-row   { display: flex; align-items: center; gap: 8px; }
.legend-swatch { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-meta   { display: flex; flex-direction: column; width: 108px; flex-shrink: 0; }
.legend-name   { font-size: 11px; font-weight: 500; color: var(--text-2); }
.legend-range  { font-size: 10px; color: var(--text-3); }
.legend-bar-wrap { flex: 1; height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.legend-bar      { height: 100%; border-radius: 2px; opacity: .65; }

/* Station List */
/* ── Search ──────────────────────────────────────────────────────── */
.stn-search-wrap {
  position: relative;
  margin: 0 0 6px;
  flex-shrink: 0;
}
.stn-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.stn-search-input {
  width: 100%; height: 32px;
  background: var(--surface-2); border: 1px solid var(--border-md); border-radius: 6px;
  padding: 0 32px 0 30px;
  font-family: inherit; font-size: 12px; color: var(--text-1);
  outline: none; transition: border-color .15s, background .3s;
}
.stn-search-input::placeholder { color: var(--text-3); }
.stn-search-input:focus { border-color: var(--accent); }
.stn-search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface-3); border: none; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  color: var(--text-3); transition: background .15s;
}
.stn-search-clear.visible { display: flex; }
.stn-search-clear:hover { background: var(--border-md); color: var(--text-1); }

/* ── Sort & Select Toolbar ───────────────────────────────────────── */
.stn-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px; gap: 6px; flex-shrink: 0;
}
.stn-sort-group, .stn-select-group { display: flex; align-items: center; gap: 3px; }

.stn-sort-btn {
  height: 26px; padding: 0 9px; border-radius: 5px;
  background: transparent; border: 1px solid var(--border);
  font-family: inherit; font-size: 11px; color: var(--text-3);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.stn-sort-btn:hover  { border-color: var(--border-md); color: var(--text-2); background: var(--surface-2); }
.stn-sort-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
[data-theme="light"] .stn-sort-btn.active { color: #fff; }

.stn-sel-btn {
  height: 26px; padding: 0 8px; border-radius: 5px;
  background: transparent; border: 1px solid var(--border);
  font-family: inherit; font-size: 11px; color: var(--text-3);
  cursor: pointer; transition: all .15s;
}
.stn-sel-btn:hover { border-color: var(--border-md); color: var(--text-2); background: var(--surface-2); }

/* ── Action Bar ──────────────────────────────────────────────────── */
.stn-action-bar {
  display: none; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 6px; padding: 6px 10px; margin-bottom: 6px; flex-shrink: 0;
}
.stn-action-bar.visible { display: flex; animation: fade-in .15s ease; }
.stn-action-count { font-size: 11px; font-weight: 600; color: var(--accent); }
.stn-action-btns  { display: flex; gap: 5px; }
.stn-action-btn {
  display: flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 8px; border-radius: 4px;
  background: var(--surface-3); border: 1px solid var(--border-md);
  font-family: inherit; font-size: 11px; font-weight: 500; color: var(--text-2);
  cursor: pointer; transition: all .15s;
}
.stn-action-btn:hover { background: var(--border-md); color: var(--text-1); }
.stn-action-btn--danger:hover { background: rgba(201,42,42,.12); border-color: rgba(201,42,42,.3); color: var(--red); }

/* ── Station scroll ──────────────────────────────────────────────── */
.station-scroll { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.station-scroll::-webkit-scrollbar { width: 3px; }
.station-scroll::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }
.station-list { display: flex; flex-direction: column; gap: 2px; }

.station-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; position: relative;
  transition: all .15s;
}
.station-item:hover { background: var(--surface-2); border-color: var(--border); }
.station-item.active { background: var(--surface-2); border-color: var(--border-md); }
.station-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: var(--accent); border-radius: 0 2px 2px 0;
}
/* Checkbox */
.stn-checkbox {
  width: 15px; height: 15px; border-radius: 4px; flex-shrink: 0;
  border: 1.5px solid var(--border-md); background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; cursor: pointer;
}
.station-item:hover .stn-checkbox { border-color: var(--accent); }
.stn-checkbox.checked { background: var(--accent); border-color: var(--accent); }
.stn-checkbox.checked::after {
  content: '';
  display: block; width: 8px; height: 5px;
  border-left: 1.5px solid white; border-bottom: 1.5px solid white;
  transform: rotate(-45deg) translateY(-1px);
}
.station-item.checked { background: color-mix(in srgb, var(--accent) 6%, var(--surface-1)); border-color: color-mix(in srgb, var(--accent) 25%, transparent) !important; }

.stn-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.stn-info { flex: 1; min-width: 0; }
.stn-name { font-size: 12px; font-weight: 500; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stn-area { font-size: 10px; color: var(--text-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stn-badge { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 20px; flex-shrink: 0; }

/* empty search result */
.stn-empty { text-align: center; padding: 24px 12px; color: var(--text-3); font-size: 12px; }

/* ═══════════════════════════════════════════════════════════════
   MAIN
═══════════════════════════════════════════════════════════════ */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

/* Topbar */
.topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  flex-shrink: 0; gap: 12px;
  transition: background .3s, border-color .3s;
}
.page-title { font-size: 14px; font-weight: 600; color: var(--text-1); letter-spacing: .2px; }
.page-meta  { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.topbar-filter {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-2); border: 1px solid var(--border-md); border-radius: 6px;
  padding: 0 10px; height: 32px; color: var(--text-3);
  transition: background .3s, border-color .3s;
}
.topbar-filter select {
  background: transparent; border: none; outline: none;
  color: var(--text-2); font-family: inherit; font-size: 12px; cursor: pointer; -webkit-appearance: none;
}
.topbar-filter select option { background: var(--surface-1); color: var(--text-1); }

/* ── Theme Toggle ─────────────────────────────────────────────── */
.theme-toggle {
  display: flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  background: var(--surface-2); border: 1px solid var(--border-md); border-radius: 6px;
  cursor: pointer; color: var(--text-2);
  transition: all .2s;
  position: relative;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

.theme-toggle-track {
  width: 28px; height: 16px;
  background: var(--toggle-bg);
  border-radius: 20px;
  position: relative;
  flex-shrink: 0;
  border: 1px solid var(--border-md);
  transition: background .3s;
}
.theme-toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 10px; height: 10px;
  background: var(--toggle-thumb);
  border-radius: 50%;
  transition: transform .25s cubic-bezier(.4,0,.2,1), background .3s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
[data-theme="light"] .theme-toggle-thumb { transform: translateX(12px); }

.theme-toggle-icon { display: flex; align-items: center; transition: opacity .2s; }
.theme-toggle-icon--dark  { opacity: 1; }
.theme-toggle-icon--light { opacity: 0; position: absolute; right: 10px; }
[data-theme="light"] .theme-toggle-icon--dark  { opacity: 0; }
[data-theme="light"] .theme-toggle-icon--light { opacity: 1; position: static; }

/* Bell */
.bell-btn {
  position: relative; width: 36px; height: 36px;
  background: var(--surface-2); border: 1px solid var(--border-md); border-radius: 6px;
  color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.bell-btn:hover { border-color: var(--accent); color: var(--accent); }
.bell-btn.has-alerts { color: var(--red); border-color: rgba(240,62,62,.35); animation: bell-shake 2.5s ease infinite; }

@keyframes bell-shake {
  0%,100%  { transform: rotate(0); }
  10%,30%  { transform: rotate(-7deg); }
  20%,40%  { transform: rotate(7deg); }
  50%      { transform: rotate(0); }
}

.bell-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 17px; height: 17px;
  background: var(--red); color: white;
  font-size: 9px; font-weight: 700; border-radius: 20px;
  display: none; align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid var(--surface-1);
}
.bell-badge.visible { display: flex; }

/* ── Scope Switcher (sidebar) ─────────────────────────────────── */
.sidebar-scope {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 5px; flex-shrink: 0;
}
.scope-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px;
  height: 30px; padding: 0 6px; border-radius: 6px;
  border: 1px solid var(--border); cursor: pointer;
  font-family: inherit; font-size: 11px; font-weight: 500; color: var(--text-3);
  background: transparent; transition: all .15s; white-space: nowrap;
}
.scope-btn:hover:not(.active):not(:disabled) {
  border-color: var(--border-md); color: var(--text-2); background: var(--surface-2);
}
.scope-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.scope-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Role Pill (topbar) ───────────────────────────────────────── */
.role-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-2); border: 1px solid var(--border-md); border-radius: 6px;
  padding: 0 10px; height: 32px; color: var(--text-3);
  transition: background .3s, border-color .3s;
}
.role-select {
  background: transparent; border: none; outline: none;
  color: var(--text-2); font-family: inherit; font-size: 12px; cursor: pointer;
  -webkit-appearance: none;
}
.role-select option { background: var(--surface-1); color: var(--text-1); }

/* ── View Tabs (in topbar) ────────────────────────────────────── */
.topbar-left { display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.view-tabs   { display: flex; gap: 3px; align-items: center; }

.view-tab {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 13px; border-radius: 7px;
  border: 1px solid transparent; cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 500; color: var(--text-2);
  background: transparent; transition: all .15s;
}
.view-tab:hover:not(.active) {
  background: var(--surface-2); border-color: var(--border); color: var(--text-1);
}
.view-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Analysis View ────────────────────────────────────────────── */
.analysis-view {
  display: none; flex: 1; min-height: 0; overflow-y: auto;
  padding: 24px; gap: 20px; flex-direction: column;
  background: var(--bg); transition: background .3s;
}
.analysis-view.active { display: flex; }
.analysis-view::-webkit-scrollbar { width: 4px; }
.analysis-view::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

/* Prevent flex shrink so analysis-view scrolls instead of compressing children */
.analysis-view > * { flex-shrink: 0; }

/* KPI Grid */
.ana-kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.ana-kpi-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 20px; transition: border-color .2s, background .3s;
}
.ana-kpi-card:hover { border-color: var(--border-md); }
.ana-kpi-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 14px;
}
.ana-kpi-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-3); margin-bottom: 6px; }
.ana-kpi-value { font-size: 28px; font-weight: 700; color: var(--text-1); line-height: 1; font-variant-numeric: tabular-nums; }
.ana-kpi-unit  { font-size: 11px; color: var(--text-3); margin-top: 5px; }

/* 2-col layout */
.ana-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Cards */
.ana-card, .ana-full-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; transition: background .3s, border-color .3s;
}
.ana-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.ana-card-title { font-size: 12px; font-weight: 600; color: var(--text-1); }

/* Tables */
.ana-table-wrap { overflow-x: auto; }
.ana-table { width: 100%; border-collapse: collapse; }
.ana-table th {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-3); padding: 10px 16px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-2);
}
.ana-table td {
  padding: 10px 16px; font-size: 12px; color: var(--text-1);
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.ana-table tr:last-child td { border-bottom: none; }
.ana-table tbody tr:hover { background: var(--surface-2); }
.ana-table tbody tr[onclick] { cursor: pointer; }

/* Full table — expands naturally, analysis-view handles scroll */
.ana-full-card .ana-table thead th { position: sticky; top: 0; z-index: 1; }

/* Analysis chart grid */
.ana-chart-row {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 16px;
}
.ana-chart-body {
  position: relative;
  width: 100%;
}
@media (max-width: 900px) {
  .ana-chart-row { grid-template-columns: 1fr; }
}

/* Analysis table search */
.ana-table-search-wrap {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px;
  transition: border-color .2s;
}
.ana-table-search-wrap:focus-within { border-color: var(--accent); }
.ana-table-search {
  background: none; border: none; outline: none;
  font-size: 11px; color: var(--text-1); width: 180px;
  font-family: inherit;
}
.ana-table-search::placeholder { color: var(--text-3); }
.ana-search-clear {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); font-size: 14px; line-height: 1;
  padding: 0 2px; transition: color .15s;
}
.ana-search-clear:hover { color: var(--text-1); }

/* Mini bar inside table */
.ana-mini-bar-wrap  { display: flex; align-items: center; gap: 8px; }
.ana-mini-bar-track { width: 80px; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; flex-shrink: 0; }

/* Map */
#map { flex: 1; z-index: 1; }
.leaflet-container { background: var(--bg) !important; transition: background .3s; }
.leaflet-tile { filter: var(--map-filter); transition: filter .4s; }
.leaflet-control-zoom a {
  background: var(--surface-1) !important; color: var(--text-2) !important;
  border-color: var(--border-md) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-2) !important; color: var(--text-1) !important; }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface-1) 80%, transparent) !important;
  color: var(--text-3) !important; font-size: 9px !important;
  backdrop-filter: blur(4px);
}

/* Marker */
.mk-pin {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50% 50% 50% 2px;
  transform: rotate(-45deg);
  border: 1.5px solid rgba(255,255,255,.25);
}
[data-theme="light"] .mk-pin { border-color: rgba(255,255,255,.6); }
.mk-inner {
  transform: rotate(45deg);
  font-size: 10px; font-weight: 700; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  font-family: 'Inter', sans-serif; white-space: nowrap;
}
.mk-pulse { position: absolute; border-radius: 50%; animation: pulse-ring 2.2s cubic-bezier(.2,.5,.3,1) infinite; pointer-events: none; }
@keyframes pulse-ring {
  0%   { transform: rotate(45deg) scale(1);   opacity: .45; }
  100% { transform: rotate(45deg) scale(2.4); opacity: 0; }
}

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--surface-1) !important; border: 1px solid var(--border-md) !important;
  border-radius: 14px !important; box-shadow: 0 12px 40px var(--shadow-color) !important;
  color: var(--text-1) !important; overflow: hidden;
}
.leaflet-popup-tip-container { display: none; }
.leaflet-popup-content { margin: 0 !important; }
/* drag handle injected above popup content */
.pu-drag-handle {
  display: flex; align-items: center; justify-content: center;
  height: 18px; margin: -2px -2px 6px;
  background: var(--surface-3); border-radius: 8px 8px 0 0;
  cursor: grab; user-select: none;
  transition: background .15s;
}
.pu-drag-handle:hover { background: var(--border-md); }
.pu-drag-handle:active { cursor: grabbing; }
.pu-drag-dots { font-size: 13px; color: var(--text-3); letter-spacing: 2px; line-height: 1; }

.pu-wrap    { padding: 14px 16px; min-width: 210px; }
.pu-head    { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.pu-title   { font-size: 13px; font-weight: 600; color: var(--text-1); }
.pu-area    { font-size: 10px; color: var(--text-3); margin-top: 2px; }
.pu-chip    { font-size: 10px; font-weight: 600; padding: 3px 9px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
.pu-divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.pu-row     { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.pu-key     { font-size: 11px; color: var(--text-3); }
.pu-val     { font-size: 11px; font-weight: 600; color: var(--text-1); }

/* ── Detail Panel ──────────────────────────────────────────────── */
.detail-panel {
  position: absolute; bottom: 20px; right: 20px; width: 310px;
  background: var(--surface-1); border: 1px solid var(--border-md);
  border-radius: 14px; box-shadow: 0 12px 40px var(--shadow-color);
  z-index: 400; display: none; overflow: hidden;
  transition: background .3s, border-color .3s;
}
.detail-panel.open { display: block; animation: panel-in .25s ease forwards; }
@keyframes panel-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.detail-station-name { font-size: 13px; font-weight: 600; color: var(--text-1); }
.detail-station-area { font-size: 10px; color: var(--text-3); margin-top: 3px; }
.detail-close {
  width: 26px; height: 26px; background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all .15s;
}
.detail-close:hover { color: var(--text-1); border-color: var(--border-md); }
.detail-body { padding: 14px 16px; }

.d-badge-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.d-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.d-trend { font-size: 11px; font-weight: 500; display: flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 20px; background: var(--surface-3); color: var(--text-2); }

.d-kpi-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.d-kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; text-align: center; }
.d-kpi-label { font-size: 10px; color: var(--text-3); margin-bottom: 5px; }
.d-kpi-value { font-size: 18px; font-weight: 700; color: var(--accent); line-height: 1; }
.d-kpi-unit  { font-size: 9px; color: var(--text-3); margin-top: 3px; }

.d-chart-title { font-size: 10px; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 8px; }
.d-bar-row   { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.d-bar-lbl   { font-size: 10px; color: var(--text-3); width: 70px; flex-shrink: 0; text-align: right; }
.d-bar-track { flex: 1; background: var(--surface-3); border-radius: 3px; height: 6px; overflow: hidden; }
.d-bar-fill  { height: 100%; border-radius: 3px; transition: width .5s cubic-bezier(.4,0,.2,1); }
.d-bar-val   { font-size: 10px; color: var(--text-2); width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── Rainfall Level Chips ──────────────────────────────────────── */
.lv-normal     { color: #1E87D4; background: rgba(30,135,212,var(--chip-alpha)); }
.lv-light      { color: #2DA44E; background: rgba(45,164,78,var(--chip-alpha)); }
.lv-moderate   { color: #A86700; background: rgba(168,103,0,var(--chip-alpha)); }
.lv-heavy      { color: #C05000; background: rgba(192,80,0,var(--chip-alpha)); }
.lv-very-heavy { color: #C92A2A; background: rgba(201,42,42,var(--chip-alpha)); }

[data-theme="dark"] .lv-normal     { color: #4DABF7; }
[data-theme="dark"] .lv-light      { color: #51CF66; }
[data-theme="dark"] .lv-moderate   { color: #FAB005; }
[data-theme="dark"] .lv-heavy      { color: #FD7E14; }
[data-theme="dark"] .lv-very-heavy { color: #F03E3E; }

/* ═══════════════════════════════════════════════════════════════
   ALERT PANEL
═══════════════════════════════════════════════════════════════ */
.alert-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 900;
  display: none; backdrop-filter: blur(2px);
}
.alert-overlay.open { display: block; animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.alert-panel {
  position: fixed; top: 0; right: 0; width: 360px; height: 100vh;
  background: var(--surface-1); border-left: 1px solid var(--border-md);
  box-shadow: -8px 0 40px var(--shadow-color); z-index: 901;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1), background .3s, border-color .3s;
}
.alert-panel.open { transform: translateX(0); }

.alert-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); flex-shrink: 0;
}
.alert-panel-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text-1); }
.alert-panel-close {
  width: 30px; height: 30px; background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.alert-panel-close:hover { color: var(--text-1); }

.alert-panel-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.alert-panel-body::-webkit-scrollbar { width: 3px; }
.alert-panel-body::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

.alert-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px 12px 18px; cursor: pointer; position: relative;
  transition: border-color .15s, background .3s;
  /* no overflow:hidden — let content breathe */
  border-left: 3px solid transparent;
}
.alert-card.critical { border-left-color: var(--red);    border-color: rgba(201,42,42,.2); }
.alert-card.warning  { border-left-color: var(--orange); border-color: rgba(200,92,0,.2); }
.alert-card.watch    { border-left-color: var(--amber);  border-color: rgba(168,103,0,.2); }
.alert-card:hover    { border-color: var(--border-md); }

.alert-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; flex-wrap: wrap; gap: 4px; }
.alert-type-tag {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  padding: 2px 8px; border-radius: 20px;
}
.alert-type-tag.critical { color: var(--red);    background: rgba(201,42,42,.12); }
.alert-type-tag.warning  { color: var(--orange); background: rgba(200,92,0,.12); }
.alert-type-tag.watch    { color: var(--amber);  background: rgba(168,103,0,.12); }

.alert-time    { font-size: 10px; color: var(--text-3); white-space: nowrap; }
.alert-station { font-size: 12px; font-weight: 600; color: var(--text-1); margin-bottom: 4px; }
.alert-desc    { font-size: 11px; color: var(--text-2); line-height: 1.55; margin-bottom: 2px; }
.alert-value   { font-size: 11px; font-weight: 600; margin-top: 7px; display: flex; flex-wrap: wrap; gap: 8px 14px; }

.alert-empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.alert-empty svg { opacity: .3; margin-bottom: 12px; }
.alert-empty p { font-size: 13px; line-height: 1.6; }

/* ═══════════════════════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════════════════════ */
#toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--surface-1); border: 1px solid var(--border-md);
  border-radius: 10px; box-shadow: 0 8px 32px var(--shadow-color);
  width: 320px; pointer-events: auto;
  animation: toast-in .3s cubic-bezier(.4,0,.2,1);
  position: relative; overflow: hidden;
}
.toast::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px;
  animation: toast-progress 5s linear forwards;
}
.toast.critical { border-left: 3px solid var(--red); }
.toast.critical::after { background: var(--red); }
.toast.warning  { border-left: 3px solid var(--orange); }
.toast.warning::after { background: var(--orange); }
.toast.watch    { border-left: 3px solid var(--amber); }
.toast.watch::after { background: var(--amber); }

.toast-icon { width: 24px; height: 24px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px; }
.toast.critical .toast-icon { background: rgba(201,42,42,.12); color: var(--red); }
.toast.warning  .toast-icon { background: rgba(200,92,0,.12);  color: var(--orange); }
.toast.watch    .toast-icon { background: rgba(168,103,0,.12); color: var(--amber); }

.toast-title { font-size: 12px; font-weight: 600; color: var(--text-1); margin-bottom: 2px; }
.toast-msg   { font-size: 11px; color: var(--text-2); line-height: 1.4; }

@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes toast-progress {
  from { width: 100%; }
  to   { width: 0%; }
}

/* ═══════════════════════════════════════════════════════════════
   LOGIN SCREEN
═══════════════════════════════════════════════════════════════ */
.login-screen {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(30,170,255,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 40% 40% at 80% 80%, rgba(0,212,200,0.06) 0%, transparent 50%);
}

.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface-1);
  border: 1px solid var(--border-md);
  border-radius: 20px;
  padding: 36px 40px 32px;
  box-shadow: 0 32px 64px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.04);
}

.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
}
.login-logo .logo-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(30,170,255,0.12);
  border: 1px solid rgba(30,170,255,0.2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.login-brand-name {
  font-size: 20px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--text-1);
}
.login-brand-sub {
  font-size: 10px; color: var(--text-3); margin-top: 1px;
  letter-spacing: 0.3px;
}

.login-title {
  font-size: 22px; font-weight: 700; color: var(--text-1);
  margin: 0 0 24px; letter-spacing: -0.3px;
}

.login-field { margin-bottom: 16px; }
.login-label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px; letter-spacing: 0.3px;
}
.login-input {
  width: 100%; box-sizing: border-box;
  background: var(--surface-2); border: 1px solid var(--border-md);
  border-radius: 10px; padding: 11px 14px;
  font-size: 14px; color: var(--text-1); font-family: inherit;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.login-input::placeholder { color: var(--text-3); }
.login-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30,170,255,0.15);
}

.login-pw-wrap { position: relative; }
.login-pw-wrap .login-input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 4px; transition: color .15s;
}
.pw-toggle:hover { color: var(--text-1); }

.login-remember {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0 20px;
}
.login-check-label {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 13px; color: var(--text-2);
  user-select: none;
}
.login-checkbox { display: none; }
.login-check-box {
  width: 16px; height: 16px; border-radius: 5px; flex-shrink: 0;
  border: 1.5px solid var(--border-md); background: var(--surface-2);
  transition: background .15s, border-color .15s;
  position: relative;
}
.login-checkbox:checked + .login-check-box {
  background: var(--accent); border-color: var(--accent);
}
.login-checkbox:checked + .login-check-box::after {
  content: '';
  position: absolute; left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: 2px solid #fff; border-top: none; border-left: none;
  transform: rotate(45deg);
}

.login-error {
  min-height: 20px; font-size: 12px; color: var(--red);
  margin-bottom: 12px; font-weight: 500;
}
.login-error.shake {
  animation: shake .35s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

.login-submit {
  width: 100%; display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px;
  background: var(--accent); border: none; border-radius: 10px;
  color: #fff; font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .2s, transform .1s, box-shadow .2s;
  box-shadow: 0 4px 14px rgba(30,170,255,0.35);
}
.login-submit:hover {
  background: #39b8ff;
  box-shadow: 0 6px 20px rgba(30,170,255,0.45);
}
.login-submit:active { transform: scale(0.98); }

/* Demo credentials */
.login-demo {
  margin-top: 28px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}
.login-demo-title {
  font-size: 10px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 10px;
}
.login-demo-accounts { display: flex; flex-direction: column; gap: 6px; }
.login-demo-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
  cursor: pointer; text-align: left; width: 100%;
  transition: border-color .15s, background .15s;
}
.login-demo-row:hover {
  border-color: var(--accent); background: var(--surface-3);
}
.demo-role-badge {
  font-size: 10px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; white-space: nowrap;
}
.demo-admin    { background: rgba(30,170,255,0.15); color: var(--accent); }
.demo-province { background: rgba(0,212,200,0.12);  color: var(--teal); }
.demo-district { background: rgba(250,176,5,0.12);  color: var(--amber); }
.demo-cred { font-size: 11px; color: var(--text-2); font-family: monospace; }

/* ── User Info Pill (topbar) ───────────────────────────────── */
.user-info-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border-md);
  border-radius: 20px; padding: 5px 6px 5px 10px;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; gap: 1px; line-height: 1; }
.user-name { font-size: 11px; font-weight: 600; color: var(--text-1); white-space: nowrap; }
.user-role-badge { font-size: 10px; color: var(--text-3); white-space: nowrap; }
.logout-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 5px; border-radius: 8px;
  display: flex; align-items: center; transition: color .15s, background .15s;
}
.logout-btn:hover { color: var(--red); background: rgba(240,62,62,0.1); }
