/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary:   #0d1117;
  --bg-secondary: #161b22;
  --bg-panel:     #1c2128;
  --border:       #30363d;
  --text-primary: #e6edf3;
  --text-muted:   #8b949e;
  --green:        #3fb950;
  --blue:         #1f6feb;
  --red:          #da3633;
  --yellow:       #d29922;
  --orange:       #e3702a;
  --radius:       12px;
  --shadow:       0 4px 24px rgba(0,0,0,0.45);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* ===========================
   DASHBOARD SHELL
   =========================== */
.dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.header {
  padding: 12px 18px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}

.header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.status-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.status-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  white-space: nowrap;
}
.status-badge.loading { color: var(--yellow); border-color: var(--yellow); }
.status-badge.online  { color: var(--green);  border-color: var(--green);  }
.status-badge.error   { color: var(--red);    border-color: var(--red);    }

/* ===========================
   STATS BAR
   =========================== */
.stats-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1 1 100px;
  min-width: 90px;
  padding: 10px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat-card:last-child { border-right: none; }

.stat-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-value small {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Target card */
.target-card {
  min-width: 160px;
  justify-content: center;
}

.target-row {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.target-row input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  appearance: textfield;
  -moz-appearance: textfield;
}
.target-row input::-webkit-outer-spin-button,
.target-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.target-row input::placeholder { color: var(--text-muted); }
.target-row input:focus {
  outline: none;
  border-color: var(--blue);
}

.target-btn {
  padding: 5px 12px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.2s;
}
.target-btn:hover { filter: brightness(1.15); }

/* ===========================
   PROGRESS BAR
   =========================== */
.progress-wrap {
  padding: 8px 18px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 6px;
  flex-direction: column;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-label {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.progress-pct {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
}

.progress-track {
  height: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
}

.progress-fill.complete {
  background: linear-gradient(90deg, var(--green), #57e281);
}

/* ===========================
   MAIN GRID (video + map)
   =========================== */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  flex: 1;
  min-height: 0;
}

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

/* ── Panels ── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-header {
  padding: 9px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.panel-title {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ── Live dot ── */
.live-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.live-dot.active {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  animation: blink 1.2s ease infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

/* ── Video ── */
.video-container {
  position: relative; flex: 1;
  background: #000; min-height: 240px;
}
#video {
  width: 100%; height: 100%;
  display: block; object-fit: contain; background: #000;
}
.video-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.75);
  color: var(--text-muted); gap: 12px; font-size: 13px;
}
.video-overlay.hidden { display: none; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Map ── */
#map { flex: 1; min-height: 240px; z-index: 0; }

.map-controls { display: flex; gap: 6px; }
.map-controls button {
  padding: 3px 10px; font-size: 11px;
  background: var(--bg-panel); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; transition: background 0.2s, border-color 0.2s;
}
.map-controls button:hover { background: var(--blue); border-color: var(--blue); }

.location-info {
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 14px;
  flex-shrink: 0;
}
.coord-row { display: flex; align-items: baseline; gap: 7px; }
.coord-label {
  font-size: 9px; font-weight: 700;
  letter-spacing: 1.2px; color: var(--text-muted);
  text-transform: uppercase; min-width: 30px; flex-shrink: 0;
}
.coord-row span:last-child {
  font-family: 'SF Mono','Fira Code','Consolas',monospace;
  font-size: 11px; white-space: nowrap;
}

/* ===========================
   SPLITS PANEL
   =========================== */
.splits-panel {
  margin: 0 12px 12px;
}

.reset-btn {
  padding: 3px 10px; font-size: 11px;
  background: var(--bg-panel); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; transition: all 0.2s;
}
.reset-btn:hover { color: var(--red); border-color: var(--red); }

.splits-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 260px;
}

.splits-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.splits-table thead {
  position: sticky; top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.splits-table th {
  padding: 8px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.splits-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.splits-table tr:last-child td { border-bottom: none; }

.splits-table tr:hover td { background: rgba(255,255,255,0.03); }

.splits-table td:first-child {
  font-weight: 700;
  color: var(--blue);
  font-size: 14px;
}

.split-time { color: var(--text-primary); }
.split-pace { color: var(--green); font-weight: 600; }
.split-elapsed { color: var(--text-muted); }

/* Highlight best/worst split */
.split-best td:nth-child(3) { color: var(--green) !important; }
.split-worst td:nth-child(3) { color: var(--orange) !important; }

/* ===========================
   RESPONSIVE
   =========================== */

/* Tablet */
@media (max-width: 860px) {
  .stats-bar { gap: 0; }
  .stat-card { flex: 1 1 calc(50% - 1px); }
  .stat-card:nth-child(2n) { border-right: none; }
  .stat-card:nth-child(n+3) { border-top: 1px solid var(--border); }
  .target-card { flex: 1 1 100%; border-right: none; }
  .stat-value { font-size: 18px; }
}

/* Mobile */
@media (max-width: 540px) {
  .header { padding: 10px 14px; }
  .header h1 { font-size: 15px; }
  .status-bar { gap: 4px; }
  .status-badge { font-size: 10px; padding: 2px 8px; }

  .stats-bar { flex-direction: row; flex-wrap: wrap; }
  .stat-card { flex: 1 1 calc(50% - 1px); padding: 8px 12px; }
  .stat-card:nth-child(1) { border-right: 1px solid var(--border); }
  .stat-card:nth-child(2) { border-right: none; }
  .stat-card:nth-child(3) { border-top: 1px solid var(--border); border-right: 1px solid var(--border); }
  .stat-card:nth-child(4) { border-top: 1px solid var(--border); border-right: none; }
  .target-card { flex: 1 1 100%; border-top: 1px solid var(--border); border-right: none; }

  .stat-value { font-size: 16px; }
  .main-grid { padding: 8px; gap: 8px; }
  .splits-panel { margin: 0 8px 8px; }
  .splits-table th, .splits-table td { padding: 7px 10px; }
}

/* ===========================
   SENDER PAGE
   =========================== */
.sender-body {
  background: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 40px;
}

.sender-container {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sender-header { text-align: center; padding-top: 8px; }
.sender-header h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.sender-header p { color: var(--text-muted); font-size: 13px; }

.status-card {
  position: relative;
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  transition: border-color 0.4s, box-shadow 0.4s;
  overflow: hidden;
}
.status-card.active {
  border-color: var(--green);
  box-shadow: 0 0 32px rgba(63,185,80,0.18);
}

.big-status {
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  position: relative; z-index: 1;
}
.status-icon { font-size: 44px; }
.status-text {
  font-size: 16px; font-weight: 800;
  letter-spacing: 4px; color: var(--text-muted);
}
.status-card.active .status-text { color: var(--green); }

.pulse-ring {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  pointer-events: none;
}
.pulse-ring.pulsing { animation: pulse-border 2s ease infinite; }
@keyframes pulse-border {
  0%   { box-shadow: inset 0 0 0 0 rgba(63,185,80,0.35); }
  50%  { box-shadow: inset 0 0 0 6px rgba(63,185,80,0);   }
  100% { box-shadow: inset 0 0 0 0 rgba(63,185,80,0);     }
}

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  padding: 14px; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, filter 0.15s;
  letter-spacing: 0.3px;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none !important; filter: none !important; }
.btn-start { background: var(--green); color: #000; }
.btn-start:not(:disabled):hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn-stop  { background: var(--red); color: #fff; }
.btn-stop:not(:disabled):hover  { filter: brightness(1.12); transform: translateY(-1px); }

.info-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-label {
  font-size: 11px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
}
.info-value {
  font-family: 'SF Mono','Fira Code','Consolas',monospace;
  font-size: 12px; font-weight: 600; color: var(--text-primary);
}
.status-on  { color: var(--green) !important; }
.status-off { color: var(--text-muted) !important; }

.error-box {
  background: rgba(218,54,51,0.1); border: 1px solid var(--red);
  border-radius: 8px; padding: 11px 14px; color: var(--red);
  font-size: 13px; animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(-4px)} to{opacity:1;transform:translateY(0)} }

.sender-footer { text-align: center; }
.link-btn { color: var(--blue); text-decoration: none; font-size: 14px; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
