/* ==========================================================================
   Netgauge — base, layout, components
   ========================================================================== */

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

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

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--f-base);
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(900px 520px at 82% -8%, var(--dl-soft), transparent 62%),
    radial-gradient(680px 420px at 8% 4%, var(--lat-soft), transparent 60%);
  background-attachment: fixed;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0 0 var(--s3);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.015em;
  overflow-wrap: break-word;
}
h1 { font-size: var(--f-3xl); letter-spacing: -0.03em; }
h2 { font-size: var(--f-2xl); }
h3 { font-size: var(--f-lg); }
p  { margin: 0 0 var(--s4); max-width: 68ch; color: var(--text-2); }

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

img, svg { max-width: 100%; display: block; }
ul, ol { padding-inline-start: 1.3em; margin-block: 0 var(--s4); }
li { margin-bottom: var(--s2); color: var(--text-2); }
code {
  font-size: 0.9em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

:focus-visible {
  outline: 2px solid var(--dl);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

.wrap {
  width: min(100% - 2 * var(--s4), var(--maxw));
  margin-inline: auto;
}

.skip {
  position: absolute;
  inset-inline-start: -9999px;
  top: var(--s3);
  background: var(--panel);
  color: var(--text);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  z-index: 100;
}
.skip:focus { inset-inline-start: var(--s4); }

.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }
.muted { color: var(--text-3); }
.hidden { display: none !important; }

/* دو رنگ‌بندی مشترک برای همهٔ اعداد تأخیر */
[data-tone='ok']   { color: var(--ok); }
[data-tone='warn'] { color: var(--ul); }
[data-tone='bad']  { color: var(--warn); }

/* ==========================  Header  ========================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur), background var(--dur);
}
.site-header[data-scrolled='true'] { border-bottom-color: var(--line); }

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: 62px;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--f-md);
  text-decoration: none;
  flex: none;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-sub {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--f-xs);
  font-weight: 500;
  line-height: 1.2;
  color: var(--text-3);
}

.nav { margin-inline-start: auto; display: flex; align-items: center; gap: 2px; }
.nav a {
  color: var(--text-2);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  font-size: var(--f-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--dur), background var(--dur);
}
.nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.nav a[aria-current='page'] { color: var(--dl); background: var(--dl-soft); }

.header-tools { display: flex; align-items: center; gap: var(--s2); flex: none; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font: inherit;
  font-size: var(--f-sm);
  transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--panel); }

.burger { display: none; }

@media (max-width: 1040px) {
  .nav a { padding: var(--s2); font-size: var(--f-xs); }
}

@media (max-width: 900px) {
  .burger { display: grid; }
  .nav {
    position: fixed;
    inset: 62px 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--s2) var(--s3) var(--s4);
    background: var(--bg-deep);
    border-bottom: 1px solid var(--line);
    max-height: calc(100dvh - 62px);
    overflow-y: auto;
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur), transform var(--dur);
  }
  .nav[data-open='true'] { opacity: 1; transform: none; pointer-events: auto; }
  .nav a {
    padding: var(--s3) var(--s4);
    font-size: var(--f-base);
    border-bottom: 1px solid var(--line);
  }
  .nav a:last-child { border-bottom: 0; }
}

/* ==========================  Hero  ========================== */

.section.hero { padding: var(--s6) 0 var(--s5); }
.hero-head { margin-bottom: var(--s5); }
.hero h1 { max-width: 18ch; }
.hero-lead { font-size: var(--f-md); max-width: 54ch; }

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 5px var(--s3);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--f-xs);
  color: var(--text-2);
  background: var(--panel);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.live { background: var(--ok); }
.dot.busy { background: var(--ul); }
.dot.bad { background: var(--warn); }

/* ==========================  Speed-test console  ========================== */

.console {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-console);
  background: linear-gradient(180deg, var(--panel), var(--bezel));
  box-shadow: var(--shadow-console);
  overflow: hidden;
}

.console-bar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bezel) 70%, transparent);
}
.console-title {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 600;
  font-size: var(--f-sm);
}
.console-actions { margin-inline-start: auto; display: flex; gap: var(--s2); flex-wrap: wrap; }

/* Aspect ratio taken from the official OpenSpeedTest embed snippet */
.engine {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 50%;
  min-height: 380px;
  background: var(--bezel);
}
.engine iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  overflow: hidden;
}
.engine-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s4);
  text-align: center;
  padding: var(--s5);
  background: var(--bezel);
  z-index: 2;
}
.engine-placeholder p { max-width: 44ch; margin: 0; }
.engine[data-loaded='true'] .engine-placeholder { display: none; }

.ost-credit {
  margin: 0;
  padding: var(--s2) var(--s4);
  font-size: var(--f-xs);
  color: var(--text-3);
  background: var(--bezel);
  border-top: 1px solid var(--line);
}
.ost-credit a { color: var(--text-2); }

/* ==========================  Latency probes  ========================== */

.panel { padding: 0; overflow: hidden; }

.panel-bar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
  padding: var(--s4);
  border-bottom: 1px solid var(--line);
  background: var(--bezel);
}
.panel-actions { margin-inline-start: auto; display: flex; gap: var(--s2); flex-wrap: wrap; }

.probes { list-style: none; margin: 0; padding: 0; }

.probe {
  display: grid;
  grid-template-columns: minmax(9rem, 15rem) 1fr auto;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s4);
  margin: 0;
}
.probe + .probe { border-top: 1px solid var(--line); }

.probe-name { font-weight: 600; font-size: var(--f-sm); min-width: 0; }
.probe-hint {
  display: block;
  font-weight: 400;
  font-size: var(--f-xs);
  color: var(--text-3);
  line-height: 1.3;
}

.probe-bar {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  overflow: hidden;
}
.probe-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--text-3);
  transition: width 420ms var(--ease-out), background var(--dur);
}
.probe[data-tone='ok']   .probe-bar i { background: var(--ok); }
.probe[data-tone='warn'] .probe-bar i { background: var(--ul); }
.probe[data-tone='bad']  .probe-bar i { background: var(--warn); }

.probe-value {
  font-size: var(--f-sm);
  font-weight: 700;
  color: var(--text-3);
  white-space: nowrap;
  text-align: end;
  min-width: 6.5rem;
}
.probe[data-tone='ok']   .probe-value { color: var(--ok); }
.probe[data-tone='warn'] .probe-value { color: var(--ul); }
.probe[data-tone='bad']  .probe-value { color: var(--warn); }
.probe[data-state='busy'] .probe-value { color: var(--text-2); }
.probe[data-state='busy'] .probe-value::after { content: '…'; }

.summary { padding: var(--s4); border-top: 1px solid var(--line); background: var(--bezel); }

.summary-main {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}
.summary-label { font-size: var(--f-xs); color: var(--text-3); display: block; }
.summary-value {
  font-family: var(--font-display);
  font-size: var(--f-readout);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--lat);
}
.readout-unit { font-size: var(--f-sm); color: var(--text-3); font-weight: 600; }

.summary-verdict {
  margin-inline-start: auto;
  padding: var(--s2) var(--s4);
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-weight: 700;
  font-size: var(--f-sm);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s3);
  font-size: var(--f-sm);
}
.summary-grid b { display: block; color: var(--text); font-weight: 600; }

/* ==========================  Buttons  ========================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 42px;
  padding: var(--s3) var(--s5);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: var(--f-sm);
  cursor: pointer;
  text-decoration: none;
  transition: transform 120ms var(--ease), background var(--dur), border-color var(--dur), color var(--dur);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--dl); color: #032025; box-shadow: var(--glow-dl); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--dl) 88%, #fff); }

.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); }

.btn-sm { min-height: 36px; padding: var(--s2) var(--s4); font-size: var(--f-xs); border-radius: var(--r-sm); }
.btn-danger { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: transparent; }

.button-row { display: flex; gap: var(--s2); flex-wrap: wrap; margin: var(--s4) 0; }

.segment {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bezel);
  flex-wrap: wrap;
}
.segment button {
  border: 0;
  background: transparent;
  color: var(--text-3);
  font: inherit;
  font-size: var(--f-xs);
  font-weight: 600;
  min-height: 32px;
  padding: 0 var(--s4);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--dur), color var(--dur);
}
.segment button[aria-pressed='true'] { background: var(--dl-soft); color: var(--dl); }

/* ==========================  Sections  ========================== */

.section { padding: var(--s8) 0; scroll-margin-top: 76px; }
.section-head { margin-bottom: var(--s5); }
.section-head p { font-size: var(--f-md); }
.section-sub { margin-top: var(--s7); }

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--s4); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s5); }

.card {
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--panel);
}
.card h3 { margin-bottom: var(--s2); }
.card > :last-child { margin-bottom: 0; }

.stat {
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
}
.stat-value {
  font-family: var(--font-display);
  font-size: var(--f-xl);
  font-weight: 700;
  line-height: 1.1;
}
.stat-label { font-size: var(--f-xs); color: var(--text-3); }

.speed-input-row { display: flex; gap: var(--s4); align-items: flex-end; flex-wrap: wrap; }

/* ==========================  Tables  ========================== */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: var(--f-sm); background: var(--panel); }
th, td { padding: var(--s3) var(--s4); text-align: start; white-space: nowrap; }
thead th {
  font-size: var(--f-xs);
  color: var(--text-3);
  font-weight: 600;
  background: var(--bezel);
  border-bottom: 1px solid var(--line);
}
tbody tr + tr td { border-top: 1px solid var(--line); }
tbody tr:hover td { background: var(--panel-2); }

.bar {
  height: 5px;
  border-radius: 3px;
  background: currentColor;
  opacity: 0.5;
  min-width: 3px;
  display: block;
  margin-top: 3px;
}

/* ==========================  Accordion  ========================== */

.acc { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel); overflow: hidden; }
.acc + .acc { margin-top: var(--s3); }
.acc summary {
  list-style: none;
  cursor: pointer;
  padding: var(--s4);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--s3);
}
.acc summary::-webkit-details-marker { display: none; }
.acc summary::after {
  content: '';
  margin-inline-start: auto;
  flex: none;
  width: 9px;
  height: 9px;
  border-inline-end: 2px solid var(--text-3);
  border-block-end: 2px solid var(--text-3);
  transform: rotate(45deg);
  transition: transform var(--dur) var(--ease);
}
.acc[open] summary::after { transform: rotate(-135deg); }
.acc .acc-body { padding: 0 var(--s4) var(--s4); }
.acc .acc-body > :last-child { margin-bottom: 0; }

/* ==========================  Key/value rows  ========================== */

.capability {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--s2) var(--s4);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
}
.capability + .capability { margin-top: var(--s2); }
.capability .cap-name { font-weight: 600; font-size: var(--f-sm); }
.capability .cap-need { font-size: var(--f-xs); color: var(--text-3); }
.capability .verdict { font-size: var(--f-xs); font-weight: 700; text-align: end; }
.capability[data-ok='true']  .verdict { color: var(--ok); }
.capability[data-ok='false'] .verdict { color: var(--warn); }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--f-sm);
  font-weight: 600;
}
.field input,
.field select {
  font: inherit;
  min-height: 44px;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--bezel);
  color: var(--text);
  width: 100%;
}

/* ==========================  Charts  ========================== */

.chart { width: 100%; height: auto; aspect-ratio: 3 / 1; }
.chart-empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  color: var(--text-3);
  font-size: var(--f-sm);
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  text-align: center;
  padding: var(--s4);
}

/* ==========================  Toasts  ========================== */

.toasts {
  position: fixed;
  inset-block-end: var(--s4);
  inset-inline-start: var(--s4);
  inset-inline-end: var(--s4);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s2);
  z-index: 90;
  pointer-events: none;
}
.toast {
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--panel);
  box-shadow: var(--shadow-console);
  font-size: var(--f-sm);
  max-width: min(340px, 100%);
}
.toast[data-kind='ok']  { border-inline-start: 3px solid var(--ok); }
.toast[data-kind='bad'] { border-inline-start: 3px solid var(--warn); }

/* ==========================  Footer  ========================== */

.site-footer {
  border-top: 1px solid var(--line);
  padding: var(--s7) 0 var(--s5);
  margin-top: var(--s8);
  background: var(--bg-deep);
}
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s5); }
.footer-grid h4 { font-size: var(--f-sm); color: var(--text); margin-bottom: var(--s2); }
.footer-grid ul { list-style: none; padding: 0; margin: 0; }
.footer-grid li { margin-bottom: var(--s2); }
.footer-grid a { color: var(--text-2); font-size: var(--f-sm); }
.footer-bottom {
  margin-top: var(--s6);
  padding-top: var(--s4);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  justify-content: space-between;
  font-size: var(--f-xs);
  color: var(--text-3);
}

/* ==========================================================================
   Small screens
   ========================================================================== */

@media (max-width: 720px) {
  :root {
    --s7: 40px;
    --s8: 56px;
  }

  body { line-height: 1.65; }

  .wrap { width: min(100% - 2 * var(--s4), var(--maxw)); }

  .section { padding: var(--s8) 0; }
  .section-head { margin-bottom: var(--s4); }
  .section-head p { font-size: var(--f-base); }
  .section-sub { margin-top: var(--s6); }

  .hero h1 { max-width: none; }

  /* three columns will not fit on a phone — stack them */
  .capability {
    grid-template-columns: 1fr auto;
    row-gap: 2px;
  }
  .capability .cap-name { grid-column: 1; }
  .capability .verdict { grid-column: 2; grid-row: 1; }
  .capability .cap-need { grid-column: 1 / -1; grid-row: 2; }

  .probe {
    grid-template-columns: 1fr auto;
    row-gap: var(--s2);
    padding: var(--s4);
  }
  .probe-name  { grid-column: 1; }
  .probe-value { grid-column: 2; min-width: 0; }
  .probe-bar   { grid-column: 1 / -1; }

  .panel-bar { flex-direction: column; align-items: stretch; gap: var(--s3); }
  .panel-actions { margin-inline-start: 0; }
  .panel-actions .btn { flex: 1; }

  .summary-main { gap: var(--s3); }
  .summary-verdict { margin-inline-start: 0; }

  .console-actions { margin-inline-start: 0; width: 100%; }
  .console-actions .btn { width: 100%; }

  .engine { padding-bottom: 130%; min-height: 460px; }

  .chart { aspect-ratio: 4 / 3; }

  .grid-2, .grid-3 { gap: var(--s4); }
  .card { padding: var(--s4); }

  .speed-input-row { flex-direction: column; align-items: stretch; }
  .segment { width: 100%; justify-content: space-between; }
  .segment button { flex: 1; padding: 0 var(--s2); }

  th, td { padding: var(--s3); }

  .footer-grid { gap: var(--s4); }
  .footer-bottom { flex-direction: column; gap: var(--s2); }
}

@media (max-width: 400px) {
  .brand-sub { display: none; }
  .probe-value { font-size: var(--f-xs); }
}
