:root {
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --line: #d8e2e1;
  --text: #172326;
  --muted: #647477;
  --green: #16895a;
  --green-2: #2db473;
  --yellow: #f5b83b;
  --red: #d94841;
  --blue: #3578b8;
  --ink: #0f1b20;
  --shadow: 0 18px 40px rgba(14, 31, 35, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Noto Sans Thai", "Helvetica Neue", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(12, 35, 36, 0.54), rgba(12, 35, 36, 0.5)),
    url("/assets/login-map.svg") center / cover;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-lockup {
  margin-bottom: 28px;
}

.brand-mark {
  color: var(--green);
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label,
.chart-toolbar label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-form input,
.chart-toolbar select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
}

.login-form input:focus,
.chart-toolbar select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 137, 90, 0.14);
}

.login-form button {
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  padding: 12px 16px;
  font-weight: 800;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  background: #102125;
  color: #e9f2ef;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 22px 16px;
}

.sidebar-brand {
  display: grid;
  gap: 7px;
  color: #a9bdba;
  font-size: 13px;
  font-weight: 700;
}

.sidebar .brand-mark {
  color: #64d28d;
  font-size: 28px;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: 8px;
  margin-top: 30px;
}

.nav-item,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
}

.nav-item {
  width: 100%;
  background: transparent;
  color: #c6d5d2;
  text-align: left;
  padding: 11px 12px;
  font-weight: 700;
}

.nav-item.is-active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.sidebar-foot {
  display: grid;
  gap: 10px;
}

.muted {
  color: #aebbb9;
  font-size: 13px;
}

.ghost-button {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.24);
  color: #ffffff;
  padding: 10px 12px;
}

.workspace {
  min-width: 0;
  padding: 22px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.topbar p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 19px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
}

.summary-tile {
  min-height: 86px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  display: grid;
  align-content: space-between;
}

.summary-tile span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-tile strong {
  font-size: 30px;
  line-height: 1;
}

.summary-tile.good {
  border-left: 4px solid var(--green);
}

.summary-tile.watch {
  border-left: 4px solid var(--yellow);
}

.summary-tile.critical {
  border-left: 4px solid var(--red);
}

.view-section {
  display: none;
  min-height: 0;
}

.view-section.is-visible {
  display: block;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  min-height: 650px;
}

.map-panel,
.detail-panel,
.chart-panel,
.alerts-panel,
.chart-toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.map-panel {
  position: relative;
  overflow: hidden;
  min-height: 650px;
}

.map-canvas,
.fallback-map {
  position: absolute;
  inset: 0;
}

.fallback-map {
  background:
    linear-gradient(32deg, rgba(42, 86, 72, 0.34), rgba(255, 255, 255, 0.02)),
    radial-gradient(circle at 24% 68%, rgba(76, 127, 143, 0.7) 0 8%, transparent 9%),
    radial-gradient(circle at 72% 22%, rgba(195, 174, 135, 0.72) 0 13%, transparent 14%),
    linear-gradient(135deg, #d8d0bc 0 24%, #a6b1ad 25% 31%, #d6dccf 32% 44%, #8d9b95 45% 48%, #c7d0c8 49% 100%);
}

.fallback-map::before,
.fallback-map::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 0 0 2px rgba(80, 93, 92, 0.2);
  transform: rotate(-8deg);
}

.fallback-map::before {
  width: 72%;
  height: 28px;
  left: 9%;
  top: 42%;
}

.fallback-map::after {
  width: 26px;
  height: 78%;
  left: 48%;
  top: 10%;
}

.map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 999px;
  width: 22px;
  height: 22px;
  box-shadow: 0 0 0 3px #fff, 0 8px 18px rgba(0, 0, 0, 0.25);
}

.map-marker.green {
  background: var(--green-2);
}

.map-marker.yellow {
  background: var(--yellow);
}

.map-marker.red {
  background: var(--red);
}

.map-marker.unknown {
  background: #879395;
}

.weather-panel {
  position: absolute;
  left: 18px;
  top: 18px;
  width: min(260px, calc(100% - 36px));
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(210, 222, 220, 0.9);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(13, 33, 38, 0.12);
}

.weather-title,
.section-heading {
  font-size: 13px;
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
}

.weather-panel dl {
  margin: 10px 0 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  font-size: 13px;
}

.weather-panel dt {
  color: var(--muted);
}

.weather-panel dd {
  margin: 0;
  font-weight: 800;
}

.detail-panel {
  padding: 18px;
  overflow: auto;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 20px;
}

.panel-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  white-space: nowrap;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.green {
  background: rgba(45, 180, 115, 0.14);
  color: #0a6b43;
}

.status-pill.yellow {
  background: rgba(245, 184, 59, 0.2);
  color: #8d5a00;
}

.status-pill.red {
  background: rgba(217, 72, 65, 0.15);
  color: #a62d27;
}

.status-pill.unknown {
  background: #edf1f1;
  color: var(--muted);
}

.traffic-lights {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.traffic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.light-set {
  display: flex;
  gap: 6px;
}

.light {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #dfe6e6;
}

.light.green.active {
  background: var(--green-2);
}

.light.yellow.active {
  background: var(--yellow);
}

.light.red.active {
  background: var(--red);
}

.reading-list,
.alert-list {
  display: grid;
  gap: 10px;
}

.reading-item,
.alert-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.reading-main,
.alert-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.reading-main strong {
  font-size: 22px;
}

.reading-meta,
.alert-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.section-heading {
  margin: 18px 0 10px;
}

.cctv-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.cctv-tile {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2f2;
  aspect-ratio: 16 / 9;
}

.cctv-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cctv-tile span {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(15, 27, 32, 0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.chart-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 240px));
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.chart-panel {
  padding: 18px;
}

.chart-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.chart-title-row h2 {
  margin: 0;
  font-size: 20px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 5px;
}

#trendChart {
  width: 100%;
  max-height: 520px;
}

.alerts-panel {
  padding: 18px;
}

.alert-item {
  border-left: 4px solid var(--yellow);
}

.alert-item.red {
  border-left-color: var(--red);
}

.alert-item.yellow {
  border-left-color: var(--yellow);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow: auto;
    margin-top: 0;
  }

  .sidebar-foot {
    grid-auto-flow: column;
    align-items: center;
  }

  .map-layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 14px;
  }

  .topbar,
  .chart-title-row {
    align-items: start;
    flex-direction: column;
  }

  .summary-grid,
  .chart-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .map-panel {
    min-height: 520px;
  }

  .map-layout {
    min-height: 0;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .sidebar-foot {
    grid-auto-flow: row;
  }
}

@media (max-width: 520px) {
  .summary-grid,
  .chart-toolbar {
    grid-template-columns: 1fr;
  }

  .login-panel {
    padding: 24px;
  }
}
