/* app.css — tema do site do speedtest. Sem fontes/imagens externas; sem style="" no HTML (CSP).
   As cores da MARCA chegam por CSSOM (style.setProperty em site.js) e entram só pelas variáveis
   --brand*, que têm padrão CommandoISP aqui. Claro/escuro automático (prefers-color-scheme). */

:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #d3dae8;
  --line-strong: #8693ab;
  --track: #dde3f0;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 8px 24px rgb(15 23 42 / 6%);
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --ok: #027a48;
  --ok-bg: #ecfdf3;
  --warn: #8a4b00;
  --warn-bg: #fff7e6;
  --brand: #1d4ed8;
  --on-brand: #ffffff;
  --accent: #b45309;
  --on-accent: #ffffff;
  --brand-ink-light: #1d4ed8;
  --brand-ink-dark: #6587e4;
  --accent-ink-light: #b45309;
  --accent-ink-dark: #c3753a;
  --brand-ink: var(--brand-ink-light);
  --accent-ink: var(--accent-ink-light);
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1422;
    --surface: #161e30;
    --text: #e8edf7;
    --muted: #a3b0c7;
    --line: #2a3550;
    --line-strong: #5d6d90;
    --track: #26314b;
    --shadow: none;
    --danger: #ff8b7e;
    --danger-bg: #3a1a1a;
    --ok: #4ade80;
    --ok-bg: #12301f;
    --warn: #fbbf24;
    --warn-bg: #33270a;
    --brand-ink: var(--brand-ink-dark);
    --accent-ink: var(--accent-ink-dark);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.55 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* texto da marca vem do provedor (/config.json) e pode ter uma palavra gigante sem espaço (URL, "WWWW…") nos limites do contrato
     (title 200, tagline 300, privacy_text 2000 caracteres): sem isto a página estourava para milhares de pixels de largura. `anywhere`
     (e não `break-word`) também reduz o tamanho mínimo dos itens flex/grid, que é o que prendia a largura. */
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
img, svg { max-width: 100%; }
a { color: var(--brand-ink); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.5rem, 5.5vw, 2.1rem); letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
small, .note { color: var(--muted); }
.note { font-size: .875rem; margin: .5rem 0 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* Foco SEMPRE visível (teclado) */
:focus-visible { outline: 3px solid var(--brand-ink); outline-offset: 3px; border-radius: 6px; }
.skip-link {
  position: absolute; left: 12px; top: -64px; z-index: 10; background: var(--surface); color: var(--text);
  padding: 12px 16px; border-radius: 10px; border: 2px solid var(--brand-ink); text-decoration: none;
}
.skip-link:focus { top: 12px; }

.wrap {
  width: 100%; max-width: 760px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* Cabeçalho */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-in { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 12px; min-height: 64px; padding-top: 6px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-height: 44px; min-width: 0; flex: 1 1 auto; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; flex: none; }
.brand-name { font-weight: 700; font-size: 1.1rem; overflow-wrap: break-word; min-width: 0; }
.top-nav { display: flex; gap: 4px; flex: 0 0 auto; }
.top-nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: .9375rem; white-space: nowrap;
}
.top-nav a:hover { background: var(--bg); text-decoration: underline; }
@media (max-width: 520px) {
  .top-nav { flex: 1 1 100%; margin: 0 -12px; }
}

main { flex: 1 0 auto; padding-top: 24px; padding-bottom: 40px; }
main:focus { outline: none; }
.hero { text-align: center; margin-bottom: 20px; }
.tagline { color: var(--muted); font-size: 1.0625rem; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card-title { font-size: 1rem; margin-bottom: .75rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Mostrador */
.stage { text-align: center; padding-top: 24px; }
.gauge { position: relative; width: min(100%, 400px); margin: 0 auto; }
.gauge svg { display: block; width: 100%; height: auto; }
.gauge-track, .gauge-arc { fill: none; stroke-width: 16; stroke-linecap: round; }
.gauge-track { stroke: var(--track); }
.gauge-arc { stroke: var(--brand-ink); }
.gauge[data-phase="upload"] .gauge-arc { stroke: var(--accent-ink); }
.gauge-knob { fill: var(--brand-ink); stroke: var(--surface); stroke-width: 3; }
.gauge[data-phase="upload"] .gauge-knob { fill: var(--accent-ink); }
.gauge-tick { stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.gauge-tick-label { fill: var(--muted); font: 600 11.5px var(--font); text-anchor: middle; dominant-baseline: central; }
.gauge-readout { position: absolute; left: 0; right: 0; top: 32%; padding: 0 22%; pointer-events: none; }
.gauge-number { font-weight: 800; font-size: clamp(2.4rem, 11vw, 3.4rem); line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.gauge-unit { font-size: .9375rem; font-weight: 700; color: var(--muted); letter-spacing: .02em; line-height: 1.3; }
.gauge-label { font-size: .875rem; font-weight: 600; color: var(--muted); min-height: 1.4em; margin-top: 2px; }
.gauge-ping { font-size: .8125rem; color: var(--muted); min-height: 1.3em; font-variant-numeric: tabular-nums; }

.phases { display: flex; list-style: none; margin: 4px 0 14px; padding: 0; gap: 3px; }
.phases li {
  flex: 1 1 auto; min-width: 0; font-size: .75rem; color: var(--muted); padding-top: 14px; position: relative; font-weight: 600;
  white-space: nowrap; text-align: center;
}
.phases li::before, .phases li::after {
  content: ""; position: absolute; top: 0; left: 2%; right: 2%; height: 6px; border-radius: 3px;
}
.phases li::before { background: var(--track); }
.phases li::after { background: var(--brand-ink); transform: scaleX(var(--p, 0)); transform-origin: left; transition: transform .25s linear; }
.phases li.is-done, .phases li.is-active { color: var(--text); }
.phases li.is-done { --p: 1; }
.phases li.is-indeterminate::after { transform: none; right: 52%; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.status { min-height: 1.6em; margin: 0 0 14px; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; min-width: 52px;
  padding: 0 28px; border-radius: 999px; font: 700 1.0625rem var(--font); cursor: pointer;
  border: 2px solid var(--brand-ink); background: var(--brand); color: var(--on-brand); text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-go { min-width: min(100%, 260px); font-size: 1.2rem; min-height: 58px; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--brand-ink); filter: none; }
.btn-link { background: none; border: 0; color: var(--brand-ink); font: inherit; text-decoration: underline; cursor: pointer; min-height: 44px; padding: 0; margin-left: auto; }

.lgpd { font-size: .8125rem; color: var(--muted); margin: 16px auto 0; max-width: 520px; }

.alert {
  margin: 16px auto 0; max-width: 520px; text-align: left; border-radius: 14px; padding: 14px 16px;
  background: var(--danger-bg); border: 1px solid var(--danger); color: var(--text);
}
.alert strong { display: block; color: var(--danger); margin-bottom: 2px; }
.alert p { margin: 0; }
.alert .note { margin-top: 6px; }
.alert.is-neutral { background: var(--bg); border-color: var(--line); }
.alert.is-neutral strong { color: var(--text); }

/* Resultado */
.result h2 { margin-bottom: 4px; }
.result .when { margin: 0 0 12px; }
.badge {
  display: inline-block; font-size: .8125rem; font-weight: 700; border-radius: 999px; padding: 2px 12px; margin: 0 0 14px;
  color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok);
}
.badge.is-warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn); }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0 0 16px; }
.metric { background: var(--bg); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.metric dt { font-size: .8125rem; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.metric dd { margin: 0; font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric dd small { display: block; font-size: .8125rem; font-weight: 500; }
.metric .unit { font-size: .875rem; font-weight: 600; color: var(--muted); }
.metrics .metric:last-child:nth-child(odd) { grid-column: 1 / -1; }
.metric-big dd { font-size: clamp(1.9rem, 8vw, 2.6rem); line-height: 1.1; }
.metric-down { border-left: 4px solid var(--brand-ink); }
.metric-up { border-left: 4px solid var(--accent-ink); }
.share { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.share-url {
  flex: 1 1 200px; min-width: 0; min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); padding: 0 12px; font: .9375rem var(--font);
}
.share .btn { padding: 0 20px; min-height: 48px; }

/* Informações e histórico */
.meta { display: grid; gap: 10px; margin: 0; }
.meta div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.meta div:last-child { border-bottom: 0; padding-bottom: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; text-align: right; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 14px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; font-size: .9375rem; }
.history li:last-child { border-bottom: 0; }
.history .h-when { color: var(--muted); font-size: .8125rem; grid-column: 1 / -1; }
.history b { font-weight: 700; }
.history .h-unv { color: var(--warn); font-size: .75rem; }

/* Rodapé */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 20px 0 28px; font-size: .875rem; color: var(--muted); }
.footer-links { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 0 0 8px; padding: 0; list-style: none; }
.footer-links a, .chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 600;
}
.footer-links a:hover, .chip:hover { border-color: var(--brand-ink); text-decoration: underline; }
.footer-legal { margin: 8px 0 0; }

/* Páginas de texto */
.prose { max-width: 680px; margin: 0 auto; }
.prose h2 { margin-top: 1.8em; }
.prose li { margin-bottom: .45em; }
.prose figure { margin: 1.5em 0; }
.prose figcaption { font-size: .875rem; color: var(--muted); margin-top: .5em; }
.prose svg { display: block; width: 100%; max-width: 520px; height: auto; margin: 0 auto; }
.diagram-bar { fill: var(--track); }
.diagram-warm { fill: var(--muted); opacity: .35; }
.diagram-win { fill: var(--brand-ink); }
.diagram-text { fill: var(--text); font: 600 13px var(--font); }
.diagram-axis { stroke: var(--muted); stroke-width: 1.5; fill: none; }
.provider-text { white-space: pre-line; background: var(--bg); border-radius: 12px; padding: 12px 14px; }

@media (min-width: 640px) {
  main { padding-top: 40px; }
  .card { padding: 28px; }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-big { grid-column: span 1; }
}

@media (max-width: 480px) {
  .share-url { flex-basis: 100%; }
  .share .btn { flex: 1 1 100%; }
}
@media (max-width: 420px) {
  .card { padding: 16px; }
  .phases li { font-size: .6875rem; }
  .gauge-label { font-size: .8125rem; }
  .gauge-unit { font-size: .875rem; }
}
@media (max-width: 350px) {
  .phases li { font-size: .625rem; }
  .card { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  .site-header, .site-footer, .actions, .share { display: none; }
  body { background: #fff; color: #000; }
}
