/* ==========================================================================
   BDIX Speed Tester — Global Stylesheet
   Google Sans typography, FontAwesome, dark/light mode, mobile-first
   ========================================================================== */

/* ---------- Google Sans import (provided by project) ---------- */
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --font: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* Light theme */
  --bg: #f4f6fb;
  --bg-gradient: radial-gradient(1200px 600px at 10% -10%, #dfe9ff 0%, transparent 55%),
                 radial-gradient(900px 500px at 110% 20%, #e6f2ff 0%, transparent 50%);
  --card-bg: #ffffff;
  --card-border: rgba(13, 71, 161, 0.08);
  --text: #0f2147;
  --text-muted: #5b6b8c;
  --primary: #1a73e8;
  --primary-strong: #0d47a1;
  --accent: #00c853;
  --warn: #f9a825;
  --danger: #e53935;
  --surface: #ffffff;
  --surface-raised: #f8faff;
  --input-bg: #f0f3fa;
  --shadow: 0 10px 30px rgba(23, 43, 99, 0.08);
  --shadow-lg: 0 24px 60px rgba(23, 43, 99, 0.16);
  --border: #e7ecf5;
  --chip-bg: #f0f3fa;
  --ring: rgba(26, 115, 232, 0.35);
}

[data-theme='dark'] {
  --bg: #0b1220;
  --bg-gradient: radial-gradient(1200px 600px at 10% -10%, rgba(26, 115, 232, 0.18) 0%, transparent 55%),
                 radial-gradient(900px 500px at 110% 20%, rgba(0, 150, 255, 0.10) 0%, transparent 50%);
  --card-bg: #121a2b;
  --card-border: rgba(120, 160, 255, 0.10);
  --text: #e8eefc;
  --text-muted: #93a1c0;
  --primary: #4d9dff;
  --primary-strong: #8ab9ff;
  --surface: #121a2b;
  --surface-raised: #182338;
  --input: #1a2540;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  --border: #243047;
  --chip-bg: #1e2a44;
  --ring: rgba(77, 157, 255, 0.4);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background-color: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .35s ease, color .35s ease;
  overflow-x: hidden;
}

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

img, svg { display: block; max-width: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

[hidden] { display: none !important; }

/* ---------- Typography Helpers ---------- */
.fw-400 { font-weight: 400; }
.fw-500 { font-weight: 500; }
.fw-700 { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mono, code {
  font-family: 'Google Sans', ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.main {
  padding-top: 24px;
  padding-bottom: 80px;
}

/* ---------- App Bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 90;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-bottom: 1px solid var(--border);
}

.appbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--text);
  font-size: 1.08rem;
}

.brand i { color: var(--primary); font-size: 1.35rem; }
.brand .brand-tag { color: var(--primary); }

.nav-actions { display: flex; align-items: center; gap: 8px; }

.toolbar-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--text-muted);
  background: var(--chip-bg);
  font-size: 1.05rem;
  transition: background .2s, color .2s, transform .15s;
}
.toolbar-btn:hover { background: var(--primary); color: #fff; transform: translateY(-2px); }
.toolbar-btn.active { background: var(--primary); color: #fff; }

/* ---------- Navigation / Tabs ---------- */
.navtabs {
  display: flex;
  gap: 6px;
  background: var(--chip-bg);
  border-radius: 16px;
  padding: 5px;
  margin: 18px 0 22px;
  overflow-x: auto;
  scrollbar-width: none;
}
.navtabs::-webkit-scrollbar { display: none; }

.navtab {
  flex: 1;
  white-space: nowrap;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .25s, color .25s, box-shadow .25s;
}
.navtab i { font-size: 0.95rem; }
.navtab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 4px 14px var(--shadow);
  font-weight: 700;
}

/* ---------- Cards & Panels ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: fadeUp .5s ease both;
}

.card + .card { margin-top: 18px; }

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title i { color: var(--primary); }

.card-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 18px; }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 30px 0 6px; }

.hero-title {
  font-size: clamp(1.9rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.15;
  background: linear-gradient(120deg, var(--primary), var(--primary-strong));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-sub {
  color: var(--text-muted);
  max-width: 640px;
  margin: 14px auto 0;
  font-size: 1.02rem;
}

/* ---------- Big Action Button ---------- */
.speed-btn-wrap { text-align: center; margin: 30px 0; }

.speed-btn {
  position: relative;
  width: 190px; height: 190px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 700;
  box-shadow: 0 12px 40px var(--ring), inset 0 -6px 20px rgba(0,0,0,0.12);
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
}
.speed-btn:hover { transform: scale(1.05); box-shadow: 0 16px 50px var(--ring); }
.speed-btn:active { transform: scale(0.97); }

.speed-btn .ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  animation: spin 1.4s linear infinite;
  display: none;
}

.speed-btn.measuring .ring { display: block; }
.speed-btn .btn-label { display: flex; flex-direction: column; align-items: center; gap: 6px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Stats Grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 22px;
}

.stat-box {
  background: var(--surface-raised);
  border-radius: 18px;
  padding: 18px 16px;
  text-align: center;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.stat-label i { font-size: 0.85rem; }

.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.2; }
.stat-value small { font-size: 0.6em; font-weight: 500; color: var(--text-muted); }

@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Speedometer / Gauge ---------- */
.gauge-wrap { text-align: center; margin: 10px 0; }

.speedo {
  font-size: clamp(2rem, 9vw, 3.6rem);
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.speedo .unit { font-size: 0.45em; color: var(--text-muted); font-weight: 500; }

.gauge-label { color: var(--text-muted); margin-top: 10px; text-transform: uppercase; letter-spacing: 1px; font-size: 0.8rem; }

/* animated number */
.count-up { will-change: content; }

/* ---------- Graphs ---------- */
.chart {
  margin-top: 16px;
  position: relative;
  width: 100%;
  border-radius: 14px;
  background: rgba(128, 160, 255, 0.04);
  overflow: hidden;
}

.chart-canvas { width: 100%; height: 120px; display: block; }

.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 0.8rem; color: var(--text-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Progress bars ---------- */
.progress-track { background: var(--chip-bg); height: 10px; border-radius: 999px; overflow: hidden; margin-top: 14px; }
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .3s ease;
}

/* ---------- Tags / Chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}
.chip.bdix { background: rgba(0, 200, 83, 0.12); color: var(--success); }
.chip.ping { background: rgba(245, 168, 37, 0.12); color: var(--warn); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
}

input[type="text"],
input[type="url"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--input);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

.input-group {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.input-group .field { flex: 1; margin-bottom: 0; }
.input-group input { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  transition: transform .15s, box-shadow .2s, background .2s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 24px var(--ring);
}
.btn-primary:hover { background: var(--primary-strong); transform: translateY(-2px); box-shadow: 0 12px 30px var(--ring); }

.btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 10px 16px; font-size: 0.85rem; }

/* ---------- Result list ---------- */
.result-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-icon {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.1rem;
  background: var(--chip-bg);
  color: var(--primary);
}
.result-main { flex: 1; min-width: 0; }
.result-title { font-weight: 600; font-size: 0.92rem; word-break: break-all; }
.result-desc { color: var(--text-muted); font-size: 0.8rem; }
.result-value { text-align: right; font-weight: 700; }
.result-status { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }

/* ---------- Spinner ---------- */
.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner.lg { width: 40px; height: 40px; border-width: 4px; }

.loading-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 30px 0; color: var(--text-muted); }

/* ---------- Skeleton ---------- */
.skeleton {
  border-radius: 10px;
  background: linear-gradient(90deg, var(--chip-bg) 25%, var(--input) 50%, var(--chip-bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(92vw, 420px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  font-size: 0.9rem;
  animation: slideUp .3s ease;
}
.toast i { font-size: 1.1rem; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.info i { color: var(--primary); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding: 28px 0 40px;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  margin-top: 30px;
}
.footer .brand { justify-content: center; margin-bottom: 8px; font-size: 0.95rem; }

/* ---------- Simplify / Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 18px 0; border: none; }

.badge-bdix {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 200, 83, 0.12);
  color: var(--success);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-bdix i { animation: pulse 2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Animations ---------- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */
@media (min-width: 768px) {
  .navtabs { max-width: 680px; margin-left: auto; margin-right: auto; }
}

@media (max-width: 480px) {
  .card { padding: 18px; }
  .speed-btn { width: 160px; height: 160px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}