/* Starlink Availability Platform: used by index.html and country.html
   Look: an aeronautical chart. Cool chart paper, slate ink, the map framed by a neatline,
   and chart magenta for everything clickable.
   Uses only system fonts: Segoe UI on Windows, San Francisco on macOS, Roboto on Android/Linux. */


:root {
  --paper: #f2f5f7;     /* page background */
  --surface: #ffffff;   /* tables, map frame */
  --ink: #1d2733;       /* text */
  --muted: #5b6875;     /* secondary text */
  --rule: #c8d1d8;      /* lines */
  --rule-soft: #e3e8ec; /* row lines */
  --water: #d5e2e9;     /* map ocean */
  --accent: #a1286a;    /* chart magenta: links, buttons, focus, selection */
  --accent-soft: #f6e8f0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- headings ---------- */

h1, h2, h3 {
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0;
}

h1 { font-size: 36px; letter-spacing: -0.02em; }
h2 { font-size: 22px; }
h3 { font-size: 16px; font-weight: 600; margin: 22px 0 6px; }

.small { font-size: 13px; color: var(--muted); }
.error { color: #c62828; font-weight: 500; }

/* ---------- masthead and sources (index.html) ---------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px 32px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.lede { margin: 6px 0 0; max-width: 62ch; font-size: 17px; color: var(--muted); }
.lede.wide { max-width: 100ch; }  /* timeline.html, compare.html: nothing next to it in the masthead */

/* status line below the masthead: when each source was last updated (wraps on small screens) */
#status {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 22px;
  margin: 10px 0 0;
}
#status b, #status .status-label { font-weight: 600; color: var(--ink); }
#status .status-label { flex-basis: 100%; font-size: 16px; }

.sources {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 6px 32px;
  margin: 14px 0 26px;
  font-size: 13px;  /* the descriptions; the headlines (dt) are larger */
  color: var(--muted);
}
.sources dt { font-weight: 600; color: var(--ink); font-size: 16px; }  /* the same size as "Last updated:" */
.sources dd { margin: 0; max-width: 60ch; }

/* ---------- the map: framed like a printed chart (outer line + inner neatline) ---------- */

.chart {
  background: var(--surface);
  border: 1px solid var(--ink);
  outline: 1px solid var(--rule);
  outline-offset: 3px;
  padding: 12px 14px 14px;
  margin: 4px 4px 0;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}
.chart-toolbar label { display: flex; align-items: center; gap: 8px; font-weight: 500; }

#mapDayNote { margin: 8px 0 0; min-height: 0; }
#mapDayNote:empty { display: none; }

#map {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 10px;
  background: var(--water);
  border: 1px solid var(--rule);
  cursor: grab;
}
#map:active { cursor: grabbing; }

#map path {
  stroke: #fff;
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;  /* borders stay thin when zooming in */
}
#map path:hover { stroke: var(--ink); stroke-width: 1.2; }

/* legend: one key per value, the count in muted figures */
#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin-top: 10px;
}
#legend span.legend-item {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  padding: 3px 9px 3px 7px;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
#legend span.legend-item:hover { border-color: var(--rule); }
#legend span.legend-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.hint { margin: 12px 4px 0; }

#tooltip {
  display: none;
  position: absolute;
  z-index: 10;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--ink);
  border-left: 3px solid var(--accent);
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(29, 39, 51, 0.18);
}
#tooltip b { font-size: 15px; font-weight: 700; }

/* color key boxes (legend, table) */
.box {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1px solid rgba(29, 39, 51, 0.35);
  border-radius: 2px;
}

/* ---------- sections ---------- */

section { margin-top: 44px; }
section.chart { margin-top: 4px; }  /* the map frame sits right below the sources */

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding-bottom: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

/* country.html: plain h2 headings with the same rule */
body > h2 {
  margin-top: 44px;
  padding-bottom: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

/* ---------- controls ---------- */

input, select, button {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}

input, select {
  padding: 5px 8px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
}
input:hover, select:hover { border-color: var(--muted); }

button {
  padding: 5px 12px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 3px;
  font-weight: 500;
  cursor: pointer;
}
button:hover { background: #86205a; border-color: #86205a; }
button.quiet { background: transparent; color: var(--accent); }
button.quiet:hover { background: var(--accent-soft); }

/* filter bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
#search, #prefixSearch { min-width: 220px; }
.filters-label { margin-left: 8px; font-weight: 500; }

#activeFilters:empty, #prefixActiveFilters:empty { display: none; }
#activeFilters, #prefixActiveFilters { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 2px 2px 2px 9px;
  font-size: 13px;
}
.chip button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
  padding: 0 6px;
}
.chip button:hover { background: none; color: var(--ink); }

/* ---------- tables ---------- */

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--rule-soft);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 2px solid var(--ink);
}

tbody tr:hover td { background: #f7f9fa; }

#countries th, #prefixTable th { cursor: pointer; user-select: none; }
#countries th:hover, #prefixTable th:hover { color: var(--accent); }
#countries td:first-child a { font-weight: 600; text-decoration: none; }
#countries td:first-child a:hover { text-decoration: underline; }

.table-scroll {
  max-height: 600px;
  overflow: auto;
  border: 1px solid var(--rule);
  background: var(--surface);
}
.table-scroll table { border: none; }

/* country.html: label/value tables */
table.info { border: 1px solid var(--rule); max-width: 900px; }
table.info th {
  width: 280px;
  font-weight: 500;
  color: var(--muted);
  background: #f7f9fa;
  white-space: normal;
}
table.info td { white-space: normal; }

/* ---------- charts (country.html) ---------- */

#apnicChart, .mlabChart {
  display: block;
  width: 100%;
  max-width: 820px;
  height: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
}
.tick text { font-family: var(--font); font-size: 11px; fill: var(--muted); }
.tick line, .domain { stroke: var(--rule); }

#countryMap {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
  margin-top: 18px;
  background: var(--water);
  border: 1px solid var(--ink);
  outline: 1px solid var(--rule);
  outline-offset: 3px;
}
#countryMap path { stroke: #fff; stroke-width: 0.5; }

.back { margin: 0 0 10px; font-weight: 500; }
.back a { text-decoration: none; }
.back a:hover { text-decoration: underline; }

/* country.html: M-Lab and Cloudflare side by side, one row per metric (one column on small screens) */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 28px;
}
.compare h3 { margin-top: 4px; }
.compare h4 { font-size: 14px; font-weight: 600; margin: 16px 0 6px; }
.compare p { margin: 4px 0; }
@media (max-width: 900px) {
  .compare { grid-template-columns: 1fr; }
}

/* ---------- query (index.html) and guide (query-guide.html) ---------- */

#queryText {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 8px 10px;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  resize: vertical;
}
#queryText:hover { border-color: var(--muted); }

code, pre {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 0.92em;
  background: #e8edf1;
  border-radius: 3px;
}
code { padding: 1px 4px; }
pre { padding: 10px 12px; overflow-x: auto; line-height: 1.5; }

.guide { max-width: 900px; }
.guide p, .guide li { max-width: 80ch; }
.guide table td { white-space: normal; }
.guide h2 { margin: 30px 0 8px; }
.guide h3 { margin: 22px 0 8px; }
.guide p, .guide li { line-height: 1.6; }
.guide .intro { margin: 16px 0 0; padding-left: 20px; }
.guide .intro li { margin: 4px 0; }
/* tables and columns: name, rows and link on one line, the description below */
.guide .table-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 34px 0 4px; }
.guide .table-head h3 { margin: 0; }
.guide .table-description { margin: 0 0 10px; }

/* link from the query field to the guide: clearly visible */
.guide-link {
  font-size: 15px;
  font-weight: 600;
  padding: 5px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 3px;
  text-decoration: none;
}
.guide-link:hover { background: var(--accent); color: #fff; }

/* ---------- timeline (timeline.html) and comparison (compare.html) ---------- */

/* index.html: links to the timeline and the comparison, in the masthead */
.page-links { display: flex; flex-wrap: wrap; gap: 8px; }
.page-links a {
  font-weight: 600;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 3px;
  text-decoration: none;
}
.page-links a:hover { background: var(--accent); color: #fff; }

/* the timeframe or the two countries, below the masthead */
.timeframe { margin: 18px 0 6px; }
#coverage:empty { display: none; }

/* key figures: one tile per figure, the countries folded away below it */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--ink);
  padding: 10px 12px 12px;
}
.tile-value { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-percent { font-size: 15px; font-weight: 500; color: var(--muted); }
.tile-label { font-weight: 600; margin: 4px 0 6px; }
.tile details { font-size: 13px; margin-top: 6px; }
.tile summary { cursor: pointer; color: var(--accent); }
.tile ul { margin: 6px 0 0; padding-left: 18px; max-height: 220px; overflow: auto; }

/* events: one checkbox per type */
.event-types { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; }
.event-type { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* below a chart with several lines: their names */
.line-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 0; }

#countryTable th { cursor: pointer; user-select: none; }
#countryTable th:hover { color: var(--accent); }

/* compare.html: the overview, the values that are the same highlighted in green */
.compare-table thead th { width: auto; background: var(--surface); color: var(--ink); font-size: 14px; }
.compare-table tr.same td { background: #e3f5e9; }

/* ---------- footer ---------- */

footer {
  margin-top: 48px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  body { padding: 18px 14px 32px; }
  h1 { font-size: 28px; }
  .chart { padding: 10px; margin: 4px 0 0; outline: none; }
  .chart-toolbar label { flex-wrap: wrap; min-width: 0; max-width: 100%; }
  .chart-toolbar select { max-width: 100%; }
  select { max-width: 100%; }
  #search, #prefixSearch, #countrySearch { min-width: 0; flex: 1 1 100%; }
  .filters-label { margin-left: 0; }
}

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