:root {
  --color-bg: #0b1e39;
  --color-fg: #e6eefc;
  --color-fg-muted: #dbe7ff;
  --panel-bg: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.12);
  --table-head-bg: rgba(20, 45, 80, 0.98);
  --table-head-fg: #e6f0ff;
  --table-row-alt: rgba(255, 255, 255, 0.03);
  --orange-bg-1: rgba(255, 171, 64, 0.18);
  --orange-bg-2: rgba(255, 171, 64, 0.1);
  --orange-border: rgba(230, 120, 20, 0.6);
  --orange-shadow-1: rgba(255, 159, 64, 0.35);
  --orange-shadow-2: rgba(255, 159, 64, 0.1);
  --orange-shadow-3: rgba(255, 159, 64, 0.25);
  --orange-fg: #2b1900;
  --orange-fg-sub: #4a2b00;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --radius-1: 0.25rem;
  --radius-2: 0.375rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  font-size: clamp(14px, 0.95vw, 18px);
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 1rem;
}

body.alert-mode {
  position: relative;
}

body.alert-mode::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(255, 159, 64, 0) 45%,
    rgba(255, 159, 64, 0.12) 70%,
    rgba(255, 159, 64, 0.2) 100%
  );
  opacity: 0.16;
  animation: alert-vignette 3s ease-in-out infinite;
  z-index: 1;
}

body.alert-mode-red::before {
  background: radial-gradient(
    circle at 50% 50%,
    rgba(255, 107, 107, 0) 45%,
    rgba(255, 107, 107, 0.12) 70%,
    rgba(255, 107, 107, 0.2) 100%
  );
}

@keyframes alert-vignette {
  0%,
  100% {
    opacity: 0.12;
  }
  50% {
    opacity: 0.25;
  }
}

.screen {
  height: 100vh;
  width: 100vw;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  padding: var(--space-2);
}

.screen.alert-on {
  box-shadow: inset 0 0 20rem var(--orange-shadow-3), inset 0 0 20rem var(--orange-shadow-1);
  animation: screenGlowOrange 1.8s ease-in-out infinite;
}

.screen.alert-red {
  box-shadow: inset 0 0 20rem rgba(255, 107, 107, 0.25), inset 0 0 20rem rgba(255, 107, 107, 0.35);
  animation: screenGlowRed 1.8s ease-in-out infinite;
}

@keyframes screenGlowOrange {
  0%,
  100% {
    box-shadow: inset 0 0 20rem var(--orange-shadow-3), inset 0 0 20rem var(--orange-shadow-1);
  }
  50% {
    box-shadow: none;
  }
}

@keyframes screenGlowRed {
  0%,
  100% {
    box-shadow: inset 0 0 20rem rgba(255, 107, 107, 0.25), inset 0 0 20rem rgba(255, 107, 107, 0.35);
  }
  50% {
    box-shadow: none;
  }
}

.left,
.right {
  min-width: 0;
  min-height: 0;
}

.left {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chart-container {
  flex: 1;
  min-height: 0;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-1);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
}

.chart-wrapper {
  flex: 1;
  min-height: 0;
}

.station-info-title {
  font-size: 1rem;
  margin-bottom: var(--space-2);
  color: #d5e3ff;
  text-align: center;
  font-weight: 700;
}

.map-container {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-1);
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

.right {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-1);
  padding: calc(var(--space-1) + 0.125rem) var(--space-2);
  color: var(--color-fg-muted);
}

.controls label {
  font-size: 0.8125rem;
  color: #bfd0ef;
}

.controls input,
.controls select,
.controls button {
  padding: var(--space-1) var(--space-2);
  font-size: 0.8125rem;
  border-radius: 0.1875rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-fg);
}

.controls input::placeholder {
  color: #98b1e0;
}

.controls select option {
  background: var(--color-bg);
  color: var(--color-fg);
}

.controls button {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.02));
  cursor: pointer;
  border-color: rgba(255, 255, 255, 0.18);
}

.controls button:hover {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.05));
}

.summary-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-2);
  padding: var(--space-3);
  color: #dfe9ff;
  line-height: 1.6;
  box-shadow: none;
  transition: all 0.4s ease;
}

.summary-panel.alert-on {
  background: linear-gradient(180deg, var(--orange-bg-1), var(--orange-bg-2));
  border: 1px solid var(--orange-border);
  box-shadow: 0 6px 24px var(--orange-shadow-1), 0 2px 10px var(--orange-shadow-3), inset 0 1px 0 var(--orange-shadow-2);
  color: var(--orange-fg);
  animation: panelGlowOrange 1.8s ease-in-out infinite;
}

.summary-panel.alert-red {
  background: linear-gradient(180deg, rgba(255, 107, 107, 0.22), rgba(255, 107, 107, 0.12));
  border: 1px solid rgba(200, 40, 40, 0.6);
  box-shadow: 0 6px 24px rgba(255, 107, 107, 0.35), 0 2px 10px rgba(255, 107, 107, 0.25), inset 0 1px 0 rgba(255, 107, 107, 0.12);
  color: #3a0b0b;
  animation: panelGlowRed 1.8s ease-in-out infinite;
}

.summary-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: var(--space-1);
}

.summary-panel.alert-on .summary-title,
.summary-panel.alert-red .summary-title {
  font-size: 1.7rem;
}

.summary-sub {
  font-size: 0.875rem;
  color: #bcd0ff;
}

.table-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-1);
  background: var(--panel-bg);
  overflow: hidden;
}

.table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #4f9cff;
  animation: spin 1s linear infinite;
}

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

@keyframes panelGlowOrange {
  0%,
  100% {
    background: linear-gradient(180deg, var(--orange-bg-1), var(--orange-bg-2));
    border-color: var(--orange-border);
    box-shadow: 0 6px 24px var(--orange-shadow-1), 0 2px 10px var(--orange-shadow-3), inset 0 1px 0 var(--orange-shadow-2);
  }
  50% {
    background: var(--color-bg);
    border-color: var(--panel-border);
    box-shadow: none;
  }
}

@keyframes panelGlowRed {
  0%,
  100% {
    background: linear-gradient(180deg, rgba(255, 107, 107, 0.22), rgba(255, 107, 107, 0.12));
    border-color: rgba(200, 40, 40, 0.6);
    box-shadow: 0 6px 24px rgba(255, 107, 107, 0.35), 0 2px 10px rgba(255, 107, 107, 0.25), inset 0 1px 0 rgba(255, 107, 107, 0.12);
  }
  50% {
    background: var(--color-bg);
    border-color: var(--panel-border);
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
  }
}
