:root {
  color-scheme: light;
  --navy: #16324f;
  --blue: #2878b5;
  --bg: #eef3f7;
  --panel: #ffffff;
  --text: #17212b;
  --muted: #647585;
  --line: #d8e2ea;
  --low: #2f855a;
  --moderate: #b7791f;
  --high: #c05621;
  --extreme: #b8323c;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 10px;
  padding: .8rem 1rem;
  background: var(--navy);
  color: white;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: wait; }
button.secondary {
  background: #e6eef5;
  color: var(--navy);
  border: 1px solid #c8d7e4;
}
.app-header {
  background: var(--navy);
  color: white;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.app-header h1 { margin: 0; font-size: 1.65rem; }
.app-header p { margin: .2rem 0 0; opacity: .85; }
main {
  max-width: 850px;
  margin: 0 auto;
  padding: 1rem;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 16px rgba(20, 50, 80, .06);
}
.panel h2 { margin: 0 0 .8rem; font-size: 1.15rem; }
.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
}
input, select {
  width: 100%;
  border: 1px solid #b9c8d4;
  border-radius: 10px;
  padding: .78rem;
  background: white;
  color: var(--text);
}
.button-row {
  display: flex;
  gap: .6rem;
  margin-top: .7rem;
  flex-wrap: wrap;
}
.status { margin: .75rem 0 0; color: var(--muted); }
.status.error { color: var(--extreme); font-weight: 700; }
.summary-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .72rem;
  color: var(--muted);
  margin: 0;
}
#locationName { margin: .2rem 0; font-size: 1.4rem; }
.muted { color: var(--muted); }
.risk-badge {
  min-width: 104px;
  text-align: center;
  border-radius: 14px;
  padding: .65rem .8rem;
  color: white;
}
.risk-badge span { display: block; font-size: .75rem; letter-spacing: .08em; }
.risk-badge strong { font-size: 2rem; line-height: 1; }
.risk-low { background: var(--low); }
.risk-moderate { background: var(--moderate); }
.risk-high { background: var(--high); }
.risk-extreme { background: var(--extreme); }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .7rem;
  margin-top: 1rem;
}
.metric {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .8rem;
  background: #f8fafc;
}
.metric span, .metric small { display: block; color: var(--muted); font-size: .78rem; }
.metric strong { display: block; margin: .35rem 0; font-size: 1.2rem; }
.event-message {
  margin-top: 1rem;
  border-left: 5px solid var(--blue);
  background: #eef7ff;
  padding: .8rem 1rem;
  border-radius: 8px;
  line-height: 1.45;
}
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
}
.section-title-row select { width: auto; }
canvas {
  display: block;
  width: 100%;
  height: auto;
  margin-top: .5rem;
  border-radius: 10px;
  background: #fbfdff;
}
.legend { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .78rem; margin-top: .6rem; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .25rem; }
.dot.stable { background: var(--low); }
.dot.moderate { background: var(--moderate); }
.dot.high { background: var(--extreme); }
.period-list { display: grid; gap: .65rem; }
.period {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .8rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .75rem;
  align-items: center;
}
.period-level {
  width: 68px;
  text-align: center;
  padding: .45rem;
  color: white;
  border-radius: 8px;
  font-size: .72rem;
  font-weight: 800;
}
.period p { margin: .12rem 0; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .8rem;
  margin: 1rem 0;
}
.settings-grid label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  border: 1px solid var(--line);
  padding: .75rem;
  border-radius: 10px;
}
.settings-grid label span { display: flex; align-items: center; gap: .3rem; white-space: nowrap; }
.settings-grid input { width: 76px; padding: .5rem; }
details summary { font-weight: 800; cursor: pointer; }
.note p { line-height: 1.5; }
footer {
  max-width: 850px;
  margin: 0 auto;
  padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .8rem;
}
.link-button { background: transparent; color: var(--blue); padding: 0; }
.hidden { display: none !important; }

@media (max-width: 650px) {
  .search-row { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .summary-top { align-items: center; }
}
