/* ============================================================================
   Connectivity Investigation Dashboard — stylesheet
   ----------------------------------------------------------------------------
   Contents
     1.  Design tokens (light + dark)
     2.  Base / reset
     3.  Utilities
     4.  Top bar & brand
     5.  Buttons, chips, selects, inputs
     6.  Layout & sections
     7.  Cards, stats, meta grid, verdict
     8.  Charts
     9.  Timeline
     10. Toolbar (search / filters / sort)
     11. Server cards
     12. Code panels (line numbers + syntax colours)
     13. Warnings, empty & loading states
     14. Toast
     15. Footer
     16. Motion preferences
     17. Print styles (A4)
   ========================================================================== */


/* ============================================================================
   1. Design tokens
   ========================================================================== */

:root {
  /* --- Neutral surfaces (GitHub / Cloudflare style light palette) --- */
  --bg:              #f2f4f7;
  --bg-elevated:     #ffffff;
  --surface:         #ffffff;
  --surface-subtle:  #f6f8fa;
  --surface-inset:   #f0f3f6;
  --code-bg:         #f8fafc;
  --code-gutter-bg:  #f1f4f8;

  /* --- Lines --- */
  --border:          #d8dee6;
  --border-strong:   #c2cad4;
  --border-subtle:   #e6eaf0;

  /* --- Text --- */
  --text:            #10161c;
  --text-secondary:  #4a5560;
  --text-muted:      #6b7684;
  --text-inverse:    #ffffff;

  /* --- Accent --- */
  --accent:          #0b62d6;
  --accent-hover:    #0a56bd;
  --accent-soft:     rgba(11, 98, 214, 0.10);
  --accent-ring:     rgba(11, 98, 214, 0.36);

  /* --- Semantic status colours --- */
  --success:         #10783a;
  --success-soft:    rgba(26, 127, 55, 0.12);
  --info:            #0b62d6;
  --info-soft:       rgba(11, 98, 214, 0.12);
  --warning:         #a84a00;
  --warning-soft:    rgba(188, 76, 0, 0.13);
  --danger:          #c0202c;
  --danger-soft:     rgba(207, 34, 46, 0.12);
  --neutral:         #5c6773;
  --neutral-soft:    rgba(92, 103, 115, 0.12);

  /* --- Code token colours --- */
  --tok-comment:     #6b7684;
  --tok-key:         #7c3aed;
  --tok-string:      #0a6b52;
  --tok-number:      #0b62d6;
  --tok-ip:          #a1560a;
  --tok-host:        #0f766e;
  --tok-error:       #c0202c;
  --tok-ok:          #10783a;
  --tok-out:         #7c3aed;
  --tok-in:          #0b62d6;
  --tok-dim:         #98a2b0;

  /* --- Elevation --- */
  --shadow-sm:  0 1px 2px rgba(16, 22, 28, 0.05), 0 1px 1px rgba(16, 22, 28, 0.04);
  --shadow-md:  0 2px 4px rgba(16, 22, 28, 0.05), 0 6px 16px rgba(16, 22, 28, 0.06);
  --shadow-lg:  0 8px 28px rgba(16, 22, 28, 0.12);

  /* --- Geometry --- */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;
  --radius-pill: 999px;

  /* --- Type --- */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans",
               Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo,
               Consolas, "Liberation Mono", monospace;

  /* --- Rhythm --- */
  --page-max:   1320px;
  --gap-xs:  6px;
  --gap-sm:  10px;
  --gap-md:  16px;
  --gap-lg:  24px;
  --gap-xl:  36px;

  color-scheme: light;
}

/*  Dark palette — applied automatically when the OS prefers dark and the user
    has not overridden the theme. The identical token block is repeated below
    for the explicit `data-theme="dark"` override; keep the two in sync.        */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg:              #0b0f14;
    --bg-elevated:     #131920;
    --surface:         #151b23;
    --surface-subtle:  #1a212a;
    --surface-inset:   #10161d;
    --code-bg:         #0e141b;
    --code-gutter-bg:  #131a22;

    --border:          #2e3742;
    --border-strong:   #3d4854;
    --border-subtle:   #232b34;

    --text:            #e8eef6;
    --text-secondary:  #aeb9c6;
    --text-muted:      #8b96a4;
    --text-inverse:    #0b0f14;

    --accent:          #4d9dff;
    --accent-hover:    #6fb0ff;
    --accent-soft:     rgba(77, 157, 255, 0.14);
    --accent-ring:     rgba(77, 157, 255, 0.42);

    --success:         #4ec97a;
    --success-soft:    rgba(63, 185, 80, 0.16);
    --info:            #4d9dff;
    --info-soft:       rgba(77, 157, 255, 0.16);
    --warning:         #e8974a;
    --warning-soft:    rgba(219, 109, 40, 0.18);
    --danger:          #ff6b63;
    --danger-soft:     rgba(248, 81, 73, 0.16);
    --neutral:         #9aa5b3;
    --neutral-soft:    rgba(154, 165, 179, 0.14);

    --tok-comment:     #8b96a4;
    --tok-key:         #c792ea;
    --tok-string:      #7ee0b8;
    --tok-number:      #79b8ff;
    --tok-ip:          #f0b072;
    --tok-host:        #5ad0c0;
    --tok-error:       #ff6b63;
    --tok-ok:          #4ec97a;
    --tok-out:         #c792ea;
    --tok-in:          #79b8ff;
    --tok-dim:         #5d6875;

    --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md:  0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg:  0 12px 34px rgba(0, 0, 0, 0.55);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:              #0b0f14;
  --bg-elevated:     #131920;
  --surface:         #151b23;
  --surface-subtle:  #1a212a;
  --surface-inset:   #10161d;
  --code-bg:         #0e141b;
  --code-gutter-bg:  #131a22;

  --border:          #2e3742;
  --border-strong:   #3d4854;
  --border-subtle:   #232b34;

  --text:            #e8eef6;
  --text-secondary:  #aeb9c6;
  --text-muted:      #8b96a4;
  --text-inverse:    #0b0f14;

  --accent:          #4d9dff;
  --accent-hover:    #6fb0ff;
  --accent-soft:     rgba(77, 157, 255, 0.14);
  --accent-ring:     rgba(77, 157, 255, 0.42);

  --success:         #4ec97a;
  --success-soft:    rgba(63, 185, 80, 0.16);
  --info:            #4d9dff;
  --info-soft:       rgba(77, 157, 255, 0.16);
  --warning:         #e8974a;
  --warning-soft:    rgba(219, 109, 40, 0.18);
  --danger:          #ff6b63;
  --danger-soft:     rgba(248, 81, 73, 0.16);
  --neutral:         #9aa5b3;
  --neutral-soft:    rgba(154, 165, 179, 0.14);

  --tok-comment:     #8b96a4;
  --tok-key:         #c792ea;
  --tok-string:      #7ee0b8;
  --tok-number:      #79b8ff;
  --tok-ip:          #f0b072;
  --tok-host:        #5ad0c0;
  --tok-error:       #ff6b63;
  --tok-ok:          #4ec97a;
  --tok-out:         #c792ea;
  --tok-in:          #79b8ff;
  --tok-dim:         #5d6875;

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md:  0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg:  0 12px 34px rgba(0, 0, 0, 0.55);

  color-scheme: dark;
}


/* ============================================================================
   2. Base
   ========================================================================== */

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

/* Several components below set `display`, which would otherwise out-specify the
   user-agent rule for the `hidden` attribute and leave them on screen. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "cv02", "cv03", "cv04", "tnum" 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.011em;
  font-weight: 650;
}

p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, kbd { font-family: var(--font-mono); }

code {
  font-size: 0.88em;
  background: var(--surface-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.36em;
}

canvas { max-width: 100%; }

/* A single, consistent focus ring everywhere. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-soft); }


/* ============================================================================
   3. Utilities
   ========================================================================== */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: top 0.18s ease;
}
.skip-link:focus { top: 12px; text-decoration: none; }

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  display: block;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 7px;
  vertical-align: 1px;
}
.dot--success { background: var(--success); }
.dot--info    { background: var(--info); }
.dot--warning { background: var(--warning); }
.dot--server,
.dot--danger  { background: var(--danger); }
.dot--neutral { background: var(--neutral); }


/* ============================================================================
   4. Top bar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-md);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand__mark {
  width: 36px; height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #7c3aed));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand__mark svg { width: 20px; height: 20px; }

.brand__text { display: flex; flex-direction: column; min-width: 0; }

.brand__title {
  font-size: 15px;
  font-weight: 660;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand__subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  flex: none;
}


/* ============================================================================
   5. Controls: buttons, chips, inputs, selects
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1;
  padding: 8px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease,
              transform 0.12s ease, box-shadow 0.16s ease, color 0.16s ease;
}
.btn:hover {
  background: var(--surface-subtle);
  border-color: var(--border-strong);
}
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { background: var(--accent-hover); border-color: transparent; }

.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--surface-subtle); }

.btn--sm { padding: 6px 10px; font-size: 12.5px; }

.btn--icon {
  padding: 8px;
  width: 34px;
  height: 34px;
}

/* Theme toggle swaps its glyph with the resolved theme. */
.theme-toggle .icon--moon { display: none; }
:root[data-resolved="dark"] .theme-toggle .icon--sun  { display: none; }
:root[data-resolved="dark"] .theme-toggle .icon--moon { display: block; }

.chip {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease,
              border-color 0.16s ease, transform 0.12s ease;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip:active { transform: translateY(1px); }

.chip.is-active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.chip__count {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-inset);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}
.chip.is-active .chip__count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  border-color: transparent;
}
.chip[data-empty="true"]:not(.is-active) { opacity: 0.5; }

.select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.select__label {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-muted);
}
.select__control {
  font: inherit;
  font-size: 13px;
  padding: 7px 30px 7px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7684' d='M4.2 6.3a.75.75 0 0 1 1.06 0L8 9.05l2.74-2.75a.75.75 0 1 1 1.06 1.06L8.53 10.6a.75.75 0 0 1-1.06 0L4.2 7.36a.75.75 0 0 1 0-1.06Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 15px;
  transition: border-color 0.16s ease;
}
.select__control:hover { border-color: var(--border-strong); }


/* ============================================================================
   6. Layout
   ========================================================================== */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.section { margin-bottom: var(--gap-xl); }

.section__head { margin-bottom: var(--gap-md); }

.section__title {
  font-size: 19px;
  font-weight: 660;
  letter-spacing: -0.015em;
}
#overview-heading { font-size: 24px; }

.section__desc {
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 76ch;
}


/* ============================================================================
   7. Cards, stats, meta, verdict
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* --- Investigation meta ------------------------------------------------- */

.meta-card { padding: 20px 22px; margin-bottom: var(--gap-md); }

.meta-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px 26px;
}

.meta-item { min-width: 0; }
.meta-item--wide { grid-column: span 2; }

.meta-item dt {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.meta-item dd {
  margin: 0;
  font-size: 14.5px;
  font-weight: 560;
  color: var(--text);
  overflow-wrap: anywhere;
}

.meta-link { font-weight: 560; }

.flag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}
.flag-list span { white-space: nowrap; }

/* --- Big stat cards ----------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
}

.stat {
  position: relative;
  padding: 18px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--neutral);
}
.stat[data-tone="danger"]::before  { background: var(--danger); }
.stat[data-tone="warning"]::before { background: var(--warning); }
.stat[data-tone="info"]::before    { background: var(--info); }
.stat[data-tone="success"]::before { background: var(--success); }

.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.stat__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat__value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat[data-tone="danger"]  .stat__value { color: var(--danger); }
.stat[data-tone="warning"] .stat__value { color: var(--warning); }
.stat[data-tone="info"]    .stat__value { color: var(--info); }

.stat__hint { font-size: 12.5px; color: var(--text-muted); }

/* --- Verdict banner ----------------------------------------------------- */

.verdict {
  display: flex;
  gap: 14px;
  padding: 18px 20px;
  border-left: 3px solid var(--danger);
  background: linear-gradient(90deg, var(--danger-soft), transparent 60%), var(--surface);
}
.verdict[data-tone="ok"] {
  border-left-color: var(--success);
  background: linear-gradient(90deg, var(--success-soft), transparent 60%), var(--surface);
}
.verdict[data-tone="warn"] {
  border-left-color: var(--warning);
  background: linear-gradient(90deg, var(--warning-soft), transparent 60%), var(--surface);
}

.verdict__icon {
  flex: none;
  color: var(--danger);
  margin-top: 1px;
}
.verdict[data-tone="ok"]   .verdict__icon { color: var(--success); }
.verdict[data-tone="warn"] .verdict__icon { color: var(--warning); }
.verdict__icon svg { width: 20px; height: 20px; display: block; }

.verdict__title { font-size: 15px; margin-bottom: 3px; }
.verdict__text  { font-size: 14px; color: var(--text-secondary); max-width: 92ch; }


/* ============================================================================
   8. Charts
   ========================================================================== */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--gap-md);
}

.chart-card { padding: 18px 20px 14px; }

.chart-card__title {
  font-size: 13.5px;
  font-weight: 620;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.chart-card__canvas {
  position: relative;
  height: 258px;
}

.chart-fallback {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}


/* ============================================================================
   9. Timeline
   ========================================================================== */

.timeline-card { padding: 20px 22px; }

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 22px;
  position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
  border-radius: 2px;
}

.timeline__item {
  position: relative;
  padding: 8px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 14px;
}
.timeline__item::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 15px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--neutral);
}
.timeline__item[data-tone="success"]::before { border-color: var(--success); }
.timeline__item[data-tone="info"]::before    { border-color: var(--info); }
.timeline__item[data-tone="warning"]::before { border-color: var(--warning); }
.timeline__item[data-tone="danger"]::before  { border-color: var(--danger); }

.timeline__time {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 168px;
}

.timeline__host {
  font-weight: 570;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.timeline__meta { font-size: 12.5px; color: var(--text-muted); }


/* ============================================================================
   10. Toolbar
   ========================================================================== */

.toolbar { padding: 14px 16px; }

.toolbar__row {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  flex-wrap: wrap;
}
.toolbar__row--filters {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  justify-content: space-between;
}

.toolbar__right {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  flex-wrap: wrap;
}

.search {
  position: relative;
  flex: 1 1 320px;
  min-width: 240px;
  display: flex;
  align-items: center;
}
.search__icon {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  pointer-events: none;
}
.search__input {
  font: inherit;
  font-size: 14px;
  width: 100%;
  padding: 9px 36px 9px 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--text);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
.search__input::placeholder { color: var(--text-muted); }
.search__input:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  outline: none;
}
.search__input::-webkit-search-cancel-button { display: none; }

.search__clear {
  position: absolute;
  right: 7px;
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.search__clear:hover { background: var(--surface-subtle); color: var(--text); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-count {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}


/* ============================================================================
   11. Server cards
   ========================================================================== */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(430px, 1fr));
  gap: var(--gap-md);
  align-items: start;
}
@media (max-width: 560px) {
  .card-grid { grid-template-columns: 1fr; }
}

.server-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: card-in 0.42s cubic-bezier(0.22, 0.85, 0.3, 1) both;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.server-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.server-card.is-open { box-shadow: var(--shadow-md); }

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

/* --- Header ------------------------------------------------------------- */

.server-card__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 12px;
}

.server-card__flag {
  font-size: 26px;
  line-height: 1.1;
  flex: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
}

.server-card__ident { flex: 1 1 auto; min-width: 0; }

.server-card__name {
  font-size: 15.5px;
  font-weight: 640;
  overflow-wrap: anywhere;
}

.server-card__sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

/* --- Status badge ------------------------------------------------------- */

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 640;
  letter-spacing: 0.01em;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge--success { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.badge--info    { color: var(--info);    background: var(--info-soft);    border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.badge--warning { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 32%, transparent); }
.badge--danger  { color: var(--danger);  background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 32%, transparent); }
.badge--neutral { color: var(--neutral); background: var(--neutral-soft); border-color: color-mix(in srgb, var(--neutral) 30%, transparent); }

/* --- Facts table -------------------------------------------------------- */

.server-card__facts {
  margin: 0;
  padding: 0 18px 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
}

.fact { min-width: 0; }
.fact--wide { grid-column: 1 / -1; }

.fact__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.fact__value {
  margin: 1px 0 0;
  font-size: 13.5px;
  font-weight: 540;
  overflow-wrap: anywhere;
}
.fact__value--mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: -0.01em;
}

/* --- Detected-signal pills --------------------------------------------- */

.signals {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 14px;
}

.signal {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 570;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--surface-inset);
  color: var(--text-secondary);
}
.signal--ok   { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 24%, transparent); }
.signal--bad  { color: var(--danger);  background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 24%, transparent); }
.signal--warn { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 26%, transparent); }
.signal__glyph { font-weight: 700; }

/* --- Actions ------------------------------------------------------------ */

.server-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-subtle);
}

/* --- Expandable details ------------------------------------------------- */

/* `grid-template-rows: 0fr -> 1fr` animates height without a fixed max. */
.server-card__details {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.32s cubic-bezier(0.3, 0.9, 0.3, 1);
  border-top: 0 solid var(--border-subtle);
}
.server-card.is-open .server-card__details {
  grid-template-rows: 1fr;
  border-top-width: 1px;
}

.server-card__details-inner {
  overflow: hidden;
  min-height: 0;
}

.details-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.details-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 2px;
}


/* ============================================================================
   12. Code panels
   ========================================================================== */

.code-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--code-bg);
  overflow: hidden;
}

.code-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-subtle);
}

.code-panel__title {
  font-size: 12.5px;
  font-weight: 620;
  color: var(--text-secondary);
  letter-spacing: 0.005em;
}

.code-panel__cmd {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-panel__spacer { flex: 1 1 auto; }

.code-panel__copy {
  font: inherit;
  font-size: 11.5px;
  font-weight: 560;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  flex: none;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.code-panel__copy:hover { background: var(--surface-inset); color: var(--text); border-color: var(--border-strong); }
.code-panel__copy[data-copied="true"] { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }

/* Gutter stays put while the code itself scrolls horizontally. */
.code-body {
  display: flex;
  align-items: stretch;
  max-height: 380px;
  overflow-y: auto;
}

.code-gutter {
  flex: none;
  padding: 10px 10px 10px 12px;
  text-align: right;
  background: var(--code-gutter-bg);
  border-right: 1px solid var(--border-subtle);
  color: var(--tok-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  font-variant-numeric: tabular-nums;
  user-select: none;
  -webkit-user-select: none;
}
/* The gutter's <pre> must inherit metrics exactly or the numbers drift out of
   alignment with the code beside them. */
.code-gutter pre {
  margin: 0;
  font: inherit;
  color: inherit;
}

.code-scroll {
  flex: 1 1 auto;
  overflow-x: auto;
  min-width: 0;
}

.code-scroll pre {
  margin: 0;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre;
  tab-size: 4;
  color: var(--text-secondary);
}

.code-line { display: block; min-height: 1.65em; }

/* Line-level tones */
.ln-info    { color: var(--tok-comment); }
.ln-out     { color: var(--tok-out); }
.ln-in      { color: var(--tok-in); }
.ln-data    { color: var(--tok-dim); }
.ln-dim     { color: var(--tok-dim); }
.ln-error   { color: var(--tok-error); font-weight: 600; }
.ln-ok      { color: var(--tok-ok); }
.ln-status  { color: var(--text); font-weight: 650; }

/* Inline token tones */
.tok-key     { color: var(--tok-key); }
.tok-string  { color: var(--tok-string); }
.tok-num     { color: var(--tok-number); }
.tok-ip      { color: var(--tok-ip); font-weight: 560; }
.tok-host    { color: var(--tok-host); }
.tok-err     { color: var(--tok-error); font-weight: 650; }
.tok-ok      { color: var(--tok-ok); font-weight: 600; }
.tok-warn    { color: var(--warning); font-weight: 600; }
.tok-code2xx { color: var(--success); font-weight: 700; }
.tok-code3xx { color: var(--info);    font-weight: 700; }
.tok-code4xx { color: var(--warning); font-weight: 700; }
.tok-code5xx { color: var(--danger);  font-weight: 700; }

.code-empty {
  padding: 14px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-style: italic;
}


/* ============================================================================
   13. Warnings, empty & loading states
   ========================================================================== */

.warning-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--gap-md);
}

.warning-card {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--warning) 42%, var(--border));
  background: linear-gradient(90deg, var(--warning-soft), transparent 70%), var(--surface);
  box-shadow: var(--shadow-sm);
}

.warning-card__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 640;
  color: var(--warning);
  margin-bottom: 5px;
}

.warning-card__file {
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
  margin-bottom: 4px;
}

.warning-card__msg { font-size: 12.5px; color: var(--text-muted); overflow-wrap: anywhere; }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 90px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.fatal-error {
  max-width: 720px;
  margin: 56px auto;
  padding: 26px 28px;
  border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.fatal-error__title { font-size: 17px; color: var(--danger); margin-bottom: 10px; }
.fatal-error__message { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 14px; overflow-wrap: anywhere; }
.fatal-error__hint { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 10px; }
.fatal-error__code {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
  font-size: 12.5px;
  overflow-x: auto;
}

.empty-state {
  text-align: center;
  padding: 56px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty-state__title { font-size: 15px; font-weight: 620; }
.empty-state__text { font-size: 13.5px; color: var(--text-muted); margin: 6px 0 16px; }


/* ============================================================================
   14. Toast
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 14px);
  z-index: 90;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--bg-elevated);
  font-size: 13px;
  font-weight: 560;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }


/* ============================================================================
   15. Footer
   ========================================================================== */

.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 22px 24px 34px;
}
.footer p {
  max-width: var(--page-max);
  margin: 0 auto;
  font-size: 12.5px;
  color: var(--text-muted);
}


/* ============================================================================
   16. Responsive tweaks
   ========================================================================== */

@media (max-width: 760px) {
  .topbar__inner { padding: 10px 14px; }
  .topbar__actions .btn span { display: none; }
  .topbar__actions .btn { padding: 8px; width: 34px; height: 34px; }
  .page { padding: 20px 14px 48px; }
  .meta-item--wide { grid-column: 1 / -1; }
  .timeline__time { min-width: 100%; }
  .result-count { margin-left: 0; width: 100%; }
}

@media (max-width: 430px) {
  /* Two fact columns get too cramped for long ASN and ISP values. */
  .server-card__facts { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .meta-grid { grid-template-columns: 1fr; }
  .meta-item--wide { grid-column: auto; }
}


/* ============================================================================
   17. Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}


/* ============================================================================
   18. Print — A4, evidence-grade
   ========================================================================== */

@page {
  size: A4;
  margin: 14mm 12mm;
}

@media print {
  :root {
    /* Force the light palette so printed output stays legible. */
    --bg: #fff;
    --bg-elevated: #fff;
    --surface: #fff;
    --surface-subtle: #fff;
    --surface-inset: #fff;
    --code-bg: #fff;
    --code-gutter-bg: #fff;
    --border: #b9c1cb;
    --border-subtle: #d5dbe2;
    --border-strong: #98a2ae;
    --text: #000;
    --text-secondary: #23292f;
    --text-muted: #4b535c;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
    color-scheme: light;
  }

  body {
    background: #fff;
    font-size: 10pt;
    line-height: 1.4;
  }

  /* Chrome-free page: no controls, no navigation. */
  .skip-link,
  .topbar__actions,
  .toolbar,
  #controls,
  .server-card__actions,
  .details-toolbar,
  .code-panel__copy,
  .toast,
  .empty-state,
  .search,
  .filters,
  .btn { display: none !important; }

  .topbar {
    position: static;
    border-bottom: 2px solid #000;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .topbar__inner { padding: 0 0 8px; }

  .page { max-width: none; padding: 14px 0 0; }

  .section { margin-bottom: 16px; break-inside: avoid; }
  #charts { break-inside: avoid; }

  .card {
    box-shadow: none !important;
    border: 1px solid #b9c1cb;
    break-inside: avoid;
  }

  .stat-grid { grid-template-columns: repeat(6, 1fr); gap: 8px; }
  .stat { padding: 10px; }
  .stat__value { font-size: 20pt; }

  .chart-grid { grid-template-columns: repeat(3, 1fr); }
  .chart-card__canvas { height: 150px; }

  .card-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Every card prints fully expanded — the raw output is the evidence. */
  .server-card { break-inside: avoid; page-break-inside: avoid; }
  .server-card__details {
    display: block !important;
    grid-template-rows: none !important;
    border-top: 1px solid #d5dbe2 !important;
  }
  .server-card__details-inner { overflow: visible !important; }

  .code-body { max-height: none !important; overflow: visible !important; }
  .code-scroll { overflow: visible !important; }
  .code-scroll pre {
    /* Wrap instead of clipping — no evidence may be lost off the page edge. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 7.6pt;
    line-height: 1.42;
  }
  /* Wrapped lines would desynchronise the gutter, so drop it when printing. */
  .code-gutter { display: none !important; }
  .code-panel { break-inside: auto; }

  a { color: #000; text-decoration: underline; }

  .footer { border-top: 1px solid #b9c1cb; padding: 10px 0 0; }
}
