/* ═══════════════════════════════════════════════════
   SPEED TEST APP — Design System
   ═══════════════════════════════════════════════════ */

/* ── Google Font ─────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ── CSS Custom Properties ───────────────────────── */
:root {
  /* Palette BPS - Clean Corporate Light Mode (bps.go.id theme) */
  --bg-primary:    #f4f6f9; /* Abu-abu terang bersih khas portal BPS */
  --bg-secondary:  #ffffff; 
  --bg-card:       #ffffff;
  --bg-card-solid: #ffffff;
  --border-subtle: #e2e8f0; 
  --border-accent: #00569c; /* Biru BPS Utama */

  /* Aksen BPS Corporate Blue */
  --accent-start:  #00569c; /* Biru BPS */
  --accent-mid:    #0072c6; 
  --accent-end:    #008ce3; 
  --gradient:      linear-gradient(135deg, var(--accent-start), var(--accent-mid));

  /* Text */
  --text-primary:   #1e293b; /* Slate gelap untuk kenyamanan baca */
  --text-secondary: #475569; /* Slate medium */
  --text-dim:       #64748b;

  /* Semantic */
  --success:  #10b981; /* Hijau modern */
  --warning:  #f59e0b;
  --danger:   #ef4444;
  --info:     #00569c;

  /* Typography */
  --font:       'Inter', system-ui, -apple-system, sans-serif;
  --radius:     12px; /* Lebih minimalis dan formal */
  --radius-sm:  8px;
  --radius-lg:  16px;

  /* Shadows - Minimalist Premium Shadows */
  --shadow-card:  0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-glow:  0 0 40px rgba(0, 86, 156, 0.03);
}

/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* ── Background Decoration ───────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: none;
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ──────────────────────────────────────── */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Header ──────────────────────────────────────── */
.app-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.app-header__logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-header__logo svg {
  width: 32px;
  height: 32px;
}

.app-header__sub {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* ── Glass Card ──────────────────────────────────── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-card);
  transition: border-color 0.3s ease;
}

.card:hover {
  border-color: var(--border-accent);
}

.card + .card {
  margin-top: 1.5rem;
}

/* ── Gauge ───────────────────────────────────────── */
.gauge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0;
}

.gauge-svg {
  width: 280px;
  height: 280px;
  filter: drop-shadow(0 0 35px rgba(242, 111, 33, 0.2));
}

.gauge-bg {
  fill: none;
  stroke: #e2e8f0; /* Abu-abu terang agar nampak kontras */
  stroke-width: 16;
  stroke-linecap: round;
}

.gauge-progress {
  fill: none;
  stroke: url(#gaugeGrad);
  stroke-width: 16;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.35s ease-out;
}

.gauge-ticks line {
  stroke: #cbd5e1;
  stroke-width: 1;
}

.gauge-ticks line.major {
  stroke: #94a3b8;
  stroke-width: 2;
}

.gauge-speed-value {
  font-size: 2.6rem;
  font-weight: 900;
  fill: var(--text-primary);
  text-anchor: middle;
  letter-spacing: -0.04em;
}

.gauge-speed-unit {
  font-size: 0.9rem;
  font-weight: 500;
  fill: var(--text-secondary);
  text-anchor: middle;
}

.gauge-phase-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  fill: var(--accent-start);
  text-anchor: middle;
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  font-family: var(--font);
}

.btn-primary {
  background: var(--gradient);
  color: #fff;
  border: none;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

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

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-danger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background-color: rgba(239, 68, 68, 0.05);
}

/* ── Start Button (large) ────────────────────────── */
.start-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem; /* Reduced gap */
  padding: 0.2rem 0; /* Reduced padding */
}

.btn-start {
  padding: 0.85rem 3.5rem;
  height: 52px;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  background: var(--gradient);
  color: #fff;
  border: none;
  box-shadow:
    0 4px 15px rgba(242, 111, 33, 0.25),
    0 1px 2px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-family: var(--font);
}

.btn-start:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    0 6px 20px rgba(242, 111, 33, 0.4),
    0 2px 4px rgba(0,0,0,0.15);
}

.btn-start:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* ── Phase Indicator ─────────────────────────────── */
.phase-bar {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 1.5rem 0;
}

.phase-dot {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: color 0.3s ease;
}

.phase-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all 0.3s ease;
}

.phase-dot.active {
  color: var(--accent-start);
}

.phase-dot.active::before {
  background: var(--accent-start);
  box-shadow: 0 0 10px var(--accent-start);
  animation: pulseDot 1.2s infinite;
}

.phase-dot.done {
  color: var(--success);
}

.phase-dot.done::before {
  background: var(--success);
}

/* ── Results Grid ────────────────────────────────── */
.results-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: 1.5rem;
}

.result-card {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  transition: all 0.3s ease;
  animation: fadeUp 0.5s ease-out both;
}

.result-card:hover {
  border-color: var(--border-accent);
  background: rgba(242, 111, 33, 0.03);
}

.result-card__icon {
  font-size: 1.4rem;
  margin-bottom: 0.3rem;
}

.result-card__label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

.result-card__value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0.15rem 0;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-card__unit {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ── Geo Info ────────────────────────────────────── */
.geo-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.geo-panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.geo-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.geo-source--gps {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.geo-source--ip {
  background: rgba(0, 86, 156, 0.08);
  color: var(--accent-start);
  border: 1px solid rgba(0, 86, 156, 0.2);
}

.geo-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.geo-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
}

.geo-item__icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.geo-item__content {
  min-width: 0;
}

.geo-item__label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.geo-item__value {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── hCaptcha Container ──────────────────────────── */
.captcha-wrapper {
  display: flex;
  justify-content: center;
  margin: 0.2rem 0; /* Reduced margin */
  min-height: 78px;
}

/* ── Status Text ─────────────────────────────────── */
.status-text {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
  min-height: 1.4em;
}

/* ═══════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════ */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
  font-family: var(--font);
  color: var(--text-primary);
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.form-group input:focus {
  border-color: var(--accent-end);
  box-shadow: 0 0 0 3px rgba(242, 111, 33, 0.1);
}

.form-error {
  color: var(--danger);
  font-size: 0.82rem;
  text-align: center;
  margin-bottom: 1rem;
  min-height: 1.2em;
}

.login-card .btn-primary {
  width: 100%;
  margin-top: 0.5rem;
}

/* ═══════════════════════════════════════════════════
   ADMIN DASHBOARD
   ═══════════════════════════════════════════════════ */
.admin-container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.admin-header__title {
  font-size: 1.4rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.admin-header__actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Stats overview cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1.2rem;
  transition: border-color 0.3s;
}

.stat-card:hover {
  border-color: var(--border-accent);
}

.stat-card__label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

.stat-card__value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 0.25rem;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-card__sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  align-items: end;
}

.filter-bar .form-group {
  margin-bottom: 0;
  flex: 1;
  min-width: 140px;
}

.filter-bar .form-group label {
  margin-bottom: 0.25rem;
}

.filter-bar .form-group input,
.filter-bar .form-group select {
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
}

.filter-bar .form-group select {
  width: 100%;
  font-family: var(--font);
  color: var(--text-primary);
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  outline: none;
}

/* Data table */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card-solid);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
  color: var(--text-secondary);
  padding: 0.8rem 0.75rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  color: var(--text-primary);
}

.data-table tbody tr {
  transition: background 0.2s;
}

.data-table tbody tr:hover {
  background: rgba(99,102,241,0.04);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.pagination button {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--accent-mid);
  background: rgba(99,102,241,0.08);
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pagination button.active {
  background: var(--gradient);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.pagination__info {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Chart container */
.chart-section {
  margin-top: 2rem;
}

.chart-section h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.chart-bar-container {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 0.5rem 0;
}

.chart-bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 70px;
  gap: 1rem;
  align-items: center;
  font-size: 0.82rem;
  padding: 0.25rem 0;
  transition: transform 0.2s ease;
}

.chart-bar-row:hover {
  transform: translateX(4px);
}

.chart-bar-label {
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.chart-bar-track {
  height: 12px;
  border-radius: 9999px;
  background: #f1f5f9;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chart-bar-fill {
  height: 100%;
  border-radius: 9999px;
  background: var(--gradient);
  transition: width 1s cubic-bezier(0.1, 0.8, 0.2, 1);
  min-width: 4px;
}

.chart-bar-value {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.82rem;
}

/* ═══════════════════════════════════════════════════
   Utilities & Animations
   ═══════════════════════════════════════════════════ */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

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

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.4); }
}

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

.fade-in {
  animation: fadeUp 0.5s ease-out both;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 600px) {
  .app-container { padding: 1.5rem 1rem 3rem; }

  .gauge-svg { width: 220px; height: 220px; }

  .gauge-speed-value { font-size: 2.0rem; }

  .results-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }

  .result-card { padding: 0.8rem; }
  .result-card__value { font-size: 1.4rem; }

  .geo-info { grid-template-columns: 1fr; }

  .btn-start { width: 100%; max-width: 250px; height: 48px; border-radius: 10px; font-size: 1.1rem; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .filter-bar { flex-direction: column; }

  .admin-header { flex-direction: column; align-items: flex-start; }

  .chart-bar-row { grid-template-columns: 80px 1fr 50px; }
}
