:root{
  --primary:#0F2A5F;
  --secondary:#1D4ED8;
  --accent:#38BDF8;
  --sidebar:#0B1F46;
  --topbar:#153E7E;
  --page-bg:#EFF6FF;
  --card-bg:#FFFFFF;
  --text:#0F172A;
  --muted:#64748B;
  --thead:#1E3A8A;
  --border:#BBD7FF;
  --success:#16A34A;
  --warning:#F59E0B;
  --danger:#EF4444;
  --sidebar-w:250px;
  --topbar-h:56px;
}
html,body{height:100%}
body{background:var(--page-bg);color:var(--text);font-family:"Segoe UI",system-ui,-apple-system,Roboto,Arial,sans-serif;font-size:.9rem}
a{text-decoration:none}

/* ---------- Shell ---------- */
.app-shell{display:flex;min-height:100vh}
.sidebar{position:fixed;top:var(--topbar-h);left:0;bottom:0;width:var(--sidebar-w);background:linear-gradient(180deg,var(--sidebar),#081735);overflow-y:auto;z-index:1030;padding:10px 10px 30px;scrollbar-width:thin;transition:transform .2s ease}
.main{flex:1;margin-left:var(--sidebar-w);min-width:0;display:flex;flex-direction:column}
.content{padding:16px;flex:1}

.nav-section{color:#9DDFFF;text-transform:uppercase;font-size:.68rem;font-weight:800;letter-spacing:.08em;margin:14px 6px 6px}
.nav-section:first-child{margin-top:4px}
.sidebar .nav-link{display:flex;align-items:center;gap:10px;width:100%;color:#E2E8F0;font-weight:700;padding:8px 10px;margin-bottom:5px;border-radius:12px;background:linear-gradient(135deg,rgba(255,255,255,.075),rgba(255,255,255,.025));border:1px solid rgba(255,255,255,.10);box-shadow:0 7px 16px rgba(0,0,0,.18),inset 0 1px 0 rgba(255,255,255,.10);transition:.15s ease;text-align:left}
.sidebar .nav-link:hover,.sidebar .nav-link:focus{color:#fff;background:linear-gradient(135deg,rgba(79,70,229,.68),rgba(6,182,212,.52));border-color:rgba(125,211,252,.38);transform:translateY(-1px)}
.sidebar .nav-link.active{color:#0F172A;background:linear-gradient(135deg,#7DD3FC,#38BDF8);border-color:#BAE6FD;box-shadow:0 8px 20px rgba(56,189,248,.35)}
.sidebar .nav-link.active-parent{border-color:rgba(125,211,252,.45)}
.nav-icon{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:9px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.14);font-size:.85rem;flex:0 0 auto}
.nav-link.active .nav-icon{background:rgba(255,255,255,.45)}
.nav-caret{margin-left:auto;color:#94a3b8;transition:.18s ease}
.nav-group-toggle[aria-expanded="true"] .nav-caret{transform:rotate(180deg)}
.nav-submenu{margin:0 0 6px 14px;padding-left:10px;border-left:1px dashed rgba(157,223,255,.35)}
.sidebar .nav-submenu .nav-sublink{font-weight:600;font-size:.84rem;padding:6px 10px;margin-bottom:4px}
.sidebar-backdrop{display:none}

/* ---------- Topbar ---------- */
.topbar{position:sticky;top:0;z-index:1040;display:flex;height:var(--topbar-h);margin-left:calc(var(--sidebar-w) * -1)}
.topbar-brand{width:var(--sidebar-w);flex:0 0 var(--sidebar-w);display:flex;align-items:center;gap:10px;padding:0 16px;background:var(--sidebar);color:#fff;border-bottom:1px solid rgba(255,255,255,.08)}
.topbar-logo{width:30px;height:30px;border-radius:9px;box-shadow:0 0 12px rgba(56,189,248,.45)}
.brand-name{font-weight:800;font-size:1.05rem;letter-spacing:.02em;color:#7DD3FC}
.topbar-main{flex:1;display:flex;align-items:center;gap:10px;padding:0 14px;background:linear-gradient(90deg,var(--topbar),#1B4B94);color:#fff;box-shadow:0 4px 14px rgba(15,23,42,.18);min-width:0}
.topbar-title{min-width:0}
.topbar-title h1{font-size:1rem;font-weight:800;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.topbar-title small{color:#BFDBFE;font-size:.72rem}
.topbar-right{margin-left:auto;display:flex;align-items:center;gap:6px}
.topbar-btn{width:34px;height:34px;display:inline-flex;align-items:center;justify-content:center;border-radius:10px;color:#fff;background:rgba(255,255,255,.12);border:1px solid rgba(255,255,255,.18)}
.topbar-btn:hover{color:#fff;background:rgba(255,255,255,.25)}
.topbar-btn-logout:hover{background:var(--danger)}
.topbar-live{align-items:center;gap:6px;font-size:.75rem;font-weight:700;padding:5px 10px;border-radius:999px;background:rgba(255,255,255,.12);margin-right:4px}
.live-dot{width:8px;height:8px;border-radius:50%;background:#22C55E;box-shadow:0 0 0 0 rgba(34,197,94,.7);animation:pulse 1.8s infinite}
.topbar-live.is-error .live-dot{background:var(--danger);animation:none}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(34,197,94,.7)}70%{box-shadow:0 0 0 8px rgba(34,197,94,0)}100%{box-shadow:0 0 0 0 rgba(34,197,94,0)}}

/* ---------- Cards / stat ---------- */
.card{border:1px solid rgba(15,23,42,.08);border-radius:14px;box-shadow:0 6px 18px rgba(15,42,95,.06);background:var(--card-bg)}
.card-header{background:transparent;border-bottom:1px solid rgba(15,23,42,.07);font-weight:800;display:flex;align-items:center;gap:8px;padding:10px 14px}
.card-header .card-tools{margin-left:auto;display:flex;gap:6px;align-items:center}
.stat-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));gap:12px;margin-bottom:16px}
.stat-card{border-radius:14px;padding:14px;display:flex;align-items:center;gap:12px;border:1px solid rgba(15,23,42,.06);box-shadow:0 6px 16px rgba(15,42,95,.06)}
.stat-card .stat-icon{width:42px;height:42px;border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:1.25rem;background:rgba(255,255,255,.6)}
.stat-card span{display:block;font-size:.75rem;font-weight:700;opacity:.85}
.stat-card strong{display:block;font-size:1.45rem;line-height:1.1}
.stat-1{background:#DBEAFE;color:#1E3A8A}
.stat-2{background:#DCFCE7;color:#166534}
.stat-3{background:#F1F5F9;color:#334155}
.stat-4{background:#E0F2FE;color:#0C4A6E}
.stat-5{background:#FEF3C7;color:#92400E}
.stat-6{background:#FCE7F3;color:#9D174D}

/* ---------- Tables ---------- */
.table-card .table{margin:0}
.table thead th{background:var(--thead);color:#fff;font-weight:700;font-size:.78rem;text-transform:uppercase;letter-spacing:.03em;border-color:#1E3A8A;white-space:nowrap;vertical-align:middle}
.table tbody td{vertical-align:middle;border-color:#E2ECFA}
.table-striped>tbody>tr:nth-of-type(odd)>*{--bs-table-accent-bg:#F8FBFF}
.table-hover>tbody>tr:hover>*{--bs-table-accent-bg:#EAF4FF}
.table-responsive{border-radius:0 0 14px 14px}
.table-actions{white-space:nowrap;text-align:right}
.table-actions .btn{width:28px;height:28px;padding:0;display:inline-flex;align-items:center;justify-content:center;border-radius:8px}
.toolbar{display:flex;flex-wrap:wrap;gap:8px;align-items:center;padding:10px 14px;background:#DBEAFE;border-bottom:1px solid var(--border)}
.toolbar .form-control,.toolbar .form-select{max-width:240px}
.empty-row td{text-align:center;color:var(--muted);padding:26px!important}

.badge-status{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:999px;font-size:.72rem;font-weight:800}
.badge-status::before{content:"";width:7px;height:7px;border-radius:50%;background:currentColor}
.st-online{background:#DCFCE7;color:#15803D}
.st-offline{background:#FEE2E2;color:#B91C1C}
.st-unknown{background:#F1F5F9;color:#475569}
.st-moving{background:#DBEAFE;color:#1D4ED8}
.st-stopped{background:#FEF3C7;color:#B45309}

.btn{border-radius:10px;font-weight:600}
.btn-primary{background:var(--secondary);border-color:var(--secondary)}
.form-label{font-weight:700;font-size:.8rem;margin-bottom:3px}
.form-control,.form-select{border-radius:10px}
.modal-content{border-radius:16px;border:1px solid #BFDBFE}
.modal-header{background:#DBEAFE;border-radius:16px 16px 0 0}
.modal-title{font-weight:800;font-size:1rem}
.section-label{font-size:.72rem;font-weight:800;text-transform:uppercase;color:var(--secondary);letter-spacing:.06em;border-bottom:1px dashed #BFDBFE;padding-bottom:3px;margin:6px 0 2px}

/* ---------- Map ---------- */
.map-box{height:420px;border-radius:0 0 14px 14px}
.leaflet-container{font-family:inherit}
.vehicle-marker{display:flex;align-items:center;justify-content:center}
.vehicle-marker .vm-arrow{width:30px;height:30px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;border:2px solid #fff;box-shadow:0 3px 10px rgba(0,0,0,.35);font-size:14px}
.vm-online .vm-arrow{background:#16A34A}
.vm-moving .vm-arrow{background:#1D4ED8}
.vm-offline .vm-arrow{background:#94A3B8}
.vehicle-label{background:rgba(15,23,42,.85);color:#fff;border:0;border-radius:6px;font-weight:700;font-size:.72rem;padding:2px 6px;box-shadow:none}
.vehicle-label::before{display:none}
.popup-table td{padding:1px 6px 1px 0;font-size:.78rem}
.popup-table td:first-child{color:var(--muted)}
.popup-title{font-weight:800;font-size:.9rem;margin-bottom:4px}

/* Peta live full */
.page-map .content{padding:0}
.live-wrap{display:flex;height:calc(100vh - var(--topbar-h))}
.live-list{width:320px;flex:0 0 320px;background:#fff;border-right:1px solid var(--border);display:flex;flex-direction:column}
.live-list-head{padding:10px;background:#DBEAFE;border-bottom:1px solid var(--border)}
.live-filter{display:flex;gap:4px;margin-top:8px}
.live-filter .btn{flex:1;font-size:.72rem;padding:3px 4px}
.live-items{overflow-y:auto;flex:1}
.live-item{padding:9px 12px;border-bottom:1px solid #EEF2F7;cursor:pointer;display:flex;gap:10px;align-items:center}
.live-item:hover{background:#F1F7FF}
.live-item.selected{background:#DBEAFE}
.live-item .li-icon{width:34px;height:34px;border-radius:10px;display:flex;align-items:center;justify-content:center;color:#fff;flex:0 0 auto}
.live-item .li-name{font-weight:800;font-size:.86rem}
.live-item .li-sub{font-size:.72rem;color:var(--muted)}
.live-item .li-speed{margin-left:auto;text-align:right;font-weight:800;font-size:.85rem;white-space:nowrap}
.live-item .li-speed small{display:block;font-weight:600;font-size:.68rem;color:var(--muted)}
.live-map{flex:1;position:relative}
.live-map #liveMap{position:absolute;inset:0}
.live-detail{position:absolute;right:12px;top:12px;z-index:500;width:300px;background:#fff;border-radius:14px;box-shadow:0 10px 30px rgba(0,0,0,.2);display:none}
.live-detail.show{display:block}
.live-detail .ld-head{padding:10px 12px;background:var(--topbar);color:#fff;border-radius:14px 14px 0 0;display:flex;align-items:center;gap:8px}
.live-detail .ld-body{padding:10px 12px}
.live-detail .ld-grid{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.live-detail .ld-grid div{background:#F1F7FF;border-radius:8px;padding:6px 8px}
.live-detail .ld-grid span{display:block;font-size:.66rem;color:var(--muted);font-weight:700}
.live-detail .ld-grid b{font-size:.85rem}

/* Riwayat */
.history-wrap{display:grid;grid-template-columns:320px 1fr;gap:12px}
.history-map{height:calc(100vh - var(--topbar-h) - 32px);min-height:420px;border-radius:14px}
.playback{display:flex;gap:8px;align-items:center}
.playback input[type=range]{flex:1}

/* ---------- Toast ---------- */
.toast-stack{position:fixed;right:16px;bottom:16px;z-index:2000;display:flex;flex-direction:column;gap:8px}
.app-toast{min-width:240px;max-width:360px;padding:10px 14px;border-radius:12px;color:#fff;font-weight:600;box-shadow:0 10px 24px rgba(0,0,0,.2);animation:toastIn .2s ease}
.app-toast.ok{background:#16A34A}.app-toast.err{background:#DC2626}.app-toast.info{background:#1D4ED8}
@keyframes toastIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}

.loading-overlay{position:absolute;inset:0;background:rgba(255,255,255,.6);display:flex;align-items:center;justify-content:center;z-index:600}

/* ---------- Login ---------- */
.login-page{background:radial-gradient(circle at 20% 20%,#1D4ED8 0,transparent 40%),radial-gradient(circle at 80% 80%,#0EA5E9 0,transparent 40%),#0B1F46;min-height:100vh}
.login-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:16px}
.login-card{width:100%;max-width:380px;background:#fff;border-radius:20px;padding:26px;box-shadow:0 30px 60px rgba(0,0,0,.35)}
.login-brand{display:flex;align-items:center;gap:12px;margin-bottom:20px}
.login-brand img{width:52px;height:52px;border-radius:14px}
.login-brand h1{font-size:1.3rem;font-weight:900;margin:0;color:var(--primary)}
.login-brand small{color:var(--muted)}
.btn-login{padding:10px;font-weight:800}
.login-foot{text-align:center;color:var(--muted);font-size:.75rem;margin-top:16px}

.code-box{background:#0F172A;color:#7DD3FC;border-radius:10px;padding:10px 12px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:.82rem;word-break:break-all}

/* ---------- Mobile ---------- */
@media (max-width:991.98px){
  .sidebar{transform:translateX(-100%)}
  .sidebar.show{transform:none}
  .sidebar-backdrop.show{display:block;position:fixed;inset:0;background:rgba(15,23,42,.45);z-index:1020}
  .main{margin-left:0}
  .topbar{margin-left:0}
  .topbar-brand{width:auto;flex:0 0 auto;padding:0 10px}
  .brand-name{display:none}
  .topbar-title small{display:none}
  .live-wrap{flex-direction:column-reverse;height:calc(100vh - var(--topbar-h))}
  .live-list{width:100%;flex:0 0 40%;border-right:0;border-top:1px solid var(--border)}
  .live-detail{left:8px;right:8px;width:auto;top:8px}
  .history-wrap{grid-template-columns:1fr}
  .history-map{height:60vh}
  .content{padding:10px}
}
