/*
 * Gauss Algorithmic monitoring overview.
 *
 * Brand palette lives in `--ga-*` tokens; the semantic `--surface`/`--text`/...
 * tokens are what components reference, and they are the only thing the dark
 * theme redefines.
 *
 * Per-card accents come from `--service-color` / `--service-contrast`, which
 * `app.js` sets from the catalogue after validating the hex value.
 */

:root {
  /* Brand palette - teal */
  --ga-teal: #27bfb4;
  --ga-teal-light: #bdede9;
  --ga-teal-50: #f1fcfa;
  --ga-teal-100: #cef9f2;
  --ga-teal-200: #9df2e5;
  --ga-teal-400: #34cdc0;
  --ga-logo-teal: #00a79d;

  /* Brand palette - navy */
  --ga-navy: #1b2974;
  --ga-navy-dark: #081556;
  --ga-navy-50: #eef0f9;
  --ga-navy-100: #d5d9f0;
  --ga-navy-400: #5560b8;
  --ga-navy-600: #2a3a88;
  --ga-navy-800: #111a5e;

  /* Brand palette - neutrals */
  --ga-bg-light: #f6f7fb;
  --ga-bg-green: #f3fbfb;
  --ga-text-grey: #656e8c;
  --ga-text-primary: #0f172a;
  --ga-border: #cbd5e1;
  --ga-border-light: #e2e8f0;

  /* Semantic tokens - light theme */
  --bg: var(--ga-bg-light);
  --bg-accent: var(--ga-bg-green);
  --surface: #ffffff;
  --surface-hover: var(--ga-teal-50);
  --text: var(--ga-text-primary);
  --text-muted: var(--ga-text-grey);
  --heading: var(--ga-navy);
  --accent: var(--ga-teal);
  --accent-strong: var(--ga-logo-teal);
  --border: var(--ga-border-light);
  --border-strong: var(--ga-border);
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 8px 24px rgb(15 23 42 / 6%);
  --shadow-hover: 0 2px 6px rgb(15 23 42 / 8%), 0 18px 38px rgb(15 23 42 / 12%);

  /* Soft mesh laid over the flat page background. */
  --mesh-a: rgb(39 191 180 / 10%);
  --mesh-b: rgb(85 96 184 / 8%);

  /*
   * Per-card accent treatment. `--service-tint` fills the icon tile,
   * `--chip-tint` the link chips, and `--service-lighten` blends white into
   * the stroke/text so a saturated brand colour stays legible on dark navy.
   */
  --service-tint: 16%;
  --chip-tint: 12%;
  --service-lighten: 0%;

  /*
   * Status colours. The vivid `--status-*` value carries the dot and the tints;
   * the darker `--status-*-ink` keeps the small pill label above 4.5:1.
   */
  --status-up: #16a34a;
  --status-up-ink: #0b6b2f;
  --status-down: #e0523f;
  --status-down-ink: #a8331f;
  --status-unknown: #94a3b8;
  --status-unknown-ink: #5a6474;

  --radius: 16px;
  --radius-sm: 12px;
  --radius-icon: 14px;
  --max-width: 1120px;

  /* Hero band - identical in both themes, so the values are literal. */
  --hero-ink: #ffffff;
  --hero-fill: rgb(255 255 255 / 12%);
  --hero-fill-hover: rgb(255 255 255 / 20%);
  --hero-line: rgb(255 255 255 / 22%);
  --hero-up: #4ade80;
  --hero-down: #ff8a7a;
  --hero-unknown: #b6bde0;
}

/* System dark mode, only while the user has not explicitly chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--ga-navy-dark);
    --bg-accent: #0c1a63;
    --surface: var(--ga-navy-800);
    --surface-hover: #17226e;
    --text: #e8ebf7;
    --text-muted: #a8b0d4;
    --heading: #ffffff;
    --accent: var(--ga-teal-400);
    --accent-strong: var(--ga-teal-200);
    --border: #24306f;
    --border-strong: #2f3c85;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 24%);
    --shadow-hover: 0 2px 6px rgb(0 0 0 / 36%), 0 18px 38px rgb(0 0 0 / 34%);

    --mesh-a: rgb(39 191 180 / 16%);
    --mesh-b: rgb(85 96 184 / 20%);

    --service-tint: 24%;
    --chip-tint: 20%;
    --service-lighten: 32%;

    --status-up: #4ade80;
    --status-up-ink: #4ade80;
    --status-down: #ff8a7a;
    --status-down-ink: #ff8a7a;
    --status-unknown: #8b93b8;
    --status-unknown-ink: #a8b0d4;
  }
}

/* Explicit dark choice always wins over the media query. */
:root[data-theme="dark"] {
  --bg: var(--ga-navy-dark);
  --bg-accent: #0c1a63;
  --surface: var(--ga-navy-800);
  --surface-hover: #17226e;
  --text: #e8ebf7;
  --text-muted: #a8b0d4;
  --heading: #ffffff;
  --accent: var(--ga-teal-400);
  --accent-strong: var(--ga-teal-200);
  --border: #24306f;
  --border-strong: #2f3c85;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 24%);
  --shadow-hover: 0 2px 6px rgb(0 0 0 / 36%), 0 18px 38px rgb(0 0 0 / 34%);

  --mesh-a: rgb(39 191 180 / 16%);
  --mesh-b: rgb(85 96 184 / 20%);

  --service-tint: 24%;
  --chip-tint: 20%;
  --service-lighten: 32%;

  --status-up: #4ade80;
  --status-up-ink: #4ade80;
  --status-down: #ff8a7a;
  --status-down-ink: #ff8a7a;
  --status-unknown: #8b93b8;
  --status-unknown-ink: #a8b0d4;
}

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

html {
  color-scheme: light dark;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image: radial-gradient(at 15% 0%, var(--mesh-a), transparent 40%),
    radial-gradient(at 100% 100%, var(--mesh-b), transparent 45%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-strong);
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.5rem 1rem;
  background: var(--surface);
  z-index: 10;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* ---------- Hero ---------- */

/* Always navy, in both themes: this band is the brand, not part of the palette. */
.hero {
  position: relative;
  overflow: hidden;
  color: var(--hero-ink);
  background-color: var(--ga-navy-dark);
  background-image: radial-gradient(
      circle at 85% 20%,
      rgb(39 191 180 / 35%),
      transparent 55%
    ),
    linear-gradient(135deg, #081556 0%, #1b2974 60%, #2a3a88 100%);
}

.hero__curve {
  position: absolute;
  right: 2.5%;
  /* Seated on the band's edge: sized off its height so the peak is never
     clipped, and the curve's own tails land on the bottom border. */
  bottom: 0;
  height: 88%;
  width: auto;
  color: var(--ga-teal);
  opacity: 0.18;
  pointer-events: none;
}

.hero__inner {
  position: relative;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.6rem 1.25rem 1.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.1rem 1.5rem;
}

.hero__brand {
  min-width: 0;
}

.hero__wordmark {
  display: block;
  height: 44px;
  width: auto;
}

.hero__title {
  margin: 0.55rem 0 0;
  font-size: clamp(1.5rem, 1.15rem + 1.3vw, 1.9rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.015em;
  color: var(--hero-ink);
}

.hero__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ---------- Hero status summary ---------- */

.summary {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--hero-ink);
  background: var(--hero-fill);
  border: 1px solid var(--hero-line);
  border-radius: 999px;
}

.summary__dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--hero-unknown);
}

.summary--up .summary__dot {
  background: var(--hero-up);
  animation: ga-hero-pulse 2.2s ease-out infinite;
}

.summary--down .summary__dot {
  background: var(--hero-down);
}

.summary__count {
  padding: 0.05rem 0.45rem;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  background: rgb(255 255 255 / 16%);
  border-radius: 999px;
}

@keyframes ga-hero-pulse {
  0% {
    box-shadow: 0 0 0 0 rgb(74 222 128 / 55%);
  }
  70% {
    box-shadow: 0 0 0 7px rgb(74 222 128 / 0%);
  }
  100% {
    box-shadow: 0 0 0 0 rgb(74 222 128 / 0%);
  }
}

.theme-toggle {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--hero-ink);
  background: var(--hero-fill);
  border: 1px solid var(--hero-line);
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  background: var(--hero-fill-hover);
  border-color: rgb(255 255 255 / 40%);
}

/* ---------- Layout ---------- */

.main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.25rem 2.5rem;
}

/* ---------- Section rows ---------- */

.sections {
  display: flex;
  flex-direction: column;
}

/* Label column on the left, tiles on the right, both anchored to the row top. */
.section {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5rem;
  align-items: start;
  padding-block: 1.6rem;
}

.section:first-child {
  padding-top: 0;
}

.section:last-child {
  padding-bottom: 0;
}

.section + .section {
  border-top: 1px solid var(--border);
}

.section__title {
  position: relative;
  margin: 0;
  /* Optical nudge so the label sits level with the tile's icon, not its border. */
  padding: 0.2rem 0 0.7rem;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--heading);
}

.section__title::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 28px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
}

/*
 * `auto-fill` (not `auto-fit`) keeps the empty tracks, so a section holding a
 * single tile renders it at the same width as the tiles in a fuller row.
 * `min()` keeps a single column from overflowing narrow phones.
 */
.section__tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
  gap: 1.1rem;
}

/* ---------- Card ---------- */

.card {
  /* Overridden per card by `app.js` once the catalogue colour is validated. */
  --service-color: var(--ga-teal);
  --service-contrast: #ffffff;

  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.3rem 1.15rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
  /* `backwards` (not `both`) so the finished animation stops shadowing :hover. */
  animation: ga-card-in 0.42s ease-out backwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}

/* Accent bar; clipped to the card radius by the card's own `overflow: hidden`. */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--service-color);
}

.card--down {
  border-color: color-mix(in srgb, var(--status-down) 45%, var(--border));
}

.card:hover,
.card:focus-within {
  border-color: var(--service-color);
  box-shadow: var(--shadow-hover);
  transform: translateY(-3px);
}

@keyframes ga-card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.card__icon {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-icon);
  background: color-mix(in srgb, var(--service-color) var(--service-tint), transparent);
  color: color-mix(in srgb, var(--service-color), white var(--service-lighten));
}

.card__icon svg {
  display: block;
  width: 24px;
  height: 24px;
}

.card__body {
  /*
   * Auto block margins centre the name in whatever height the row settles on,
   * so a card with no chips splits the slack above and below it instead of
   * trailing one large void.
   */
  margin-block: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.card__name {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.card__link {
  color: var(--heading);
  text-decoration: none;
}

/* Stretched link: the whole card is one click target, with no nested anchors. */
.card__link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card:hover .card__link,
.card__link:focus-visible {
  color: var(--accent-strong);
}

/* ---------- Card chips ---------- */

.card__chips {
  margin: auto 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.card__chip {
  /* Lifted above the stretched link so a chip keeps its own target. */
  position: relative;
  z-index: 1;
  display: inline-block;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  /* A chip is a pill: it may wrap to the next line, never mid-label. */
  white-space: nowrap;
  border-radius: 999px;
  background: color-mix(in srgb, var(--service-color) var(--chip-tint), transparent);
  color: color-mix(in srgb, var(--service-color), white var(--service-lighten));
  transition: background-color 0.15s ease, color 0.15s ease;
}

.card__chip:hover {
  /* `--service-contrast` is picked by luminance in `app.js`, so this stays legible. */
  background: var(--service-color);
  color: var(--service-contrast);
}

/* ---------- Status pill ---------- */

.card__status {
  /* Also above the stretched link, so its diagnostic tooltip stays reachable. */
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  border-radius: 999px;
  color: var(--status-unknown-ink);
  background: color-mix(in srgb, var(--status-unknown) 14%, transparent);
  cursor: default;
}

.card__status--up {
  color: var(--status-up-ink);
  background: color-mix(in srgb, var(--status-up) 14%, transparent);
}

.card__status--down {
  color: var(--status-down-ink);
  background: color-mix(in srgb, var(--status-down) 14%, transparent);
}

.dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-unknown);
}

.dot--up {
  background: var(--status-up);
  animation: ga-dot-pulse 2.2s ease-out infinite;
}

.dot--down {
  background: var(--status-down);
}

.dot--unknown {
  background: var(--status-unknown);
}

@keyframes ga-dot-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-up) 50%, transparent);
  }
  70% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--status-up) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-up) 0%, transparent);
  }
}

/* ---------- Banner ---------- */

.banner {
  margin: 0 0 1.4rem;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--status-down-ink);
  background: color-mix(in srgb, var(--status-down) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--status-down) 35%, transparent);
  border-radius: var(--radius-sm);
}

/* ---------- Footer ---------- */

.footer {
  flex: 0 0 auto;
}

.footer__text {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem 1.6rem;
  font-size: 0.8rem;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Narrow screens ---------- */

@media (max-width: 720px) {
  .section {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }
}

@media (max-width: 640px) {
  .hero__curve {
    display: none;
  }

  .hero__wordmark {
    height: 34px;
  }

  .hero__inner {
    align-items: flex-start;
  }
}

@media (max-width: 420px) {
  .hero__inner,
  .main,
  .footer__text {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .card {
    padding: 1.2rem 1rem 1rem;
  }
}

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

  .card:hover,
  .card:focus-within {
    transform: none;
  }
}
