/* First-party overrides for Pico. Keep this file small. */

/* Tells the browser this page handles both schemes natively. Belt-and-
   braces with the <meta name="darkreader-lock"> in base.html: also
   discourages Chrome's "Force Dark Mode for Web Contents" and Safari's
   equivalent from re-tinting our already-themed UI. */
:root {
  color-scheme: light dark;
}

/* Brand prefix shown on secure.<domain>. Pico's blue accent token; Pico
   updates it to the right shade for both light and dark themes, so this
   stays readable without a dark-mode rule. */
.cptv-brand-prefix {
  color: var(--pico-color-blue-500, #0050b8);
}

/* Per-stack ASN / GeoIP rows. When v4 and v6 differ the JS appends
   two <ul>s into these containers; auto-fit grid puts them
   side-by-side when the card is wide enough (~28 rem) and stacks
   them on phone widths. When the JS appends a single merged <ul>
   it just fills the row. */
#geoip-stacks,
#asn-stacks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0 1.5rem;
  align-items: start;
}
#geoip-stacks > ul,
#asn-stacks > ul {
  margin: 0;
}

/* Two-column layout for the Geolocation card: text on the left, OSM
   map on the right. Single column (text on top, map below) on narrow
   viewports — the map is the more bandwidth-heavy element and is the
   first thing to wrap below the fold on phones. */
.cptv-geo-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}
@media (min-width: 48rem) {
  .cptv-geo-layout {
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 22rem);
    align-items: start;
  }
}
#geo-map {
  height: 220px;
  width: 100%;
  border-radius: var(--pico-border-radius, 0.25rem);
  background: var(--pico-muted-border-color, #ddd);
}

/* The request-headers dump in the request-inspection panel can have
   long header values; let them wrap so they don't blow out the card. */
.cptv-headers-dump {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- responsive header (PLAN \u00a74.13 / mobile UX) ---------- */

/* The header is a flex row: brand on the left, controls on the right.
   On narrow viewports the menu hides and the hamburger button surfaces;
   click flips data-open on this <nav> and the menu drops down absolute
   relative to this container. */
.cptv-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: relative;
}
.cptv-brand,
.cptv-brand:hover {
  color: inherit;
  text-decoration: none;
}
.cptv-brand strong {
  margin-right: 0.3rem;
}
/* Hamburger button. Bigger glyph than the previous <summary> version
   because it's a touch target on mobile. */
.cptv-nav-toggle {
  cursor: pointer;
  user-select: none;
  font-size: 1.9rem;
  line-height: 1;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--pico-muted-border-color, #ccc);
  border-radius: 0.4rem;
  color: inherit;
  background: transparent;
  width: auto;
  /* Pico styles <button> as a chunky filled primary button by default;
     reset to a flat outlined hamburger so this looks like a nav toggle. */
  margin: 0;
}
.cptv-nav-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.cptv-nav-menu li {
  margin: 0;
  padding: 0;
}

/* Desktop (>= 721 px): hide the hamburger button, show the inline menu. */
@media (min-width: 721px) {
  .cptv-nav-toggle {
    display: none;
  }
  /* Force the menu to be inline regardless of any data-open state. */
  .cptv-nav-menu {
    display: flex !important;
  }
}

/* Phone + tablet (<= 720 px): show the hamburger; hide the menu until
   the user clicks. The toggle JS flips data-open on the <nav>. */
@media (max-width: 720px) {
  .cptv-nav .cptv-nav-menu {
    display: none;
  }
  .cptv-nav[data-open="true"] .cptv-nav-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    background: var(--pico-card-background-color, #fff);
    border: 1px solid var(--pico-muted-border-color, #ccc);
    border-radius: 0.4rem;
    padding: 0.5rem 0.75rem;
    z-index: 10;
    min-width: 12rem;
  }
}

/* Phone: drop the tagline so the brand line stays one row. */
@media (max-width: 480px) {
  .cptv-brand-tagline {
    display: none;
  }
}

/* The <details> summary lines inside content cards, the geolocation
   request button, and the history clear button are all "click here to
   do a thing" controls. Pico styles <button> as a chunky filled button
   by default; that looks out of place inside the diagnostic cards.
   Restyle them as plain blue underlined links so they read as inline
   actions. The :not() guard excludes the navigation hamburger summary,
   which has its own button-like styling.

   Specificity matters here: Pico ships
   `details summary:not([role])` at (0,2,1) which sets summary color to
   the body text colour. We match that specificity with
   `details summary:not(.cptv-nav-toggle)` so app.css (loaded after
   pico.min.css) wins on cascade order. */
details summary:not(.cptv-nav-toggle),
#request-geolocation,
#history-clear {
  color: var(--pico-primary, #0a4f9c);
  text-decoration: underline;
  text-decoration-color: var(--pico-primary, #0a4f9c);
  text-underline-offset: 0.15em;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
}
details summary:not(.cptv-nav-toggle):hover,
#request-geolocation:hover,
#history-clear:hover {
  text-decoration-thickness: 2px;
}
details summary:not(.cptv-nav-toggle) {
  /* Drop the default disclosure marker; the underlined text is enough. */
  list-style: none;
}
details summary:not(.cptv-nav-toggle)::-webkit-details-marker {
  display: none;
}
/* Pico's `details summary::after` adds a chevron via background-image.
   On these inline link-summaries it just adds noise; hide it. */
details summary:not(.cptv-nav-toggle)::after {
  display: none;
}

/* IP addresses are long (especially IPv6); allow them to wrap mid-string
   so they never blow out the article width on phones. */
code.ip-current,
#dual-stack code,
#captive-portal-section code,
#dns-section code,
#anycast-section code,
#resolver-detected code {
  overflow-wrap: anywhere;
  word-break: break-word;
}

article {
  margin-block: 1rem;
}

article > header {
  padding-block: 0.5rem;
}

#dual-stack ul,
#geoip-section ul,
#asn-section ul,
#quick-links-section ul {
  padding-left: 1.25rem;
}

#clock-skew-warning {
  color: var(--pico-color-amber-500, #c08000);
  font-weight: bold;
}

code.ip-current {
  font-size: 1.25rem;
}

/* ---------- subtle CSS-only animations (PLAN §4.13) ---------- */

/* Fade-in cards on load. Each section gets a tiny stagger so the page
   doesn't pop in all at once. Strictly opacity-only — no layout shifts. */
@keyframes cptv-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

main.container > article {
  animation: cptv-fade-in 0.3s ease-out both;
}

main.container > article:nth-child(2) {
  animation-delay: 0.04s;
}
main.container > article:nth-child(3) {
  animation-delay: 0.08s;
}
main.container > article:nth-child(4) {
  animation-delay: 0.12s;
}
main.container > article:nth-child(5) {
  animation-delay: 0.16s;
}
main.container > article:nth-child(6) {
  animation-delay: 0.2s;
}
main.container > article:nth-child(7) {
  animation-delay: 0.24s;
}

/* Pulse the traceroute status banner while a live trace is in progress.
   Triggered by the JS adding the `is-running` class on the card. */
@keyframes cptv-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.cptv-trace-pane.is-running .cptv-trace-status {
  animation: cptv-pulse 1.4s ease-in-out infinite;
}

/* DNSSEC badge flashes 'validating\u2026' until the probe settles or the
   30-second timeout fires. The .cptv-dnssec-pending class is set
   server-side on initial render so the flash starts immediately;
   checkDnssec() in app.js removes the class once a verdict is known. */
.cptv-dnssec-pending {
  animation: cptv-pulse 1.4s ease-in-out infinite;
}

/* Tab strip for IPv4 / IPv6 traceroute panes. */
.cptv-trace-tabs {
  display: flex;
  gap: 0.4rem;
  border: 0;
  padding: 0;
  margin-block-end: 0.5rem;
}
.cptv-trace-tabs label {
  cursor: pointer;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--pico-muted-border-color, #ccc);
  border-radius: 0.4rem;
  user-select: none;
}
.cptv-trace-tabs label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.cptv-trace-tabs label:has(input:checked) {
  background: var(--pico-primary-background, #0a4f9c);
  color: var(--pico-primary-inverse, #fff);
  border-color: transparent;
}

/* Newly-arrived hop rows briefly highlight so the eye catches updates. */
@keyframes cptv-row-flash {
  from {
    background-color: var(--pico-mark-background-color, #ffe69c);
  }
  to {
    background-color: transparent;
  }
}

.cptv-trace-hops tr.cptv-hop-flash > td {
  animation: cptv-row-flash 0.6s ease-out both;
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  main.container > article,
  .cptv-trace-pane.is-running .cptv-trace-status,
  .cptv-trace-hops tr.cptv-hop-flash > td,
  .cptv-dnssec-pending {
    animation: none !important;
  }
}

/* ---------- responsive traceroute table ---------- */

/* Mid-width fallback: let the table scroll horizontally inside its
   figure if the screen still has room for table-cell layout. Pico
   wraps the table in <figure>; we only need the overflow rule. */
.cptv-trace-pane figure {
  overflow-x: auto;
}

/* Phone-narrow viewports: collapse the 8-column table into a stacked
   card per hop. Each <td> renders as a label/value row using its
   data-label attribute. The <thead> is hidden because the labels move
   onto the cells themselves. */
@media (max-width: 720px) {
  .cptv-trace-pane table,
  .cptv-trace-pane thead,
  .cptv-trace-pane tbody,
  .cptv-trace-pane tr,
  .cptv-trace-pane td {
    display: block;
    width: 100%;
  }

  .cptv-trace-pane thead {
    /* Visually hide but keep accessible to assistive tech. */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .cptv-trace-pane tr {
    border: 1px solid var(--pico-muted-border-color, #ccc);
    border-radius: 0.4rem;
    margin-block: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--pico-card-background-color, transparent);
  }

  /* Hop row layout: number + IP on top, every other cell as a
     "label: value" pair below. */
  .cptv-trace-pane td {
    border: none;
    padding: 0.15rem 0;
    display: grid;
    grid-template-columns: 5.5rem 1fr;
    align-items: baseline;
    column-gap: 0.5rem;
  }

  .cptv-trace-pane td::before {
    content: attr(data-label);
    color: var(--pico-muted-color, #666);
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  /* IP on its own line stays full-width and wraps. */
  .cptv-trace-pane td[data-label="IP"] code {
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  /* Make non-responding hop rows visually distinct. */
  .cptv-trace-pane tr.hop-no-reply {
    opacity: 0.7;
  }

  /* Smaller IP heading on cramped screens. */
  code.ip-current {
    font-size: 1.05rem;
  }

  /* Trim card chrome so we don't waste horizontal space. */
  main.container > article {
    padding-inline: 0.75rem;
  }
}
