:root {
  --bg: #070b12;
  --surface: #0f1623;
  --surface-2: #161f30;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.14);
  --orange: #f97316;
  --orange-bg: rgba(249, 115, 22, 0.14);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.14);
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.14);
  --blue: #38bdf8;
  --blue-bg: rgba(56, 189, 248, 0.14);
  --radius: 14px;
  --font-sans: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

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

body {
  background: radial-gradient(circle at top right, #131d33 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  min-height: 100vh;
}

.mono {
  font-family: var(--font-mono);
}

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(7, 11, 18, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--red-bg);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.8);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.75); }
  70% { box-shadow: 0 0 0 9px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.25;
}

.subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
}

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

.clock-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.clock-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

#live-clock {
  font-size: 14px;
  font-weight: 700;
  color: var(--blue);
}

.btn-refresh {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-refresh:hover {
  background: #1f2b42;
  border-color: rgba(56, 189, 248, 0.45);
}

.btn-refresh.spinning #refresh-icon {
  display: inline-block;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ALERT STRIP */
.alert-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 22px;
  background: linear-gradient(90deg, rgba(234, 179, 8, 0.14), rgba(249, 115, 22, 0.1));
  border-bottom: 1px solid rgba(234, 179, 8, 0.28);
  font-size: 13.5px;
}

.alert-pill {
  padding: 4px 11px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.status-controlled {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.45);
}

.alert-message {
  color: #fef3c7;
}

/* LAYOUT */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.grid-hero {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 18px;
  align-items: start;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.grid-bottom {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 18px;
  align-items: start;
}

/* PANELS */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header.wrap {
  flex-wrap: wrap;
}

.panel-header h2 {
  font-size: 16.5px;
  font-weight: 700;
  color: #ffffff;
}

.panel-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* MAP & CHECKER */
.map-legend-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.leg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.dot.red { background: var(--red); }
.dot.orange { background: var(--orange); }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }
.dot.plume { background: #a855f7; }

.checker-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #0284c7);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn-primary:hover {
  opacity: 0.94;
  transform: translateY(-1px);
}

.select-input,
.search-input {
  flex: 1;
  min-width: 220px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  font-family: var(--font-sans);
  font-size: 13.5px;
}

.select-input:focus,
.search-input:focus {
  outline: none;
  border-color: var(--blue);
}

.checker-result {
  padding: 14px 16px;
  border-radius: 11px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  font-size: 14px;
}

.checker-result.hidden {
  display: none;
}

.checker-result.safe {
  background: var(--green-bg);
  border-color: rgba(16, 185, 129, 0.45);
}

.checker-result.caution {
  background: var(--yellow-bg);
  border-color: rgba(234, 179, 8, 0.45);
}

.checker-result.high {
  background: var(--red-bg);
  border-color: rgba(239, 68, 68, 0.5);
}

.checker-title {
  font-size: 15.5px;
  font-weight: 700;
  margin-bottom: 4px;
}

.checker-meta {
  font-size: 13px;
  color: #e2e8f0;
  margin-bottom: 6px;
}

.checker-advice {
  font-size: 13px;
  color: #cbd5e1;
}

.map-canvas {
  width: 100%;
  height: 520px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: #0a0f18;
}

/* TELEMETRY */
.status-chip {
  padding: 5px 11px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.chip-neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.chip-safe { background: var(--green-bg); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.4); }
.chip-caution { background: var(--yellow-bg); color: #fde047; border: 1px solid rgba(234, 179, 8, 0.4); }
.chip-high { background: var(--red-bg); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.45); }

.wind-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 11px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.14), rgba(56, 189, 248, 0.1));
  border: 1px solid rgba(168, 85, 247, 0.35);
  margin-bottom: 14px;
}

.wind-compass {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(168, 85, 247, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wind-arrow {
  font-size: 20px;
  color: #c084fc;
  transition: transform 0.4s ease;
}

.wind-title {
  font-size: 14px;
  color: #f8fafc;
}

.wind-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.metric-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
}

.metric-value {
  font-size: 19px;
  font-weight: 700;
  color: #ffffff;
}

.metric-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.forecast-strip {
  border-top: 1px solid var(--border);
  padding-top: 11px;
}

.forecast-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.forecast-items {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.fc-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
  font-size: 11px;
}

.fc-time {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.fc-dir {
  font-weight: 700;
  color: #e9d5ff;
  margin: 2px 0;
}

.fc-spd {
  color: var(--blue);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* TIMELINE */
.timeline-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline-list li {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  align-items: start;
  padding-bottom: 11px;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}

.timeline-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.tl-time {
  background: var(--surface-2);
  color: var(--blue);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
}

.tl-body {
  color: #cbd5e1;
}

.tl-body strong {
  color: #ffffff;
}

/* DISTRICTS MATRIX */
.filter-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab:hover {
  color: #ffffff;
  border-color: rgba(148, 163, 184, 0.4);
}

.tab.active {
  background: rgba(56, 189, 248, 0.18);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.5);
}

.safe-summary-box {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.32);
  border-radius: 10px;
  padding: 12px 15px;
  font-size: 13.5px;
  color: #d1fae5;
  margin-bottom: 14px;
}

.districts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 10px;
}

.district-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 13px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.district-card:hover {
  transform: translateY(-2px);
  border-color: rgba(56, 189, 248, 0.5);
}

.district-card.level-high {
  border-left: 4px solid var(--red);
}
.district-card.level-caution {
  border-left: 4px solid var(--yellow);
}
.district-card.level-safe {
  border-left: 4px solid var(--green);
}

.dc-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.dc-name {
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
}

.dc-dist {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.dc-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge-high { background: var(--red-bg); color: #fca5a5; }
.badge-caution { background: var(--yellow-bg); color: #fde047; }
.badge-safe { background: var(--green-bg); color: #6ee7b7; }
.badge-downwind { background: rgba(168, 85, 247, 0.22); color: #e9d5ff; }
.badge-upwind { background: rgba(56, 189, 248, 0.16); color: #bae6fd; }

/* NEWS FEED */
.news-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 620px;
  overflow-y: auto;
  padding-right: 4px;
}

.news-card {
  display: block;
  text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 15px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.news-card:hover {
  background: #1b263b;
  border-color: rgba(56, 189, 248, 0.45);
}

.news-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 11.5px;
}

.news-source {
  color: var(--blue);
  font-weight: 600;
}

.news-time {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.news-title {
  font-size: 14.5px;
  font-weight: 600;
  color: #f8fafc;
  line-height: 1.45;
}

.loading-state {
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* PROTOCOL & HOTLINES */
.hotline-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.hotline-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 10px;
  border-radius: 10px;
  text-decoration: none;
  border: 1px solid var(--border);
  transition: transform 0.12s ease;
}

.hotline-btn:hover {
  transform: translateY(-2px);
}

.hotline-btn.emergency { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.45); }
.hotline-btn.fire { background: rgba(249, 115, 22, 0.16); border-color: rgba(249, 115, 22, 0.45); }
.hotline-btn.bma { background: rgba(16, 185, 129, 0.16); border-color: rgba(16, 185, 129, 0.45); }
.hotline-btn.pcd { background: rgba(56, 189, 248, 0.16); border-color: rgba(56, 189, 248, 0.45); }

.hl-num {
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
}

.hl-name {
  font-size: 12px;
  color: #cbd5e1;
}

.protocol-block {
  margin-bottom: 16px;
}

.protocol-block:last-child {
  margin-bottom: 0;
}

.protocol-block h3 {
  font-size: 14.5px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 6px;
}

.proto-note {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.proto-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  color: #cbd5e1;
}

.proto-list li {
  position: relative;
  padding-left: 16px;
}

.proto-list.danger-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--red);
  font-weight: 700;
}

.proto-list.safe-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--green);
  font-weight: 700;
}

/* FOOTER */
.footer {
  border-top: 1px solid var(--border);
  padding: 18px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* LEAFLET DARK POPUP */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #0f172a !important;
  color: #f8fafc !important;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

/* RESPONSIVE */
@media (max-width: 1024px) {
  .grid-hero,
  .grid-bottom {
    grid-template-columns: 1fr;
  }
  .map-canvas {
    height: 400px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
  }
  .brand-text h1 {
    font-size: 15.5px;
  }
  .alert-strip {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 14px;
  }
  .container {
    padding: 12px 12px 30px;
  }
  .forecast-items {
    grid-template-columns: repeat(3, 1fr);
  }
}
