:root {
  --blue: #1b75bb;
  --blue-light: #29abe2;
  --map-blue: #3b7ddd;
  --orange: #e87722;
  --orange-light: #f5923e;
  --ink: #222;
  --muted: #667;
  --ok: #1e9e4a;
  --warn: #e6a817;
  --bad: #d43f3a;
  --panel-bg: #ffffff;
  --page-bg: #f7f9fc;
  --border: #dde4ee;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--page-bg);
  min-height: 100vh;
}

/* ---------- header ---------- */
.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 42px; height: 42px; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name { font-size: 30px; font-weight: 800; letter-spacing: 1px; font-style: italic; }
.brand-sub { font-size: 7.5px; letter-spacing: 0.06em; color: var(--blue-light); font-weight: 700; margin-top: 3px; }
.site-header h1 { font-size: 26px; text-align: center; }
.copyright { text-align: right; font-size: 13px; color: var(--muted); }

main { max-width: 1200px; margin: 0 auto; padding: 20px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- step 1: map ---------- */
.map-wrap { display: flex; justify-content: center; padding: 10px 0 0; }
#usmap { width: min(860px, 95vw); }
#usmap svg { width: 100%; height: auto; display: block; }
#usmap .state { fill: var(--map-blue); transition: fill 0.15s; }
#usmap .borders { stroke: #fff; stroke-width: 0.7; stroke-dasharray: 3 2; }
#usmap .dccircle { display: none; }
#usmap .separator1, #usmap .separator2 { display: none; }

.nrt-marker { cursor: pointer; }
.nrt-marker circle.core {
  fill: var(--orange-light);
  stroke: #c96a1b;
  stroke-width: 1.5;
  transition: r 0.15s;
}
.nrt-marker circle.halo {
  fill: none;
  stroke: var(--orange-light);
  stroke-width: 2;
  opacity: 0.8;
  animation: haloPulse 1.8s ease-out infinite;
  pointer-events: none;
}
@keyframes haloPulse {
  0% { r: 9; opacity: 0.8; }
  100% { r: 26; opacity: 0; }
}
.nrt-marker:hover circle.core { r: 12; }
.nrt-marker text {
  font-size: 15px;
  font-weight: 700;
  fill: #123;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
  pointer-events: none;
}
.map-caption { text-align: center; font-size: 20px; font-weight: 700; margin: 26px 0 40px; }

/* ---------- step 2: form ---------- */
.form-card { max-width: 720px; margin: 24px auto; background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 32px 40px; box-shadow: 0 2px 10px rgba(20, 40, 80, 0.06); }
.form-card h2 { font-size: 30px; margin-bottom: 16px; }
.instructions { margin: 0 0 26px 20px; line-height: 1.8; }
.field-row { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; margin-bottom: 20px; }
.field-row label { font-weight: 600; padding-top: 6px; }
.field-row .hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.field-row input[type="text"], .field-row input[type="number"], .field-row select {
  font-size: 15px; padding: 8px 10px; border: 1.5px solid var(--blue-light); border-radius: 6px; width: 100%; max-width: 260px; background: #fff;
}
.product-cards { display: flex; flex-direction: column; gap: 10px; }
.product-card {
  display: flex; align-items: center; gap: 12px; border: 1.5px solid var(--border); border-radius: 8px; padding: 10px 14px; cursor: pointer; user-select: none; transition: border-color 0.15s, background 0.15s;
}
.product-card input { width: 18px; height: 18px; accent-color: var(--blue); }
.product-card.selected { border-color: var(--blue); background: #eef5fd; }
.product-card .p-name { font-weight: 700; }
.product-card .p-tag { font-size: 12px; color: var(--muted); }
.form-error { color: var(--bad); font-weight: 600; margin-bottom: 12px; }
.form-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 26px; }

.btn-primary {
  background: var(--orange); color: #fff; font-size: 16px; font-weight: 700; border: none; border-radius: 6px; padding: 12px 26px; cursor: pointer;
}
.btn-primary:hover { background: #d1691d; }
.btn-primary:disabled { background: #ccc; cursor: default; }
.btn-secondary {
  background: #fff; color: var(--blue); font-size: 14px; font-weight: 600; border: 1.5px solid var(--blue); border-radius: 6px; padding: 10px 18px; cursor: pointer;
}
.btn-secondary:hover { background: #eef5fd; }

/* ---------- step 3: test dashboard ---------- */
.test-head { text-align: center; margin: 10px 0 22px; }
.test-head h2 { font-size: 24px; margin-bottom: 14px; }
.progress-track { height: 10px; background: #e3e9f2; border-radius: 6px; max-width: 700px; margin: 0 auto; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--blue-light), var(--blue)); border-radius: 6px; transition: width 0.4s ease; }
.progress-label { margin-top: 8px; font-size: 14px; color: var(--muted); }

.dash { display: grid; grid-template-columns: 1fr 1.2fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .dash { grid-template-columns: 1fr; } .site-header { grid-template-columns: 1fr; text-align: center; } .copyright { text-align: center; } .field-row { grid-template-columns: 1fr; } }

.panel { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; box-shadow: 0 2px 10px rgba(20, 40, 80, 0.05); }
.panel h3 { font-size: 16px; margin-bottom: 14px; color: #123; }
.badge { display: inline-block; background: #eef5fd; color: var(--blue); border-radius: 12px; font-size: 12px; padding: 2px 10px; margin-left: 8px; vertical-align: middle; }

.port-checklist { list-style: none; }
.port-checklist li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid #eef1f7; }
.port-checklist li:last-child { border-bottom: none; }
.port-ind { width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 13px; color: #fff; background: #c9d2e0; }
.port-ind.pending { background: #c9d2e0; }
.port-ind.running { background: var(--blue-light); animation: spinPulse 1s linear infinite; }
@keyframes spinPulse { 0% { box-shadow: 0 0 0 0 rgba(41, 171, 226, 0.5); } 100% { box-shadow: 0 0 0 12px rgba(41, 171, 226, 0); } }
.port-ind.open { background: var(--ok); }
.port-ind.blocked { background: var(--bad); }
.port-ind.inferred { background: var(--warn); }
.port-line-main { font-weight: 700; font-size: 14px; }
.port-line-sub { font-size: 12px; color: var(--muted); }
.port-status-word { margin-left: auto; font-size: 13px; font-weight: 700; }
.port-status-word.open { color: var(--ok); }
.port-status-word.blocked { color: var(--bad); }
.port-status-word.inferred { color: var(--warn); }
.port-status-word.running { color: var(--blue-light); }

.pulse-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.pulse-node { background: var(--blue); color: #fff; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 6px 12px; }
.pulse-line { position: relative; flex: 1; height: 3px; background: #dfe6f0; border-radius: 2px; overflow: visible; }
.pulse-dot { position: absolute; top: -3.5px; width: 10px; height: 10px; border-radius: 50%; background: var(--orange-light); animation: travel 1.6s linear infinite; }
.pulse-dot.d2 { animation-delay: 0.53s; }
.pulse-dot.d3 { animation-delay: 1.06s; }
@keyframes travel { 0% { left: 0%; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { left: calc(100% - 10px); opacity: 0; } }
#voipPanel.idle .pulse-dot { animation-play-state: paused; opacity: 0.25; }

#rttChart { width: 100%; height: 160px; background: #0e1726; border-radius: 8px; }

.live-stats { display: flex; gap: 12px; margin-top: 14px; }
.stat { flex: 1; background: #f2f6fc; border-radius: 8px; text-align: center; padding: 10px 6px; }
.stat-val { display: block; font-size: 24px; font-weight: 800; color: var(--blue); }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.log-panel { margin-top: 18px; }
.test-log { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.7; max-height: 160px; overflow-y: auto; background: #0e1726; color: #9fd1a8; border-radius: 8px; padding: 10px 14px; }
.test-log .t-info { color: #8ab4de; }
.test-log .t-ok { color: #6fdb8f; }
.test-log .t-warn { color: #f0c26a; }
.test-log .t-bad { color: #f08a86; }

/* ---------- header right (copyright + gear) ---------- */
.header-right { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.header-right .copyright { font-size: 13px; color: var(--muted); }
.gear-link { color: #8a94a6; display: inline-flex; padding: 6px; border-radius: 50%; transition: color 0.15s, background 0.15s, transform 0.3s; }
.gear-link:hover { color: var(--blue); background: #eef5fd; transform: rotate(40deg); }
.header-logo { height: 46px; width: auto; }
.brand-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }

/* ---------- step 4: report (shared with admin detail) ---------- */
#view-report, #view-detail { max-width: 1400px; margin: 0 auto; }
.report {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 0 0 28px; box-shadow: 0 3px 16px rgba(20, 40, 80, 0.08); overflow: hidden;
}
.report > * { margin-left: 44px; margin-right: 44px; }

.letterhead {
  display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
  margin: 0 !important; padding: 26px 44px 22px;
  border-bottom: 4px solid var(--blue);
  background: linear-gradient(180deg, #fbfdff, #f2f7fd);
}
.lh-brand { display: flex; align-items: center; gap: 10px; }
.lh-logo { height: 52px; width: auto; }
.lh-title { text-align: right; }
.lh-doc { font-size: 26px; font-weight: 800; color: #12263f; letter-spacing: 0.01em; }
.lh-meta { font-size: 13px; color: var(--muted); margin-top: 4px; }

.verdict-banner {
  margin: 0 !important; padding: 16px 44px; color: #fff;
  display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap;
}
.verdict-banner.ready { background: linear-gradient(90deg, #1e9e4a, #26b859); }
.verdict-banner.warnings { background: linear-gradient(90deg, #d99a0b, #e6a817); }
.verdict-banner.not-ready { background: linear-gradient(90deg, #c23230, #d43f3a); }
.verdict-word { font-size: 24px; font-weight: 900; letter-spacing: 0.03em; }
.verdict-reasons { font-size: 13.5px; font-weight: 600; opacity: 0.95; }

.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0;
  margin-top: 22px !important; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.meta-item { padding: 14px 18px; border-right: 1px solid var(--border); background: #fbfcfe; }
.meta-item:last-child { border-right: none; }
.m-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.m-val { font-size: 15px; font-weight: 700; color: #16324f; line-height: 1.45; }

.report h3 {
  font-size: 17px; margin-top: 30px; margin-bottom: 12px; color: #12263f;
  text-transform: uppercase; letter-spacing: 0.05em;
  padding-bottom: 7px; border-bottom: 2px solid var(--blue-light);
}
.port-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.port-table th { text-align: left; background: #12263f; color: #fff; padding: 10px 12px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.port-table td { padding: 11px 12px; border-bottom: 1px solid #e6ebf3; vertical-align: top; }
.port-table tbody tr:nth-child(even) { background: #f8fafd; }
.cell-port { font-weight: 800; white-space: nowrap; color: #16324f; }
.cell-method { font-size: 13px; }
.cell-detail { display: block; color: #7a8699; font-size: 12px; margin-top: 3px; line-height: 1.5; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 800; border-radius: 12px; padding: 4px 12px; color: #fff; letter-spacing: 0.03em; white-space: nowrap; }
.pill.open { background: var(--ok); }
.pill.blocked { background: var(--bad); }
.pill.inferred { background: var(--warn); }

.voip-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.voip-card { border: 1px solid var(--border); border-top: 4px solid #c9d2e0; border-radius: 10px; padding: 18px 14px 14px; text-align: center; background: #fbfcfe; }
.voip-card.good { border-top-color: var(--ok); }
.voip-card.warn { border-top-color: var(--warn); }
.voip-card.bad { border-top-color: var(--bad); }
.voip-card .v-val { font-size: 34px; font-weight: 850; line-height: 1; }
.voip-card .v-unit { font-size: 16px; font-weight: 700; margin-left: 2px; color: inherit; opacity: 0.7; }
.voip-card .v-name { font-size: 12px; color: #445; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 8px; }
.voip-card .v-req { font-size: 11px; color: var(--muted); margin-top: 5px; }
.voip-card.good .v-val { color: var(--ok); }
.voip-card.warn .v-val { color: var(--warn); }
.voip-card.bad .v-val { color: var(--bad); }
.voip-error { color: var(--bad); font-weight: 700; }
.voip-summary, .section-note { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.6; }

.report-chart { margin-top: 18px !important; }
.report-chart img { width: 100%; max-width: 860px; display: block; border-radius: 8px; border: 1px solid var(--border); }
.chart-caption { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

.report-notes { font-size: 12.5px; color: #5a6577; line-height: 1.75; margin-top: 28px !important; background: #f4f7fb; border-left: 4px solid var(--blue-light); border-radius: 0 8px 8px 0; padding: 14px 18px; }
.report-footer { margin-top: 26px !important; padding-top: 14px; border-top: 1px solid var(--border); font-size: 11.5px; color: #8a94a6; }
.save-line { margin-top: 14px !important; font-size: 13px; font-weight: 600; }
.save-line.ok { color: var(--ok); }
.save-line.bad { color: var(--bad); }
.report-actions { display: flex; gap: 14px; justify-content: center; margin: 22px 0 40px; }

/* ---------- admin portal ---------- */
.login-hero {
  min-height: calc(100vh - 170px);
  display: grid;
  place-items: center;
  padding: 40px 16px;
  border-radius: 18px;
  margin-top: 6px;
  background:
    radial-gradient(1000px 500px at 85% -10%, rgba(41, 171, 226, 0.35), transparent 60%),
    radial-gradient(800px 500px at 0% 110%, rgba(41, 171, 226, 0.25), transparent 55%),
    linear-gradient(135deg, #0c2340 0%, #123a63 55%, #1b75bb 100%);
}
.login-card {
  width: min(420px, 92vw);
  background: #fff;
  border-radius: 16px;
  padding: 40px 42px 30px;
  box-shadow: 0 24px 60px rgba(4, 18, 38, 0.45);
  text-align: center;
}
.login-logo { width: 190px; max-width: 80%; margin: 0 auto 18px; display: block; }
.login-card h2 { font-size: 25px; color: #12263f; margin-bottom: 4px; }
.login-sub { font-size: 13.5px; color: var(--muted); margin-bottom: 26px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 7px; }
.login-card label { font-size: 12px; font-weight: 700; color: #33445a; margin-top: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.login-card input {
  font-size: 15px; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  background: #fbfcfe; transition: border-color 0.15s, box-shadow 0.15s; width: 100%;
}
.login-card input:focus { outline: none; border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(41, 171, 226, 0.18); background: #fff; }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 44px; }
.pass-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #8a94a6; cursor: pointer; padding: 8px; border-radius: 8px; display: grid; place-items: center;
}
.pass-toggle:hover { color: var(--blue); background: #eef5fd; }
.login-submit {
  margin-top: 20px; width: 100%; padding: 13px; font-size: 15.5px; border-radius: 10px;
  background: linear-gradient(180deg, #f5923e, #e87722);
  box-shadow: 0 6px 16px rgba(232, 119, 34, 0.35);
}
.login-submit:hover { background: linear-gradient(180deg, #ef8730, #d1691d); }
.login-foot { margin-top: 22px; font-size: 11px; color: #9aa5b5; text-transform: uppercase; letter-spacing: 0.08em; }

.admin-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.admin-toolbar input[type="search"] { flex: 1; min-width: 220px; max-width: 380px; font-size: 14px; padding: 9px 14px; border: 1.5px solid var(--border); border-radius: 8px; }
.admin-toolbar input[type="search"]:focus { outline: none; border-color: var(--blue-light); }
.list-summary { font-size: 13px; color: var(--muted); margin-left: auto; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th { text-align: left; padding: 9px 10px; border-bottom: 2px solid var(--border); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: #445; }
.admin-table td { padding: 10px; border-bottom: 1px solid #eef1f7; }
.admin-table tbody tr { cursor: pointer; }
.admin-table tbody tr:hover { background: #f2f7fd; }
.cell-company { font-weight: 700; }
.loading-cell { text-align: center; color: var(--muted); padding: 26px 0 !important; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; font-size: 13px; color: var(--muted); }
.pager button:disabled { opacity: 0.4; cursor: default; }
.btn-view { padding: 5px 12px; font-size: 12.5px; }
.detail-bar { display: flex; justify-content: space-between; margin-bottom: 14px; }

/* ---------- print ---------- */
@media print {
  @page { size: letter; margin: 12mm; }
  .site-header, .no-print, .report-actions, .detail-bar { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  #view-report, #view-detail { max-width: none; }
  .report { border: none; box-shadow: none; border-radius: 0; }
  .report > * { margin-left: 0; margin-right: 0; }
  .letterhead, .verdict-banner { padding-left: 0; padding-right: 0; }
  .letterhead { background: none; }
  .verdict-banner, .letterhead, .pill, .port-table th, .voip-card, .meta-item, .report-notes {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .port-table, .voip-cards, .meta-grid, .report-chart { break-inside: avoid; }
  h3 { break-after: avoid; }
}
