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

:root {
  --bg:            #0d0f12;
  --surface:       rgba(255,255,255,.04);
  --surface-hover: rgba(255,255,255,.07);
  --border:        rgba(255,255,255,.07);
  --border-focus:  rgba(79,195,247,.4);

  --text-primary:   #e8eaed;
  --text-secondary: rgba(232,234,237,.5);
  --text-muted:     rgba(232,234,237,.3);

  --accent-blue:   #4fc3f7;
  --accent-purple: #7c4dff;
  --accent-green:  #69f0ae;
  --accent-red:    #ff5252;
  --accent-amber:  #ffd740;

  --grad: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));

  --sidebar-w: 220px;
  --radius:    14px;
  --radius-sm: 8px;

  --font:      'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Background blobs ────────────────────────────────────────────────────── */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .12; animation: drift 18s ease-in-out infinite alternate; }
.blob-1 { width: 520px; height: 520px; background: var(--accent-blue);   top: -120px; left: -80px;   animation-duration: 20s; }
.blob-2 { width: 400px; height: 400px; background: var(--accent-purple); bottom: -80px; right: 40px; animation-duration: 25s; animation-delay: -8s; }
.blob-3 { width: 300px; height: 300px; background: var(--accent-green);  top: 40%; left: 40%;        animation-duration: 22s; animation-delay: -4s; }
@keyframes drift { from { transform: translate(0,0) scale(1); } to { transform: translate(40px,30px) scale(1.08); } }

/* ── Shell ───────────────────────────────────────────────────────────────── */
.shell { position: relative; z-index: 1; display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 28px 16px 24px;
  border-right: 1px solid var(--border);
  background: rgba(13,15,18,.7);
  backdrop-filter: blur(20px);
  gap: 32px;
}

.logo { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.logo-text { font-size: 15px; font-weight: 500; letter-spacing: -.01em; }
.logo-text em { font-style: normal; background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.nav-links { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary);
  font-family: var(--font); font-size: 13.5px; font-weight: 400;
  cursor: pointer; transition: background .15s, color .15s; text-align: left;
}
.nav-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.nav-btn.active { background: var(--surface-hover); color: var(--text-primary); position: relative; }
.nav-btn.active::before {
  content: ''; position: absolute; left: 0; top: 25%; bottom: 25%;
  width: 3px; border-radius: 99px; background: var(--grad);
}
.nav-btn svg { opacity: .7; flex-shrink: 0; }
.nav-btn.active svg { opacity: 1; }

/* Desktop: show text inline, hide mobile span */
.nav-label { display: inline; }

.sidebar-footer {
  margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 0 4px;
  color: var(--text-muted); font-size: 11.5px; font-family: var(--font-mono);
}
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent-green);
  animation: pulse-ring 2s ease-out infinite;
}
@keyframes pulse-ring {
  0%  { box-shadow: 0 0 0 0 rgba(105,240,174,.4); }
  70% { box-shadow: 0 0 0 6px rgba(105,240,174,0); }
  100%{ box-shadow: 0 0 0 0 rgba(105,240,174,0); }
}

/* ── Main ────────────────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; padding: 36px 40px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.tab { display: none; animation: fade-in .2s ease; }
.tab.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 500; letter-spacing: -.02em; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px;
  backdrop-filter: blur(12px);
}
.card-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin-bottom: 12px;
}
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card-trip { padding: 24px; }
.trip-state { font-size: 20px; font-weight: 500; margin-bottom: 4px; letter-spacing: -.01em; }
.trip-state.below  { color: var(--accent-green); }
.trip-state.above  { color: var(--accent-red); }
.trip-state.unknown{ color: var(--text-muted); }
.trip-route { font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono); }

/* ── Chart ───────────────────────────────────────────────────────────────── */
.card-chart { padding: 18px 20px; }
.chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-header .card-label { margin-bottom: 0; }
.chart-wrap { position: relative; height: 130px; margin-bottom: 14px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* Trend arrow */
.trend-icon { font-size: 20px; font-weight: 700; line-height: 1; }
.trend-icon.up   { color: var(--accent-red); }
.trend-icon.down { color: var(--accent-green); }
.trend-icon.flat { color: var(--text-muted); }

/* Stat pills */
.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  flex: 1; min-width: 60px;
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.pill-label { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.pill-value { font-size: 14px; font-family: var(--font-mono); font-weight: 400; color: var(--text-primary); }
.pill-value.green { color: var(--accent-green); }
.pill-value.red   { color: var(--accent-red); }
.pill-value.muted { color: var(--text-secondary); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-card { padding: 0; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  text-align: left; padding: 10px 14px; color: var(--text-muted);
  font-weight: 400; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); color: var(--text-secondary); white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-hover); color: var(--text-primary); }
.data-table td.state-below { color: var(--accent-green); }
.data-table td.state-above { color: var(--accent-red); }
.data-table td.dir { color: var(--text-primary); font-weight: 500; font-family: var(--font); }
.data-table td.avg { color: var(--accent-blue); }
.compact th, .compact td { padding: 8px 12px; }
.table-hint { text-align: center; color: var(--text-muted); font-size: 12px; padding: 14px 0 6px; }

/* ── Log controls ────────────────────────────────────────────────────────── */
.log-controls { display: flex; gap: 10px; align-items: center; }
.search-input, .select-input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font); font-size: 13px; padding: 7px 12px;
  outline: none; transition: border-color .15s;
}
.search-input:focus, .select-input:focus { border-color: var(--border-focus); }
.search-input { min-width: 160px; }
.select-input { cursor: pointer; }
.select-input option { background: #1a1d21; }

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 400; margin-bottom: 16px; }
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field span { font-size: 11.5px; color: var(--text-secondary); }
.field input {
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font-mono); font-size: 13px; padding: 9px 12px;
  outline: none; transition: border-color .15s, background .15s; width: 100%;
}
.field input:focus { border-color: var(--border-focus); background: rgba(79,195,247,.05); }
.form-actions { display: flex; align-items: center; gap: 16px; padding-top: 4px; }
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  border: none; border-radius: var(--radius-sm); background: var(--grad);
  color: #fff; font-family: var(--font); font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: opacity .15s, transform .1s;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:active { transform: scale(.98); }
#save-status { font-size: 12px; color: var(--text-muted); }
#save-status.ok  { color: var(--accent-green); }
#save-status.err { color: var(--accent-red); }

/* ── Refresh btn ─────────────────────────────────────────────────────────── */
.btn-refresh {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text-secondary); cursor: pointer; transition: background .15s, color .15s;
}
.btn-refresh:hover { background: var(--surface-hover); color: var(--text-primary); }
.btn-refresh.spinning svg { animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .shell { flex-direction: column; }

  /* Sidebar becomes fixed bottom nav */
  .sidebar {
    width: 100%; height: 62px;
    flex-direction: row; order: 2;
    padding: 0; gap: 0;
    border-right: none; border-top: 1px solid var(--border);
    background: rgba(13,15,18,.94);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  }
  .logo          { display: none; }
  .sidebar-footer{ display: none; }

  .nav-links { flex-direction: row; width: 100%; gap: 0; }
  .nav-links li  { flex: 1; }

  .nav-btn {
    flex-direction: column; justify-content: center; align-items: center;
    gap: 3px; width: 100%; height: 62px;
    padding: 6px 4px; border-radius: 0; font-size: 10px;
    color: var(--text-muted);
  }
  .nav-btn.active { color: var(--text-primary); background: transparent; }
  .nav-btn.active::before {
    top: 0; bottom: auto; left: 20%; right: 20%;
    width: auto; height: 2px; border-radius: 0 0 99px 99px;
  }

  /* Nav label: hide on desktop (shown inline), show as block on mobile */
  .nav-label { display: block; font-size: 10px; }

  .main { flex: 1; order: 1; padding: 16px 14px 80px; overflow-y: auto; }

  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 18px; }

  .cards { grid-template-columns: 1fr; gap: 10px; margin-bottom: 10px; }
  .card  { padding: 14px 16px; margin-bottom: 10px; }
  .card-trip { padding: 16px; }
  .trip-state { font-size: 17px; }

  /* Charts: taller on mobile for readability */
  .chart-wrap { height: 150px; }
  .stat-pills { gap: 6px; }
  .pill { padding: 7px 8px; min-width: 0; }
  .pill-value { font-size: 13px; }

  /* Tables: scroll horizontally inside container only */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #log-table  { min-width: 640px; }
  .data-table.compact { min-width: unset; width: 100%; }

  /* Log controls: stack */
  .log-controls { flex-direction: column; align-items: stretch; gap: 8px; }
  .search-input  { min-width: unset; width: 100%; }
  .select-input  { width: 100%; }

  /* Settings: single column, 16px inputs prevent iOS zoom */
  .settings-group { padding: 14px; }
  .fields-grid    { grid-template-columns: 1fr; gap: 10px; }
  .field input    { font-size: 16px; }

  .blob { opacity: .07; filter: blur(60px); }
}

@media (max-width: 360px) {
  .nav-label { display: none; }
}
