* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #1d232a; background: #f4f5f7;
  display: flex; flex-direction: column;
}
header { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: #1f3a5f; color: #fff; }
header h1 { margin: 0; font-size: 1.2rem; display: flex; align-items: center; gap: .45rem; color: #f4f0e4; letter-spacing: -0.02em; }
header h1 .logo { width: 34px; height: 34px; display: block; flex: none; }
header h1 .cache { color: #f8b818; }
header .muted { color: #c9d6e8; }
header nav { display: flex; gap: 2px; }
header nav a { color: #c9d6e8; text-decoration: none; padding: 2px 10px; border-radius: 4px; }
header nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
header nav a[aria-current=page] { background: rgba(255,255,255,.18); color: #fff; }
.muted { color: #66707a; }
h2 { font-size: 1rem; margin: 0 0 .5rem; display: flex; align-items: center; gap: .5rem; }

#filters { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; padding: .5rem 1rem; background: #fff; border-bottom: 1px solid #dde1e6; }
#filters label { display: flex; flex-direction: column; font-size: 12px; color: #55606b; }
#filters select, #filters input { font: inherit; padding: 2px 4px; min-width: 7rem; }
#f-minsnr { width: 5rem; min-width: 0 !important; }
#filters input[type=checkbox] { min-width: 0; margin: 0; }
fieldset { border: 1px solid #dde1e6; border-radius: 4px; padding: 2px 6px 4px; margin: 0; display: flex; flex-wrap: wrap; gap: 2px 8px; }
legend { font-size: 12px; color: #55606b; padding: 0 3px; }
fieldset label { flex-direction: row !important; align-items: center; gap: 3px; font-size: 13px !important; color: #1d232a !important; }
fieldset label.empty { color: #8a939c !important; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
button { font: inherit; padding: 3px 10px; cursor: pointer; }

main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; min-height: 0; }
#map-wrap { position: relative; min-height: 400px; }
#map { position: absolute; inset: 0; }
#map-info { position: absolute; left: 10px; bottom: 10px; z-index: 500; background: rgba(255,255,255,.9); padding: 3px 8px; border-radius: 4px; }
aside { overflow-y: auto; background: #fff; border-left: 1px solid #dde1e6; padding: .75rem; }
section { margin-bottom: 1.25rem; }

.solar-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.solar-grid div { background: #f4f5f7; border-radius: 4px; padding: 6px 8px; }
.solar-grid b { font-size: 1.15rem; display: block; }
.tag { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 12px; background: #e6ebf1; }
.tag.quiet, .tag.strong { background: #d5f0dc; }
.tag.unsettled, .tag.workable { background: #fff1c2; }
.tag.active, .tag.weak { background: #ffe0c2; }
.tag.storm { background: #ffcfcf; }

#country-form { display: flex; gap: 4px; margin-bottom: .5rem; }
#country-form input { flex: 1; font: inherit; padding: 3px 6px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin-bottom: .5rem; }
.facts dt { color: #66707a; }
.facts dd { margin: 0; }

table { border-collapse: collapse; width: 100%; }
.hours-wrap { overflow-x: auto; }
.hours { table-layout: fixed; min-width: 760px; font-size: 13px; }
.hours th, .hours td { border: 1px solid #e6e9ed; text-align: center; padding: 4px 0; }
.hours th:first-child { width: 52px; }
.hours td { cursor: pointer; font-variant-numeric: tabular-nums; }
.hours td.none { background: #f8f9fa; color: #c0c6cc; }
.hours td.now { outline: 2px solid #1f3a5f; outline-offset: -2px; }
.hours td.both { font-weight: 700; }
.hours .local { color: #8a939c; font-weight: normal; }
#cell-detail { margin-top: .5rem; font-size: 13px; }

.trend-row { display: grid; grid-template-columns: 42px 150px 1fr; align-items: center; column-gap: 8px;
  padding: 4px 0; border-bottom: 1px solid #eef0f2; }
.trend-band { font-weight: 600; text-decoration: none; }
.trend-band:hover { text-decoration: underline; }
.trend-nums { grid-column: 2 / 4; font-size: 12px; }
.spark { display: block; }
.level { justify-self: start; padding: 1px 6px; border-radius: 3px; font-size: 12px; background: #e6ebf1; white-space: nowrap; }
.level.well_above { background: #1e8e3e; color: #fff; }
.level.above { background: #d5f0dc; }
.level.below { background: #ffe0c2; }
.level.well_below { background: #ffcfcf; }
.level.learning, .level.no_data { background: none; color: #66707a; font-style: italic; }

.op-band { margin-bottom: .6rem; }
.op-band h3 { font-size: 13px; margin: 0 0 2px; }
.op-table { font-size: 12px; }
.op-table td, .op-table th { padding: 1px 4px; border-bottom: 1px solid #eef0f2; text-align: left; }
.op-table th { color: #66707a; font-weight: normal; }
.op-table a { color: #1f5fa8; cursor: pointer; text-decoration: none; }
.op-table a:hover { text-decoration: underline; }
.low { color: #a36a00; }

.spot-popup { max-height: 260px; overflow-y: auto; font-size: 12px; }
.spot-popup table td, .spot-popup table th { padding: 1px 4px; border-bottom: 1px solid #eee; white-space: nowrap; }

/* ---------- stats pages ---------- */
body.stats-page { height: auto; min-height: 100%; }
#tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 1rem; background: #fff; border-bottom: 1px solid #dde1e6; }
#tabs a { padding: 8px 12px; color: #55606b; text-decoration: none; border-bottom: 3px solid transparent; }
#tabs a:hover { color: #1d232a; }
#tabs a[aria-current=page] { color: #1f3a5f; border-bottom-color: #1f3a5f; font-weight: 600; }
#stats { display: block; padding: 1rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.panel { background: #fff; border: 1px solid #dde1e6; border-radius: 6px; padding: .75rem 1rem; margin-bottom: 1rem; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 380px; }
.small { font-size: 12px; font-weight: normal; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.card { background: #fff; border: 1px solid #dde1e6; border-radius: 6px; padding: .6rem .8rem; display: flex; flex-direction: column; }
.card span { color: #66707a; font-size: 12px; }
.card b { font-size: 1.4rem; }
.card small { color: #66707a; font-size: 11px; }
.table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; }
table.data { font-size: 13px; }
table.data th, table.data td { padding: 3px 8px; border-bottom: 1px solid #eef0f2; text-align: left; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: #fff; color: #55606b; font-weight: 600; cursor: pointer; user-select: none; }
table.data th.desc::after { content: " ▾"; }
table.data th.asc::after { content: " ▴"; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data a { color: #1f5fa8; text-decoration: none; }
table.data a:hover { text-decoration: underline; }
.band-tag { display: inline-block; padding: 0 5px; border-radius: 3px; color: #fff; font-size: 11px; line-height: 16px; }
.heat-wrap { overflow-x: auto; }
table.heat { table-layout: fixed; min-width: 640px; font-size: 11px; }
table.heat th, table.heat td { border: 1px solid #eef0f2; text-align: center; padding: 3px 0; }
table.heat th:first-child { width: 48px; text-align: right; padding-right: 6px; }
table.heat td.none { color: #c0c6cc; background: #fafbfc; }
h2 select { font: inherit; font-weight: normal; font-size: 13px; }

.filter-switch { display: none; }
.filter-switch-label { display: none; }

@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  html, body { height: auto; }
  body { padding-bottom: env(safe-area-inset-bottom); }
  header {
    position: sticky; top: 0; z-index: 600; flex-wrap: wrap; align-items: center;
    gap: .35rem .5rem; padding: calc(.4rem + env(safe-area-inset-top)) .75rem .45rem;
  }
  header h1 { order: 1; flex: 1; font-size: 1.05rem; }
  header h1 .logo { width: 28px; height: 28px; }
  header nav { order: 3; flex: 1 0 100%; gap: 4px; }
  header nav a { flex: 1; text-align: center; padding: 8px 4px; }
  #status { order: 4; flex: 1 0 100%; font-size: 12px; }
  .filter-switch {
    display: block; position: absolute; left: -9999px; top: 0; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .filter-switch-label {
    order: 2; display: inline-block; padding: 6px 12px; border-radius: 4px;
    background: rgba(255,255,255,.16); color: #fff; font-size: 14px; cursor: pointer;
  }
  .filter-switch:focus-visible + .filter-switch-label { outline: 2px solid #fff; outline-offset: 2px; }
  .filter-switch:checked + .filter-switch-label { background: #fff; color: #1f3a5f; }
  #filters { display: none; flex-direction: column; align-items: stretch; gap: .6rem; padding: .75rem; }
  body:has(#filter-toggle:checked) #filters { display: flex; }
  #filters select, #filters input:not([type=checkbox]), #country-form input, #op-hour, h2 select {
    font-size: 16px; min-height: 44px;
  }
  #filters select, #filters input:not([type=checkbox]) { width: 100%; }
  #filters button, #country-form button { min-height: 44px; }
  fieldset { padding: 6px 8px 8px; }
  fieldset label { padding: 6px 2px; }
  main { display: block; }
  #map-wrap { height: calc(100dvh - 9.5rem); min-height: 280px; }
  aside { overflow: visible; border-left: 0; border-top: 1px solid #dde1e6; }
  .leaflet-bar a, .leaflet-control-zoom a { width: 36px; height: 36px; line-height: 36px; }
  .hours td { padding: 10px 0; }
  #tabs a { padding: 10px 12px; }
  #work, #stats { padding: .75rem; }
  #map-info { max-width: calc(100% - 70px); }
}

body.work-page { height: auto; min-height: 100%; }
#work { display: block; padding: 1rem; max-width: 1400px; width: 100%; margin: 0 auto; }
#work #country-form { max-width: 28rem; }
#openings { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: .25rem 1.5rem; align-items: start; }
#openings.muted { display: block; }
#country { scroll-margin-top: 1rem; }
#country a { color: #1f5fa8; }
