/* FloodKH — Phnom Penh Flood Monitor Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Khmer:wght@400;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2332;
  --bg-card-hover: #1f2b3d;
  --border: #2a3548;
  --text-primary: #e0e6f0;
  --text-secondary: #8892a4;
  --text-muted: #5a6478;
  --accent: #3b82f6;
  --level-0: #22c55e;
  --level-1: #eab308;
  --level-2: #f97316;
  --level-3: #ef4444;
  --sidebar-width: 360px;
}

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

body {
  font-family: 'Inter', 'Noto Sans Khmer', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* === HEADER === */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.header-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 12px;
}

nav { display: flex; gap: 4px; }

.nav-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  text-decoration: none;
  transition: all 0.2s;
}
.nav-btn:hover { color: var(--text-primary); background: var(--bg-card); }
.nav-btn.active { color: var(--text-primary); background: var(--accent); border-color: var(--accent); }

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.lang-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Noto Sans Khmer', sans-serif;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.lang-btn:hover { background: var(--bg-card-hover); border-color: var(--accent); }

#update-time { color: var(--text-muted); font-size: 0.75rem; }

/* === MAIN LAYOUT === */
main {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 32px;
  display: flex;
}

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.summary-card {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 14px;
  border-left: 4px solid;
  transition: transform 0.2s;
}
.summary-card:hover { transform: translateY(-2px); }
.summary-card.level-0 { border-left-color: var(--level-0); }
.summary-card.level-1 { border-left-color: var(--level-1); }
.summary-card.level-2 { border-left-color: var(--level-2); }
.summary-card.level-3 { border-left-color: var(--level-3); }

.card-count {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}
.level-0 .card-count { color: var(--level-0); }
.level-1 .card-count { color: var(--level-1); }
.level-2 .card-count { color: var(--level-2); }
.level-3 .card-count { color: var(--level-3); }

.summary-card span:last-child {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Timeline Section */
.timeline-section {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 20px;
}

.timeline-section h3 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.timeline-slider { padding: 0 4px; }

#time-slider {
  width: 100%;
  -webkit-appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}
#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.timeline-labels span.active { color: var(--accent); font-weight: 600; }

/* District Ranking */
.district-list h3,
.river-section h3,
.source-status h3 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.district-rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 4px;
}
.district-rank-item:hover { background: var(--bg-card); }

.rank-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rank-info {
  flex: 1;
  min-width: 0;
}
.rank-name {
  display: block;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rank-name-km {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: 'Noto Sans Khmer', sans-serif;
}

.rank-score {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.score-bar-bg {
  width: 60px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.score-value {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 24px;
  text-align: right;
}

/* River Gauge */
.river-section { margin-top: 20px; }

.gauge-container {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 120px;
  position: relative;
}
.gauge-bar {
  width: 40px;
  height: 100%;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--border);
}
.gauge-fill {
  width: 100%;
  border-radius: 0 0 3px 3px;
  transition: height 0.5s ease, background 0.5s ease;
}
.gauge-labels {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}
.gauge-value { font-size: 1.2rem; font-weight: 700; }
.gauge-label { font-size: 0.7rem; color: var(--text-muted); }

.gauge-thresholds {
  position: absolute;
  left: 46px;
  top: 0;
  bottom: 0;
  width: 40px;
}
.gauge-thresholds span {
  position: absolute;
  font-size: 0.6rem;
  color: var(--text-muted);
  transform: translateY(50%);
}

/* Source Status */
.source-status { margin-top: 20px; }

.source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.8rem;
}
.source-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.source-dot.live { background: var(--level-0); box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }
.source-dot.stub { background: var(--text-muted); }
.source-name { flex: 1; }
.source-status-text { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; }

/* === MAP === */
#map-container {
  flex: 1;
  min-width: 0;
}

/* Leaflet dark popup override */
.dark-popup .leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.dark-popup .leaflet-popup-tip { background: var(--bg-card); }
.dark-popup .leaflet-popup-close-button { color: var(--text-secondary); }

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.popup-header h3 { font-size: 1rem; margin: 0; }
.popup-khmer { font-size: 0.8rem; color: var(--text-secondary); margin-left: 6px; font-family: 'Noto Sans Khmer', sans-serif; }

.level-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.level-badge.level-0 { background: rgba(34,197,94,0.2); color: var(--level-0); }
.level-badge.level-1 { background: rgba(234,179,8,0.2); color: var(--level-1); }
.level-badge.level-2 { background: rgba(249,115,22,0.2); color: var(--level-2); }
.level-badge.level-3 { background: rgba(239,68,68,0.2); color: var(--level-3); }

.popup-score {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.popup-score strong { color: var(--text-primary); font-size: 1.1rem; }

.popup-forecast-bars {
  display: flex;
  gap: 6px;
  height: 60px;
  align-items: flex-end;
  margin-bottom: 12px;
  padding: 8px;
  background: var(--bg-primary);
  border-radius: 6px;
}
.forecast-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.bar-fill {
  width: 100%;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}
.bar-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.forecast-bar.active .bar-label { color: var(--accent); font-weight: 600; }

.popup-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.metric-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }
.metric span:last-child { font-size: 0.85rem; font-weight: 600; }

.popup-factors {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.factor-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* Map Legend */
.map-legend {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
}
.map-legend h4 {
  font-size: 0.75rem;
  margin-bottom: 8px;
  color: var(--text-secondary);
  text-transform: uppercase;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.8rem;
}
.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* River labels on map */
.river-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}
.river-label span {
  color: #4a90d9;
  font-size: 11px;
  font-style: italic;
  font-weight: 600;
  text-shadow: 0 0 4px #fff, 0 0 4px #fff, 1px 1px 2px rgba(0,0,0,0.3);
  white-space: nowrap;
}

/* === DASHBOARD VIEW === */
.dashboard-view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg-primary);
}
.dashboard-view.hidden { display: none; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}
.chart-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 20px;
  border: 1px solid var(--border);
}
.chart-card.full-width { grid-column: 1 / -1; }
.chart-card h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === FOOTER === */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 0.7rem;
  color: var(--text-muted);
  z-index: 1000;
}
footer strong { color: var(--text-secondary); }

/* Error banner */
.error-banner {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: rgba(239,68,68,0.15);
  border-bottom: 1px solid var(--level-3);
  color: var(--level-3);
  padding: 10px 20px;
  font-size: 0.85rem;
  text-align: center;
  z-index: 999;
}

/* Hidden utility */
.hidden { display: none !important; }

/* === METHODOLOGY PAGE === */
body:has(.methodology-content) {
  overflow-y: auto;
  height: auto;
}
.methodology-content {
  max-width: 900px;
  margin: 80px auto 60px;
  padding: 0 24px;
  line-height: 1.7;
}
.methodology-content h2 {
  font-size: 1.3rem;
  margin: 32px 0 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.methodology-content h3 {
  font-size: 1rem;
  margin: 24px 0 10px;
  color: var(--text-secondary);
}
.methodology-content p {
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.methodology-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.methodology-content th,
.methodology-content td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.methodology-content th {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
}
.methodology-content td { color: var(--text-secondary); }
.methodology-content .level-indicator {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.methodology-content code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85rem;
}
.methodology-content .disclaimer {
  background: rgba(234,179,8,0.1);
  border: 1px solid rgba(234,179,8,0.3);
  border-radius: 8px;
  padding: 16px;
  margin: 24px 0;
  color: var(--level-1);
  font-size: 0.85rem;
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 768px) {
  header { padding: 0 12px; }
  .header-subtitle { display: none; }
  .header-controls .last-updated { display: none; }

  .sidebar {
    position: fixed;
    bottom: 32px;
    left: 0;
    right: 0;
    width: 100%;
    height: 40vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 900;
    transform: translateY(0);
  }
  .sidebar.collapsed { transform: translateY(calc(100% - 48px)); }
  .sidebar::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto 12px;
  }

  #map-container {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 32px;
  }

  .dashboard-grid { grid-template-columns: 1fr; }
  .methodology-content { margin-top: 70px; padding: 0 16px; }
}

/* ---------------------------------------------------------------------------
   Hover Tooltip (map)
   --------------------------------------------------------------------------- */
.coord-display {
    position: absolute;
    z-index: 800;
    background: rgba(17, 24, 39, 0.92);
    border: 1px solid #2a3548;
    border-radius: 8px;
    padding: 8px 12px;
    pointer-events: none;
    font-size: 0.8rem;
    color: #e0e6f0;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.hover-title {
    font-weight: 600;
    margin-bottom: 4px;
}
.hover-level {
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 4px;
}
.hover-detail {
    color: #8892a4;
    font-size: 0.75rem;
}
.coord-latlon {
    display: block;
    margin-top: 4px;
    font-size: 0.7rem;
    color: #5a6478;
}

/* ---------------------------------------------------------------------------
   Telegram Coming Soon View
   --------------------------------------------------------------------------- */
.telegram-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}
.telegram-view.hidden { display: none; }

.coming-soon {
    text-align: center;
    max-width: 440px;
    padding: 48px 32px;
}
.coming-soon-icon {
    margin-bottom: 24px;
    opacity: 0.9;
}
.coming-soon h2 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.coming-soon-subtitle {
    font-size: 1.1rem;
    font-weight: 600;
    color: #3b82f6;
    margin-bottom: 16px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.coming-soon-desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 32px;
}
.coming-soon-features {
    text-align: left;
    display: inline-block;
}
.feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.feature-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3b82f6;
    flex-shrink: 0;
}
