/* ═══════════════════════════════════════════════════════════
   DESIGN SYSTEM – Dark Motorsport Aesthetic
════════════════════════════════════════════════════════════ */
:root {
  --bg-base:    #09090f;
  --bg-card:    #111119;
  --bg-glass:   rgba(255,255,255,0.03);
  --bg-hover:   rgba(255,255,255,0.06);
  --border:     rgba(255,255,255,0.08);
  --accent:     #ff5c1a;
  --accent-dim: rgba(255,92,26,0.15);
  --accent2:    #00d4ff;
  --accent2-dim:rgba(0,212,255,0.12);
  --success:    #00e676;
  --warning:    #ffab40;
  --text-1:     #f0f0f8;
  --text-2:     #8888aa;
  --text-3:     #555570;
  --font-head:  'Syne', sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
  --radius:     12px;
  --radius-lg:  20px;
  --sidebar-w:  260px;
  --topbar-h:   60px;
  --shadow-card: 0 4px 24px rgba(0,0,0,0.5);
  --glow-accent: 0 0 20px rgba(255,92,26,0.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font-head); background: var(--bg-base); color: var(--text-1); overflow: hidden; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-3); border-radius: 2px; }

/* ── PAGES ─────────────────────────────────────────────────── */
.page { display: none; height: 100vh; }
.page.active { display: flex; }

/* ═══════════ AUTH PAGE ════════════════════════════════════ */
#auth-page {
  align-items: center; justify-content: center;
  background: var(--bg-base);
  position: relative; overflow: hidden;
}
#auth-page::before {
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 30% 50%, rgba(255,92,26,0.08) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 80% 30%, rgba(0,212,255,0.06) 0%, transparent 70%);
}
.auth-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  max-width: 960px; width: 100%; margin: auto; z-index:1;
}
.auth-brand {
  display: flex; flex-direction: column; justify-content: center;
  padding: 60px 50px;
}
.auth-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 48px;
}
.auth-logo-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: var(--glow-accent);
}
.auth-logo-text { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.auth-logo-text span { color: var(--accent); }
.auth-tagline { font-size: 38px; font-weight: 800; line-height: 1.15; letter-spacing: -1px; color: var(--text-1); }
.auth-tagline em { font-style: normal; color: var(--accent); }
.auth-sub { margin-top: 16px; color: var(--text-2); font-size: 15px; font-weight: 400; }
.auth-features { margin-top: 40px; display: flex; flex-direction: column; gap: 12px; }
.auth-feat { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.auth-feat i { color: var(--accent); font-size: 16px; }

.auth-form-wrap {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 48px 40px;
  display: flex; flex-direction: column; justify-content: center;
}
.auth-tabs { display: flex; gap: 4px; margin-bottom: 36px; background: var(--bg-base); border-radius: 8px; padding: 4px; }
.auth-tab {
  flex: 1; padding: 8px; border: none; background: transparent;
  color: var(--text-2); border-radius: 6px; cursor: pointer;
  font-family: var(--font-head); font-size: 14px; font-weight: 600; transition: all .2s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.form-group { margin-bottom: 20px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: .5px; text-transform: uppercase; margin-bottom: 8px; display: block; }
.form-control {
  background: var(--bg-base); border: 1px solid var(--border);
  color: var(--text-1); border-radius: 8px; padding: 12px 14px;
  font-family: var(--font-head); font-size: 14px; width: 100%; transition: border-color .2s;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-control::placeholder { color: var(--text-3); }
.btn-primary-custom {
  width: 100%; padding: 13px; background: var(--accent); border: none;
  border-radius: 8px; color: #fff; font-family: var(--font-head); font-weight: 700;
  font-size: 15px; cursor: pointer; transition: all .2s; box-shadow: var(--glow-accent);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary-custom:hover { filter: brightness(1.1); transform: translateY(-1px); }
.auth-error { color: #ff6b6b; font-size: 13px; margin-top: 12px; text-align: center; display: none; }

/* ═══════════ APP SHELL ════════════════════════════════════ */
#app-page { flex-direction: row; }

/* ── SIDEBAR ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); height: 100vh; background: var(--bg-card);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  flex-shrink: 0; position: relative; z-index: 100;
}
.sidebar-logo {
  height: var(--topbar-h); display: flex; align-items: center; padding: 0 20px; gap: 10px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 34px; height: 34px; background: var(--accent); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  box-shadow: var(--glow-accent); flex-shrink: 0;
}
.sidebar-logo-text { font-size: 18px; font-weight: 800; letter-spacing: -.5px; }
.sidebar-logo-text span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-3); padding: 0 8px; margin: 16px 0 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; cursor: pointer; transition: all .15s; color: var(--text-2);
  font-size: 14px; font-weight: 600; user-select: none; position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: var(--accent); border-radius: 0 2px 2px 0;
}
.nav-item i { font-size: 16px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 10px;
}
.nav-badge.online { background: var(--success); }

.sidebar-user {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
  font-size: 14px; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-3); }
.user-logout { color: var(--text-3); cursor: pointer; transition: color .15s; }
.user-logout:hover { color: var(--accent); }

/* ── MAIN AREA ─────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h); background: var(--bg-card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px; flex-shrink: 0;
}
.topbar-title { font-size: 18px; font-weight: 800; flex: 1; }
.topbar-badge {
  background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(255,92,26,.3);
  padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 5px;
}
.live-dot {
  width: 7px; height: 7px; background: var(--success); border-radius: 50%;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.5;transform:scale(.8)} }

.content-area { flex: 1; overflow-y: auto; overflow-x: hidden; }

/* ── SECTION PANELS ─────────────────────────────────────────── */
.section { display: none; padding: 24px; }
.section.active { display: block; }

/* ── MAP ────────────────────────────────────────────────────── */
#map-section { padding: 0; position: relative; height: 100%; }
#map { height: 100%; width: 100%; z-index: 1; }
.map-overlay {
  position: absolute; z-index: 1000; top: 16px; left: 16px; right: 16px;
  display: flex; gap: 10px; pointer-events: none;
}
.map-overlay > * { pointer-events: all; }
.map-control-card {
  background: rgba(9,9,15,0.92); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.map-tracker-panel { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.map-tracker-item {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 8px; border-radius: 8px; transition: background .15s;
}
.map-tracker-item:hover { background: var(--bg-hover); }
.tracker-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tracker-info-mini { flex: 1; }
.tracker-name-mini { font-size: 13px; font-weight: 700; }
.tracker-speed-mini { font-size: 11px; color: var(--text-2); font-family: var(--font-mono); }

.map-info-panel { flex: 1; }
.speed-display {
  font-size: 40px; font-weight: 800; font-family: var(--font-mono);
  line-height: 1; color: var(--accent);
}
.speed-display span { font-size: 14px; font-weight: 400; color: var(--text-2); margin-left: 4px; }
.coord-display { font-size: 11px; font-family: var(--font-mono); color: var(--text-2); margin-top: 4px; }

/* ── STATS CARDS ───────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; position: relative; overflow: hidden; transition: border-color .2s;
}
.stat-card:hover { border-color: var(--accent); }
.stat-card::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 10px; background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--accent); margin-bottom: 16px;
}
.stat-icon.blue { background: var(--accent2-dim); color: var(--accent2); }
.stat-icon.green { background: rgba(0,230,118,.12); color: var(--success); }
.stat-icon.yellow { background: rgba(255,171,64,.12); color: var(--warning); }
.stat-value { font-size: 28px; font-weight: 800; font-family: var(--font-mono); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

/* ── TABLE ─────────────────────────────────────────────────── */
.card-custom {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 700; }
.table-custom { width: 100%; border-collapse: collapse; }
.table-custom th {
  padding: 12px 20px; font-size: 11px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-3); border-bottom: 1px solid var(--border);
  text-align: left; white-space: nowrap;
}
.table-custom td { padding: 14px 20px; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.table-custom tr:last-child td { border-bottom: none; }
.table-custom tr:hover td { background: var(--bg-hover); }

/* ── BADGES ─────────────────────────────────────────────────── */
.badge-custom {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.badge-online { background: rgba(0,230,118,.15); color: var(--success); border: 1px solid rgba(0,230,118,.3); }
.badge-offline { background: rgba(255,255,255,.06); color: var(--text-3); border: 1px solid var(--border); }
.badge-admin { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(255,92,26,.3); }
.badge-user { background: var(--accent2-dim); color: var(--accent2); border: 1px solid rgba(0,212,255,.3); }

/* ── FILTER BAR ─────────────────────────────────────────────── */
.filter-bar {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px;
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-label { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; }
.filter-control {
  background: var(--bg-base); border: 1px solid var(--border);
  color: var(--text-1); border-radius: 8px; padding: 8px 12px;
  font-family: var(--font-head); font-size: 13px; cursor: pointer;
}
.filter-control:focus { outline: none; border-color: var(--accent); }
select.filter-control option { background: var(--bg-card); }

/* ── BTN ─────────────────────────────────────────────────────── */
.btn-accent {
  background: var(--accent); border: none; color: #fff; border-radius: 8px;
  padding: 9px 16px; font-family: var(--font-head); font-weight: 700; font-size: 13px;
  cursor: pointer; transition: all .2s; display: inline-flex; align-items: center; gap: 6px;
}
.btn-accent:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text-2);
  border-radius: 8px; padding: 8px 14px; font-family: var(--font-head); font-weight: 600;
  font-size: 13px; cursor: pointer; transition: all .2s; display: inline-flex; align-items: center; gap: 6px;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  background: transparent; border: 1px solid rgba(255,107,107,.3); color: #ff6b6b;
  border-radius: 8px; padding: 6px 12px; font-family: var(--font-head); font-weight: 600;
  font-size: 12px; cursor: pointer; transition: all .2s;
}
.btn-danger:hover { background: rgba(255,107,107,.1); }

/* ── HISTORY MAP ─────────────────────────────────────────────── */
#history-map { height: 400px; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 20px; }

/* ── ADMIN ─────────────────────────────────────────────────── */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; width: fit-content; }
.admin-tab {
  padding: 8px 16px; border: none; background: transparent; color: var(--text-2);
  border-radius: 8px; cursor: pointer; font-family: var(--font-head); font-size: 13px; font-weight: 600; transition: all .2s;
}
.admin-tab.active { background: var(--accent); color: #fff; }

/* ── MODAL ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7);
  z-index: 9999; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px; width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 24px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ── TOAST ─────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 99999;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 20px; display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 600; transform: translateY(100px); opacity: 0;
  transition: all .3s; max-width: 340px; box-shadow: var(--shadow-card);
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-color: rgba(0,230,118,.4); }
#toast.error { border-color: rgba(255,107,107,.4); }

/* ── TRACKER CARD ─────────────────────────────────────────────── */
.tracker-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tracker-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; position: relative; transition: border-color .2s, transform .2s; cursor: pointer;
}
.tracker-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tracker-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.tracker-card-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.tracker-card-name { font-size: 15px; font-weight: 700; }
.tracker-card-imei { font-size: 11px; font-family: var(--font-mono); color: var(--text-3); }
.tracker-card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tc-stat-label { font-size: 11px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.tc-stat-value { font-size: 18px; font-weight: 800; font-family: var(--font-mono); margin-top: 2px; }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .auth-grid { grid-template-columns: 1fr; max-width: 420px; }
  .auth-brand { display: none; }
  .sidebar { width: 60px; }
  .sidebar-logo-text, .nav-item span, .user-info, .nav-section-label, .nav-badge { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
}