:root {
  --bg-main: #0c0d12;
  --bg-card: #13141c;
  --bg-card-sub: #191b26;
  --bg-card-hover: #1f212f;
  --border-color: #242738;
  --border-light: #2d3045;
  
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --color-orange: #f6821f;
  --color-purple: #c084fc;
  --color-blue: #38bdf8;
  --color-green: #22c55e;
  --color-yellow: #fbbf24;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

:root[data-theme="light"],
html[data-theme="light"],
[data-theme="light"] {
  --bg-main: #f5f6fa;
  --bg-card: #ffffff;
  --bg-card-sub: #f0f2f7;
  --bg-card-hover: #e5e8f0;
  --border-color: #e1e4ec;
  --border-light: #cfd4e0;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --color-orange: #ea580c;
  --color-purple: #9333ea;
  --color-blue: #0284c7;
  --color-green: #16a34a;
  --color-yellow: #d97706;
}

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

html {
  background-color: var(--bg-main);
  color: var(--text-primary);
  overflow-x: hidden;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  line-height: 1.5;
  padding: 24px 28px 48px 28px;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

.app-container {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* SVG Icons - Zero CLS, Instant Native Rendering */
.icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
  fill: currentColor;
  flex-shrink: 0;
}

.icon-md { width: 18px; height: 18px; }
.icon-sm { width: 16px; height: 16px; }
.icon-info { width: 16px; height: 16px; color: var(--text-muted); cursor: pointer; }
.icon-info:hover { color: var(--text-secondary); }
.icon-info-small { width: 13px; height: 13px; color: var(--text-muted); margin-left: 4px; vertical-align: -2px; }

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.logo-link {
  text-decoration: none;
  color: inherit;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--color-orange);
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.accent-dot {
  color: var(--color-orange);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Dual Unit Switcher */
.unit-toggle {
  display: flex;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.unit-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.unit-btn .unit-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

.unit-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.unit-btn.active .unit-hint {
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon {
  width: 18px;
  height: 18px;
}

.btn-outline {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-outline:hover {
  background: var(--bg-card-hover);
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.6fr 1.05fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Overview Card */
.speed-overview-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 24px;
}

.card-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.card-heading h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.test-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-green);
}

.status-indicator.live {
  box-shadow: 0 0 8px var(--color-green);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.9); }
}

/* Primary metrics grid */
.primary-metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 0.9fr;
  gap: 18px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .primary-metrics-grid {
    grid-template-columns: 1fr;
  }
}

.metric-box {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 18px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.metric-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.info-tooltip {
  display: inline-flex;
  align-items: center;
}

.metric-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.metric-number {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -1.5px;
  color: var(--text-primary);
}

.metric-unit {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Secondary Speed Display (MB/s ÷ 8) */
.secondary-speed {
  font-size: 0.85rem;
  color: var(--color-yellow);
  font-weight: 600;
  font-family: var(--font-mono);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.secondary-speed .div-hint {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 400;
  font-family: var(--font-sans);
}

.metric-meta {
  margin-top: 4px;
  margin-bottom: 10px;
}

.meta-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.graph-canvas-wrap {
  margin-top: auto;
  height: 95px;
  position: relative;
}

canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Latency Box */
.latency-box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px;
}

.latency-stat-row {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.latency-stat-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.stat-label {
  display: flex;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-val small {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-sub {
  display: flex;
  gap: 10px;
  font-size: 0.72rem;
  margin-top: 3px;
  font-family: var(--font-mono);
}

.arrow-down {
  color: var(--color-orange);
}

.arrow-up {
  color: var(--color-purple);
}

.loss-badge {
  color: var(--color-green);
  font-size: 0.7rem;
  font-weight: 600;
}

/* Network Health Summary Card */
.network-health-card {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 20px;
}

.health-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.health-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.health-icon {
  width: 20px;
  height: 20px;
  color: var(--color-orange);
}

.health-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.health-status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-green);
  border: 1px solid rgba(34, 197, 94, 0.3);
  padding: 2px 8px;
  border-radius: 4px;
}

.health-indicators-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 680px) {
  .health-indicators-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.health-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.health-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.health-item-top .icon {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}

.health-name {
  font-size: 0.75rem;
  font-weight: 500;
}

.health-score {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-green);
}

.health-score.grade-a {
  color: var(--color-blue);
}

/* Action Bar */
.card-action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
}

.action-buttons-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.pill-btn {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.pill-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
}

.timestamp-display {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Right Column: Server Location */
.server-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.server-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.server-card-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

.map-container {
  height: 240px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-color);
  margin-bottom: 18px;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--bg-card-sub);
}

.map-overlay-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 999;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-primary);
}

.pulse-ring {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-orange);
}

/* Connection Details Meta */
.connection-meta-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.meta-row {
  display: flex;
  align-items: center;
  font-size: 0.82rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
}

.meta-row:last-child {
  border-bottom: none;
}

.meta-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  margin-right: 10px;
}

.meta-label {
  color: var(--text-muted);
  width: 130px;
  flex-shrink: 0;
}

.meta-value {
  color: var(--text-primary);
  font-weight: 500;
  margin-left: auto;
  text-align: right;
  word-break: break-all;
}

.meta-value.highlight {
  color: var(--color-blue);
}

.meta-value.mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* Footer matching Akash's SKILL instructions & branding */
footer {
  margin-top: 48px;
  padding-top: 24px;
  padding-bottom: 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.footer-dot {
  color: var(--border-light);
  font-size: 0.8rem;
}

footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

.footer-bottom-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.footer-creator-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  text-decoration: none !important;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.5px;
  padding: 6px 16px;
  border-radius: 9999px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.footer-creator-link:hover {
  border-color: var(--color-orange);
  color: var(--color-orange) !important;
  transform: translateY(-1px);
}

.footer-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border-color);
  display: block;
}

/* Leaflet dark theme styling */
.leaflet-container {
  background: var(--bg-card) !important;
}

/* Dark mode map filter */
:root:not([data-theme="light"]) .leaflet-tile-pane,
html:not([data-theme="light"]) .leaflet-tile-pane {
  filter: brightness(0.65) invert(1) contrast(2) hue-rotate(200deg) saturate(0.35);
}

/* Light mode map filter: clean subtle contrast */
:root[data-theme="light"] .leaflet-tile-pane,
html[data-theme="light"] .leaflet-tile-pane {
  filter: contrast(1.05) saturate(0.9);
}

.leaflet-control-zoom {
  border: 1px solid var(--border-color) !important;
}

.leaflet-control-zoom a {
  background-color: var(--bg-card-sub) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

.leaflet-control-attribution {
  display: none !important;
}

/* ==========================================================================
   Comprehensive Mobile Responsiveness (Tablets, Phones, Ultra-compact screens)
   ========================================================================== */

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

@media (max-width: 768px) {
  body {
    padding: 16px 14px 40px 14px;
  }

  .speed-overview-card,
  .server-card {
    padding: 18px 16px;
  }

  .primary-metrics-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .metric-number {
    font-size: 2.5rem;
  }

  .metric-unit {
    font-size: 1rem;
  }

  .map-container {
    height: 220px;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding-bottom: 16px;
    margin-bottom: 18px;
  }

  .header-left {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .header-right {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
  }

  .unit-toggle {
    flex: 1;
    min-width: 0;
  }

  .unit-btn {
    flex: 1;
    padding: 7px 6px;
    font-size: 0.78rem;
    justify-content: center;
  }

  .unit-hint {
    display: none;
  }

  #restartBtn {
    padding: 7px 14px;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .card-action-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .action-buttons-group {
    display: flex;
    justify-content: space-between;
    width: 100%;
  }

  .timestamp-display {
    text-align: center;
    font-size: 0.72rem;
  }
}

@media (max-width: 480px) {
  body {
    padding: 12px 10px 32px 10px;
  }

  .logo-text {
    font-size: 1.1rem;
  }

  .logo-icon {
    width: 24px;
    height: 24px;
  }

  .speed-overview-card,
  .server-card {
    padding: 14px 12px;
  }

  .card-heading h2 {
    font-size: 1rem;
  }

  .metric-box {
    padding: 14px 12px;
  }

  .metric-number {
    font-size: 2.2rem;
  }

  .stat-val {
    font-size: 1.35rem;
  }

  .health-indicators-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .health-item {
    padding: 8px 10px;
  }

  .health-name {
    font-size: 0.7rem;
  }

  .health-score {
    font-size: 0.78rem;
  }

  .meta-row {
    flex-wrap: wrap;
    padding: 8px 0;
    gap: 4px;
    align-items: flex-start;
  }

  .meta-label {
    width: auto;
    font-size: 0.78rem;
  }

  .meta-value {
    margin-left: auto;
    font-size: 0.78rem;
    max-width: 100%;
  }

  .meta-value.mono {
    font-size: 0.72rem;
    word-break: break-all;
  }

  .map-container {
    height: 190px;
  }

  .footer-nav {
    flex-direction: column;
    gap: 8px;
    font-size: 0.78rem;
  }

  .footer-dot {
    display: none;
  }

  .footer-creator-link {
    font-size: 0.82rem;
    padding: 6px 14px;
  }
}
