/* ==========================================================================
   Dashboard: page layout, cards, and the globe.

   Replaces misc.css, grid.css, media.css and index.css. Colours come from theme.css
   and the top bar from site-bar.css.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-body);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

a {
  color: var(--label-color);
}

a:hover {
  color: var(--highlight-color);
}

a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--highlight-color);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* The sprite itself must never render or take up space. */
.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -0.125em;
}

.eyebrow {
  font-size: var(--fs-xs);
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  background: var(--bg-chip);
}

.link-button {
  align-self: flex-start;
  padding: var(--space-2) 0 0;
  border: 0;
  background: none;
  color: var(--label-color);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-chip);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

/* --- page ------------------------------------------------------------------ */

.dash {
  max-width: 1360px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-7);
}

.dash-head {
  margin-bottom: var(--space-5);
}

.dash-head h1 {
  font-size: clamp(1.625rem, 3.2vw, 2.125rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.dash-head p {
  margin-top: 6px;
  color: var(--text-secondary);
}

/* Paired by height: the visit card beside the globe, then three shorter cards, then the
   headlines across the whole width. */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    "visit globe globe"
    "weather smile photo"
    "news news news";
  gap: 20px;
  align-items: stretch;
}

.area-visit { grid-area: visit; }
.area-globe { grid-area: globe; }
.area-weather { grid-area: weather; }
.area-smile { grid-area: smile; }
.area-photo { grid-area: photo; }
.area-news { grid-area: news; }

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-head h2 {
  font-size: 1.0625rem;
  line-height: 1.3;
}

.card-sub {
  margin-top: 2px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.card-note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.card-note .icon {
  margin-top: 3px;
}

.card-caption {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.field-error {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Every source for a card failed. */
.frame-notice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

/* Label and value pairs. Each row is a pair of grid cells; an empty row - its source
   failed or had nothing to say - contributes no cells and so takes no space. */
.kv {
  display: grid;
  grid-template-columns: minmax(84px, auto) minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  font-size: 0.90625rem;
}

.kv-row {
  display: contents;
}

.kv-label {
  color: var(--text-muted);
}

.kv-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.kv-row.field-error {
  display: block;
  grid-column: 1 / -1;
}

/* --- about your visit -------------------------------------------------------- */

.visit-place {
  display: flex;
  align-items: center;
  gap: 14px;
}

.visit-place:empty,
.visit-clock:empty {
  display: none;
}

.country-flag {
  width: 46px;
  height: auto;
  max-height: 32px;
  flex: none;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.visit-city {
  display: block;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.2;
}

.visit-country {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.visit-clock {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-tint);
}

.clock-time {
  font-size: 2.375rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.clock-zone {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.disclosure {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.disclosure summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.disclosure summary::-webkit-details-marker {
  display: none;
}

.disclosure-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-muted);
}

.disclosure[open] .disclosure-hint .icon {
  transform: rotate(180deg);
}

.disclosure .kv {
  padding: 4px 14px 14px;
}

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

/* The heading only means something with holidays under it. */
.holidays:has(#holiday_list:empty) {
  display: none;
}

.holiday-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.holiday-list li {
  display: flex;
  gap: var(--space-3);
  font-size: var(--fs-sm);
}

.holiday-date {
  flex: none;
  min-width: 3.4rem;
  font-weight: 700;
  color: var(--label-color);
  font-variant-numeric: tabular-nums;
}

.holiday-name {
  min-width: 0;
}

/* --- overhead ------------------------------------------------------------------ */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.segmented button {
  height: 28px;
  min-width: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--bg-chip);
  color: var(--text-primary);
}

#weather-data:empty,
#air-quality-data:empty,
#sun-data:empty,
#moon-data:empty {
  display: none;
}

.weather-row {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* The Weather Icons files carry no fill of their own; inlined, they take this one and
   follow the theme. */
.weather-icon {
  width: 84px;
  height: 84px;
  flex: none;
  fill: var(--label-color);
}

.weather-temp {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.weather-desc {
  font-size: 1.0625rem;
  color: var(--text-secondary);
}

.weather-wind {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.wind-icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: currentColor;
}

.aq-row,
.sun-row,
.moon-row {
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-color);
}

.aq-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.aq-badge {
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 36px;
  flex: none;
  padding: 0 6px;
  border-radius: 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Official European AQI band colours (EEA). Fixed brand colours, so the text on them is
   fixed too rather than following the theme. */
.aq-good { background: #50f0e6; color: #14342f; }
.aq-fair { background: #50ccaa; color: #10302a; }
.aq-moderate { background: #f0e641; color: #3a3600; }
.aq-poor { background: #ff5050; color: #ffffff; }
.aq-very-poor { background: #960032; color: #ffffff; }
.aq-extreme { background: #7d2181; color: #ffffff; }

.aq-label,
.moon-name {
  font-size: 0.9375rem;
  font-weight: 600;
}

.aq-pollutants,
.moon-meta,
.sun-label,
.sun-daylight {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.sun-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sun-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.sun-icon {
  width: 36px;
  height: 36px;
  flex: none;
  fill: var(--label-color);
}

.sun-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sun-daylight {
  margin-top: 6px;
}

.moon-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.moon-icon {
  width: 40px;
  height: 40px;
  flex: none;
  fill: var(--label-color);
}

/* --- something to smile at ----------------------------------------------------- */

.smile-list {
  display: flex;
  flex-direction: column;
}

.smile-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--space-4) 0;
}

.smile-item:first-child {
  padding-top: var(--space-1);
}

.smile-item + .smile-item {
  border-top: 1px solid var(--border-color);
}

.smile-item:empty {
  display: none;
}

.smile-text {
  line-height: 1.55;
}

/* --- something to look at ------------------------------------------------------ */

.photo {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--bg-tint);
}

/* --- headlines ------------------------------------------------------------------ */

.news-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 40px;
}

.news-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border-color);
}

.news-link {
  color: var(--text-primary);
  font-size: 0.90625rem;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
}

.news-link:hover {
  color: var(--label-color);
  text-decoration: underline;
}

.news-meta {
  font-size: 0.78125rem;
  color: var(--text-muted);
}

/* --- above & below: the globe ----------------------------------------------------- */

.card-head--wrap {
  flex-wrap: wrap;
  align-items: flex-start;
}

.globe-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tool-group {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.tool:hover:not(:disabled) {
  background: var(--bg-chip);
  color: var(--text-primary);
}

.tool[aria-pressed="true"],
.tool[aria-pressed="true"]:hover {
  background: var(--primary-color);
  color: var(--on-primary);
}

.tool:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool .icon {
  width: 16px;
  height: 16px;
}

/* Globe first, its legend directly underneath. */
.globe-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.globe-wrap {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.globe-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.globe-info .layer-list {
  justify-content: center;
}

/* One line under the globe: when the station is next closest to the visitor. */
.iss-eta {
  margin: 0 0 var(--space-2);
  max-width: 440px;
  font-size: var(--fs-sm);
  line-height: 1.5;
  text-align: center;
  color: var(--text-secondary);
}

.iss-eta strong {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

#iss-globe {
  display: block;
  width: 100%;
  /* Square by construction, so the globe never becomes an ellipse in a narrow panel. */
  aspect-ratio: 1;
  cursor: grab;
  /* A drag must spin the globe, not select the page or pan it on a phone. */
  touch-action: none;
  user-select: none;
}

#iss-globe.is-dragging {
  cursor: grabbing;
}

.globe-ocean,
.globe-graticule,
.globe-land,
.globe-rim {
  pointer-events: none;
}

.globe-ocean {
  fill: var(--map-ocean-to);
}

.globe-graticule {
  fill: none;
  stroke: var(--primary-color);
  stroke-width: 0.4;
  opacity: 0.35;
}

.globe-land {
  fill: var(--globe-land-fill);
  stroke: var(--primary-dark);
  stroke-width: 0.9;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.globe-rim {
  fill: none;
  stroke: var(--primary-color);
  stroke-width: 1.5;
}

/* The visitor, when their own location is known and on the near face. White rather than
   a palette colour: the ocean it sits on is the accent colour. */
.globe-viewer {
  fill: #ffffff;
  stroke: var(--primary-dark);
  stroke-width: 1;
}

.globe-iss {
  fill: var(--highlight-color);
  stroke: #ffffff;
  stroke-width: 1;
}

.globe-iss-halo {
  fill: var(--highlight-color);
  opacity: 0.25;
}

/* Semi-transparent so overlapping quakes along a fault line read as a denser cluster
   rather than a single blob. */
.globe-quake {
  fill: var(--quake);
  opacity: 0.7;
}

.globe-night {
  fill: var(--globe-night);
  /* Decoration over the map; let hover reach the markers beneath. */
  pointer-events: none;
}

.globe-sun {
  fill: var(--globe-sun);
  stroke: var(--primary-dark);
  stroke-width: 0.6;
}

.globe-moon {
  fill: var(--globe-moon);
  stroke: var(--primary-dark);
  stroke-width: 0.6;
}

/* Outlines over the map; none should catch the pointer during a drag. */
.globe-plate,
.globe-track,
.globe-link {
  fill: none;
  pointer-events: none;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.globe-plate {
  stroke: var(--globe-plate);
  stroke-width: 0.8;
  opacity: 0.75;
}

.globe-track {
  stroke: var(--globe-track);
  stroke-width: 1.1;
  opacity: 0.85;
}

/* Dashed, so it reads as a sight line rather than as something physically there. */
.globe-link {
  stroke: var(--globe-link);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.9;
}

.globe-aurora {
  fill: var(--globe-aurora);
  opacity: 0.5;
  pointer-events: none;
}

/* Visitor spikes. Not interactive - they would otherwise be one more thing for a drag
   starting on the globe to land on. */
.globe-spike {
  stroke: var(--spike);
  stroke-width: 1.4;
  stroke-linecap: round;
  pointer-events: none;
}

.globe-spike-tip {
  fill: var(--spike);
  pointer-events: none;
}

/* When the station next passes over the visitor. */
.passes {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-color);
}

.pass-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pass {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px var(--space-3);
}

.pass-when {
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pass-detail {
  grid-column: 1 / -1;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.pass-badge {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-chip);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.pass-badge.is-visible {
  background: var(--primary-color);
  color: var(--on-primary);
}

/* Layer switches: chips that read as on or off without relying on colour. */
.layer-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.layer-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  background: var(--bg-chip);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.layer-toggle:hover {
  border-color: var(--label-color);
}

.layer-toggle[aria-pressed="false"] {
  border-style: dashed;
  background: transparent;
  color: var(--text-secondary);
}

.layer-toggle[aria-pressed="false"]::after {
  content: "off";
  font-weight: 400;
  color: var(--text-muted);
}

.layer-toggle[aria-pressed="false"] .legend-dot {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px currentColor;
}

/* While the aurora feed is on its way. */
.layer-toggle.is-loading {
  opacity: 0.6;
  cursor: progress;
}

.legend-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
}

/* Each swatch matches the marker it stands for. */
.legend-iss { background: var(--highlight-color); }
.legend-viewer { background: #ffffff; box-shadow: inset 0 0 0 1px var(--primary-dark); }
.legend-quake { background: var(--quake); }
.legend-sun { background: var(--globe-sun); }
.legend-visitor { background: var(--spike); }
.legend-moon { background: var(--globe-moon); box-shadow: inset 0 0 0 1px var(--primary-dark); }
.legend-plate { background: var(--globe-plate); }
.legend-aurora { background: var(--globe-aurora); }

/* --- narrower screens ----------------------------------------------------------- */

@media (min-width: 721px) {
  /* The photo grows to the height of the cards beside it instead of leaving a gap. */
  .area-photo .photo {
    flex: 1 1 auto;
    height: 0;
    min-height: 220px;
    aspect-ratio: auto;
  }
}

@media (max-width: 1100px) {
  .dash-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "visit weather"
      "globe globe"
      "smile photo"
      "news news";
  }
}

@media (max-width: 720px) {
  .dash {
    padding: var(--space-5) var(--space-4) 40px;
  }

  .dash-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "visit"
      "weather"
      "globe"
      "smile"
      "news"
      "photo";
    gap: var(--space-4);
  }

  .card {
    padding: 18px;
  }

  .news-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .globe-wrap {
    max-width: 320px;
  }

  .tool {
    gap: 4px;
    padding: 0 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body {
    transition: none;
  }
}
