/* Upwind web companion.
   Theme note: the EPA category colors (chips, sparkline strokes, map pins) are DATA
   colors set inline from app.js and identical in both themes — only the surrounding
   chrome below adapts to light/dark. */

:root {
  color-scheme: light dark;
  --bg: #f2f5f7;
  --surface: #ffffff;
  --surface-2: #e9eef2;
  --ink: #182430;
  --ink-2: #495866;
  --ink-3: #77848f;
  --line: rgba(24, 36, 48, 0.14);
  --accent: #0b6e7f;
  --accent-hover: #095e6d;
  --accent-ink: #ffffff;
  --error: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(10, 20, 30, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1519;
    --surface: #171f26;
    --surface-2: #212b34;
    --ink: #e7edf2;
    --ink-2: #a7b3be;
    --ink-3: #78848f;
    --line: rgba(231, 237, 242, 0.16);
    --accent: #35a3b4;
    --accent-hover: #4db4c4;
    --accent-ink: #06272d;
    --error: #f2867c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  max-width: 76rem;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0.25rem 0; }

.muted { color: var(--ink-2); }
.small { font-size: 0.82rem; }

.site-header { margin-bottom: 1rem; }
.site-header h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
.tagline { color: var(--ink-2); max-width: 46rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.section-title { font-size: 1.05rem; margin-bottom: 0.5rem; }

/* ---------- Controls ---------- */

.controls {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.4fr auto;
  gap: 1rem 1.5rem;
  align-items: start;
}

.control-group { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.control-label { font-weight: 600; font-size: 0.88rem; }
.control-go { justify-content: end; align-self: end; }

.origin-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.btn {
  font: inherit;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

select, input[type="text"], input[type="date"] {
  font: inherit;
  padding: 0.42rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
}
input[type="text"]#latlon { flex: 1 1 14rem; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0.15rem 0 0; }
.range-ends { display: flex; justify-content: space-between; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: fit-content; }
.seg-btn {
  font: inherit;
  font-size: 0.86rem;
  padding: 0.4rem 0.7rem;
  border: none;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  border-left: 1px solid var(--line);
}
.seg-btn:first-child { border-left: none; }
.seg-btn.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.date-wrap { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.date-wrap label { display: flex; flex-direction: column; gap: 0.2rem; color: var(--ink-2); }
.field-error { flex-basis: 100%; margin: 0; color: var(--error); font-weight: 600; }
input[aria-invalid="true"] { border-color: var(--error); }

.status { min-height: 1.4rem; color: var(--ink-2); margin: 0 0 0.75rem 0.2rem; }
.status.busy::before {
  content: "";
  display: inline-block;
  width: 0.75em; height: 0.75em;
  margin-right: 0.5em;
  border: 2px solid var(--ink-3);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -0.1em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Verdict banner ---------- */

.verdict-main { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.verdict-number { display: flex; flex-direction: column; }
.verdict-aqi { font-size: 4rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.verdict-text { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.verdict-headline { font-size: 1.25rem; font-weight: 650; }
.prelim { color: var(--ink-2); margin-top: 0.6rem; }

/* EPA category chip — background + text colors are set inline (data colors). */
.chip {
  display: inline-block;
  width: fit-content;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);   /* hairline is chrome, keeps yellow visible on white */
  font-size: 0.82rem;
  font-weight: 650;
  white-space: nowrap;
}
.chip-nodata { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Escape cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 1rem;
}

.card { display: flex; flex-direction: column; gap: 0.55rem; margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; gap: 0.6rem; align-items: start; }
.card-name { font-size: 1.08rem; }
.card-region { color: var(--ink-2); font-size: 0.84rem; margin: 0.1rem 0 0; }
.card-tagline { color: var(--ink-2); font-size: 0.86rem; font-style: italic; margin: 0; }

.spark { position: relative; cursor: crosshair; }
.spark svg { display: block; width: 100%; height: 64px; }
.spark-grid { stroke: currentColor; opacity: 0.13; stroke-width: 1; }
.spark-caption { display: flex; justify-content: space-between; margin-top: 0.1rem; }

.card-stats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; }
.card-stats li { color: var(--ink-2); }
.card-stats .drive { color: var(--ink); font-weight: 600; }
.card-summary { font-size: 0.92rem; margin: 0; }

.lodging { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.2rem; }
.lodging a {
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.32rem 0.65rem;
  background: var(--surface-2);
}
.lodging a:hover { border-color: var(--accent); }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2.2rem 1.5rem;
}
.empty-state h3 { font-size: 1.15rem; margin-bottom: 0.4rem; }
.empty-state p { color: var(--ink-2); max-width: 34rem; margin-left: auto; margin-right: auto; }

/* ---------- Map ---------- */

.map { height: 380px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }

/* ---------- Sparkline tooltip ---------- */

.spark-tip {
  position: fixed;
  z-index: 10;
  transform: translate(-50%, -100%);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- Attribution ---------- */

.attribution { margin-top: 2rem; border-top: 1px solid var(--line); padding-top: 0.9rem; color: var(--ink-2); }

/* ---------- Responsive: single column under 700px ---------- */

@media (max-width: 700px) {
  .controls { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .verdict-aqi { font-size: 3.2rem; }
  .control-go { justify-content: stretch; }
  .control-go .btn { width: 100%; }
}
