* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #f8fafc;
  --surface: #ffffff;
  --border:  #e2e8f0;
  --muted:   #64748b;
  --text:    #1e293b;
  --dim:     #94a3b8;
  --blue:    #3b82f6;
  --green:   #22c55e;
  --red:     #ef4444;
  --amber:   #f59e0b;
  --purple:  #a855f7;
  --mono:    'Courier New', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Top bar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}
.tb-logo { font-weight: 800; font-size: 16px; color: var(--blue); letter-spacing: 0.5px; cursor: pointer; }
.tb-logo span { color: var(--purple); }
.tb-badge {
  background: #2d1b69; color: var(--purple);
  border: 1px solid var(--purple); font-size: 10px; font-weight: 700;
  padding: 2px 9px; border-radius: 20px; letter-spacing: 0.6px;
}

/* stat chips */
.stat-chips { display: flex; gap: 10px; margin-left: auto; }
.chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 12px;
  font-size: 11px;
}
.chip-dot { width: 7px; height: 7px; border-radius: 50%; }
.chip-dot.blue   { background: var(--blue); }
.chip-dot.green  { background: var(--green); }
.chip-dot.red    { background: var(--red); }
.chip-dot.purple { background: var(--purple); }
.chip-val { font-weight: 700; font-size: 14px; color: var(--text); }
.chip-lbl { color: var(--muted); }

/* refresh */
.tb-refresh {
  background: none; border: 1px solid var(--border); color: var(--dim);
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 11px;
  transition: all .15s;
}
.tb-refresh:hover { border-color: var(--blue); color: var(--blue); }

.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); transition: background .3s;
  flex-shrink: 0;
}
.conn-dot.ok  { background: var(--green); }
.conn-dot.err { background: var(--red); }

/* ── Layout ── */
.main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Left sidebar ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-header {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.tenant-list { flex: 1; overflow-y: auto; }
.tenant-item {
  padding: 10px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background .1s;
  display: flex; align-items: center; gap: 10px;
}
.tenant-item:hover { background: #f1f5f9; }
.tenant-item.active { background: #dbeafe; border-left: 3px solid var(--blue); padding-left: 13px; }
.tenant-item.all { border-left: 3px solid var(--purple); padding-left: 13px; background: #f5f3ff; }
.tenant-avatar {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px; flex-shrink: 0;
}
.tenant-info { min-width: 0; }
.tenant-name { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tenant-meta { font-size: 10px; color: var(--muted); margin-top: 1px; }

/* ── Centre: map ── */
.map-panel { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }

/* ── Layer switcher ── */
#layer-switcher {
  position: absolute; top: 10px; right: 10px; z-index: 1000;
  display: flex; gap: 4px; background: #ffffffcc;
  padding: 5px; border-radius: 8px; border: 1px solid #e2e8f0;
  backdrop-filter: blur(4px);
}
.ls-btn {
  padding: 5px 10px; border-radius: 5px; border: 1px solid transparent;
  background: transparent; color: #94a3b8; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: .15s; white-space: nowrap; text-decoration: none;
  display: flex; align-items: center;
}
.ls-btn:hover { background: #e2e8f0; color: #e2e8f0; }
.ls-btn.active { background: #0284c7; color: #fff; border-color: #0369a1; }
.ls-btn.traffic-on  { background: #b45309; color: #fef3c7; border-color: #d97706; }
.ls-btn.traffic-on:hover { background: #d97706; }
.ls-btn.traffic-off { opacity: .35; cursor: not-allowed; pointer-events: none; }
.ls-btn.poi-on { background: #16a34a; color: #f0fdf4; border-color: #15803d; }
.ls-btn.poi-on:hover { background: #15803d; }
.ls-btn.geo-on { background: #0e7490; color: #ecfeff; border-color: #0891b2; }
.ls-btn.geo-on:hover { background: #0891b2; }
.ls-settings { font-size: 13px; padding: 5px 8px; }
.ls-divider { width: 1px; background: #e2e8f0; margin: 2px 2px; align-self: stretch; }

/* ── Bottom: vehicle table ── */
.table-panel {
  height: 260px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.table-toolbar {
  padding: 8px 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.table-toolbar-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.search-input {
  flex: 1; max-width: 240px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 10px; font-size: 12px; outline: none;
}
.search-input:focus { border-color: var(--blue); }
.filter-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 3px 8px; font-size: 11px; outline: none; cursor: pointer;
}
.count-badge {
  margin-left: auto;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 10px; font-size: 11px; color: var(--dim);
}
.table-wrap { flex: 1; overflow-y: auto; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th {
  position: sticky; top: 0;
  background: #f1f5f9; color: var(--muted);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  padding: 6px 12px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid #f1f5f9; transition: background .1s; cursor: pointer; }
tbody tr:hover { background: #f1f5f9; }
tbody td { padding: 7px 12px; white-space: nowrap; }
.td-reg { font-family: var(--mono); font-weight: 700; color: var(--blue); }
.td-tenant { color: var(--purple); font-size: 11px; }
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 10px; font-weight: 600;
}
.status-badge.online  { background: #14532d; color: var(--green); }
.status-badge.offline { background: #1c1c1c; color: var(--muted); }
.ignition-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600;
}
.ignition-badge.on  { color: var(--green); }
.ignition-badge.off { color: var(--muted); }
.fuel-bar-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 80px; }
.fuel-bar {
  width: 60px; height: 5px; background: #f1f5f9;
  border-radius: 3px; overflow: hidden;
}
.fuel-bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.fuel-val { font-size: 10px; color: var(--dim); white-space: nowrap; }
.batt-bar-wrap { display: flex; align-items: center; gap: 6px; }
.batt-bar {
  flex: 1; height: 8px; background: #ffffff; border-radius: 4px; overflow: hidden; min-width: 50px;
}
.batt-bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.batt-val { font-size: 10px; color: var(--dim); min-width: 30px; }
.signal-bars { display: inline-flex; align-items: flex-end; gap: 1px; height: 14px; }
.signal-bars .bar { width: 3px; background: #cbd5e1; border-radius: 1px; }
.signal-bars .bar.active { background: #22c55e; }
.signal-bars .bar.warn { background: #f59e0b; }
.signal-bars .bar.weak { background: #ef4444; }

/* ── Key hint ── */
.key-hint {
  position: fixed; bottom: 270px; right: 16px; z-index: 1000;
  background: rgba(248,250,252,0.95); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; font-size: 10px; color: var(--muted);
  backdrop-filter: blur(4px);
}

/* ── Map vehicle popup ── */
.leaflet-popup-content-wrapper {
  background: #ffffff; border: 1px solid #e2e8f0;
  border-radius: 8px; color: #e2e8f0; font-size: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.leaflet-popup-tip { background: #ffffff; }
.popup-reg { font-family: monospace; font-weight: 800; font-size: 14px; color: #3b82f6; }
.popup-row { display: flex; justify-content: space-between; gap: 16px; margin-top: 4px; }
.popup-key { color: #64748b; font-size: 11px; }
.popup-val { color: #e2e8f0; font-size: 11px; font-weight: 600; }


/* scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin .8s linear infinite; display: inline-block; }

/* ── Mode toggle ─────────────────────────────────────────────────────────── */
.mode-toggle { display: flex; gap: 4px; }
.mode-btn {
  background: none; border: 1px solid var(--border); color: var(--dim);
  padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 11px; font-weight: 600;
  transition: all .15s;
}
.mode-btn:hover { border-color: var(--blue); color: var(--blue); }
.mode-btn.active    { background: var(--blue);   border-color: var(--blue);   color: #fff; }
.mode-btn.pb-active { background: #7c3aed;        border-color: #7c3aed;       color: #fff; }

/* ── Playback bar ────────────────────────────────────────────────────────── */
#playbackBar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 500;
  background: rgba(248,250,252,0.9);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(100, 116, 139, 0.25);
  flex-direction: column;
}
.pb-top {
  padding: 5px 12px; display: flex; align-items: center; gap: 6px; flex-wrap: nowrap;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.pb-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }
.pb-select, .pb-date {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 5px 10px; font-size: 12px; outline: none; cursor: pointer;
}
.pb-select { min-width: 200px; }
.pb-select:focus, .pb-date:focus { border-color: var(--blue); }
.pb-btn {
  background: var(--blue); color: #fff; border: none;
  border-radius: 6px; padding: 4px 12px; font-size: 11px; font-weight: 700;
  cursor: pointer; transition: background .15s;
}
.pb-btn:hover { background: #2563eb; }
.pb-btn:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }
.pb-summary { margin-left: auto; font-size: 11px; color: var(--dim); white-space: nowrap; flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ── Scrubber ────────────────────────────────────────────────────────────── */
.pb-scrubber-wrap { padding: 5px 12px 2px; }
.pb-scrubber-track {
  position: relative; height: 6px; background: var(--border);
  border-radius: 4px; cursor: pointer; overflow: visible; width: 100%;
}
.pb-scrubber-fill {
  position: absolute; left: 0; top: 0; height: 100%;
  background: var(--blue); border-radius: 4px; pointer-events: none;
}
.pb-scrubber-thumb {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--blue);
  cursor: grab; z-index: 2; box-shadow: 0 0 4px rgba(0,0,0,0.5);
  pointer-events: none;
}
.pb-time-labels {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--muted); margin-top: 2px;
}

/* ── Controls ────────────────────────────────────────────────────────────── */
.pb-controls {
  padding: 4px 12px; display: flex; align-items: center; gap: 5px;
  border-top: 1px solid var(--border);
}
.pb-ctrl-btn {
  background: none; border: 1px solid var(--border); color: var(--dim);
  width: 26px; height: 24px; border-radius: 5px; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.pb-ctrl-btn:hover { border-color: var(--blue); color: var(--blue); }
.pb-ctrl-btn.play { background: var(--blue); border-color: var(--blue); color: #fff; width: 30px; font-size: 13px; }
.pb-ctrl-btn.play:hover { background: #2563eb; }
.pb-speed-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 8px; font-size: 11px; outline: none; cursor: pointer;
}
.pb-toggle-btn {
  background: none; border: 1px solid var(--border); color: var(--dim);
  border-radius: 5px; padding: 2px 8px; cursor: pointer; font-size: 11px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
}
.pb-toggle-btn:hover { border-color: var(--blue); color: var(--blue); }
.pb-toggle-btn.active { background: #dbeafe; border-color: var(--blue); color: var(--blue); }
.pb-divider { width: 1px; background: var(--border); height: 16px; margin: 0 3px; }
.pb-export-wrap { position: relative; }
.pb-cfg-section { font-size:9px; font-weight:700; color:#64748b; letter-spacing:.6px; text-transform:uppercase; margin-bottom:8px; }
.pb-cfg-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:7px; color:#94a3b8; gap:8px; cursor:default; }
.pb-cfg-row span { flex:1; }
.pb-cfg-input { width:80px; background:#f8fafc; border:1px solid #e2e8f0; color:#1e293b; border-radius:5px; padding:3px 7px; font-size:12px; text-align:right; outline:none; }
.pb-cfg-input:focus { border-color:#3b82f6; }
.pb-export-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 900;
  background: #ffffff; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 0; min-width: 170px; box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.pb-export-item {
  padding: 7px 16px; font-size: 12px; color: var(--text); cursor: pointer;
  transition: background .12s;
}
.pb-export-item:hover { background: #e2e8f0; }

/* ── Info bar ────────────────────────────────────────────────────────────── */
.pb-infobar { display: flex; align-items: stretch; border-top: 1px solid var(--border); }
.pb-info-item {
  padding: 3px 10px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 1px; min-width: 90px;
}
.pb-info-label { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.pb-info-val { font-weight: 700; color: var(--text); font-family: var(--mono); font-size: 12px; }
.pb-info-val.moving   { color: var(--green); }
.pb-info-val.idle     { color: var(--amber); }
.pb-info-val.stopped  { color: var(--muted); }
.pb-info-val.overspeed{ color: var(--red); }

/* ── Playback map markers ─────────────────────────────────────────────────── */
.pb-flag {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.pb-flag-start { background: #22c55e; color: #fff; }
.pb-flag-end   { background: #ef4444; color: #fff; }

/* ── ALERT TOAST NOTIFICATIONS ─────────────────────────────────────────────── */
#toast-container{position:fixed;top:60px;right:16px;z-index:9999;display:flex;flex-direction:column;gap:8px;pointer-events:none;max-height:calc(100vh - 80px);overflow-y:auto}
.toast{pointer-events:auto;background:#ffffff;border:1px solid #e2e8f0;border-radius:10px;padding:12px 16px;min-width:320px;max-width:420px;box-shadow:0 8px 24px rgba(0,0,0,.5);display:flex;gap:10px;align-items:flex-start;cursor:pointer;animation:toastIn .3s ease;transition:opacity .3s,transform .3s}
.toast.removing{opacity:0;transform:translateX(100px)}
@keyframes toastIn{from{opacity:0;transform:translateX(100px)}to{opacity:1;transform:translateX(0)}}
.toast-icon{font-size:20px;flex-shrink:0;line-height:1}
.toast-body{flex:1;min-width:0}
.toast-title{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.04em;margin-bottom:2px}
.toast-msg{font-size:13px;color:#e2e8f0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.toast-time{font-size:10px;color:#cbd5e1;margin-top:3px}
.toast-close{background:none;border:none;color:#cbd5e1;font-size:16px;cursor:pointer;padding:0 2px;line-height:1;flex-shrink:0}
.toast-close:hover{color:#94a3b8}
.toast-bar{position:absolute;bottom:0;left:0;height:3px;border-radius:0 0 10px 10px;animation:toastBar 10s linear forwards}
@keyframes toastBar{from{width:100%}to{width:0}}
/* Severity colors */
.toast-critical{border-left:4px solid #dc2626}.toast-critical .toast-title{color:#fca5a5}.toast-critical .toast-bar{background:#dc2626}
.toast-warning{border-left:4px solid #f59e0b}.toast-warning .toast-title{color:#fcd34d}.toast-warning .toast-bar{background:#f59e0b}
.toast-info{border-left:4px solid #3b82f6}.toast-info .toast-title{color:#93c5fd}.toast-info .toast-bar{background:#3b82f6}
/* ===== Step 2: popup icons, role-based UI (appended) ===== */
/* ===== Step 2: popup icons, role-based UI (appended) ===== */

/* Popup card layout */
.popup-card { min-width: 200px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.popup-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
}
.popup-header-row .popup-reg {
  font-size: 15px;
  font-weight: 800;
  color: #e2e8f0;
  margin: 0;
}
.popup-header-icons {
  display: flex;
  align-items: center;
  gap: 8px;
}
.popup-icon-wrap {
  position: relative;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  padding: 2px 3px;
  border-radius: 4px;
  transition: background 0.12s ease;
}
.popup-icon-wrap:hover { background: rgba(59, 130, 246, 0.12); }
.popup-icon-wrap svg { display: block; }

/* Popover revealed on click */
.popup-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 9999;
  color: #e2e8f0;
  font-size: 12px;
}
.popup-popover.open { display: block; }
.popup-popover .pp-title {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.popup-popover .pp-body { color: #e2e8f0; line-height: 1.4; }

/* Critical battery pulse (<5%) */
@keyframes blinkCritical {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
.blink-critical { animation: blinkCritical 1.2s ease-in-out infinite; }

/* Popup action buttons (Share + Playback) */
.popup-action-row {
  display: flex;
  gap: 6px;
  border-top: 1px solid #e2e8f0;
  margin-top: 10px;
  padding-top: 8px;
}
.popup-btn {
  flex: 1;
  padding: 7px 8px;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.06s ease;
}
.popup-btn:hover  { filter: brightness(1.1); }
.popup-btn:active { transform: translateY(1px); }
.popup-btn-share    { background: #3b82f6; }
.popup-btn-playback { background: #a855f7; }

/* ===== Role-based UI hiding ===== */
/* When logged in as tenant admin/owner, hide tenant-scoped UI elements
   because they only see their own tenant anyway. */

/* Sidebar is visible for tenant admins — they use it to browse their own fleet. */

/* Hide Tenants stat chip (first .chip with purple dot) */
body.role-tenant .stat-chips .chip:has(.chip-dot.purple) { display: none !important; }

/* Hide Tenant column in vehicle table (3rd column) */
body.role-tenant table thead tr th:nth-child(3),
body.role-tenant table tbody tr td:nth-child(3) { display: none !important; }
body.role-tenant table tbody tr td.td-tenant { display: none !important; }

/* Tenant admins only get tree view — hide the view toggle entirely */
body.role-tenant #viewToggle { display: none !important; }

/* Popup: tenant row is already omitted from HTML in non-super case — nothing needed here */

/* ===== Step 3: resizable splitter ===== */
/* ===== Step 3: resizable splitter ===== */
.splitter {
  height: 6px;
  background: var(--border);
  cursor: ns-resize;
  flex-shrink: 0;
  transition: background 0.15s ease;
  position: relative;
  user-select: none;
}
.splitter::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* Step 14: wider/thicker/brighter grip bar for better discoverability. */
  width: 48px;
  height: 3px;
  background: var(--muted);
  border-radius: 2px;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.splitter:hover,
.splitter.dragging { background: var(--blue); }
.splitter:hover::before,
.splitter.dragging::before { background: #fff; opacity: 1; }
.splitter.hidden { display: none; }
body.dragging-splitter,
body.dragging-splitter * {
  user-select: none !important;
  cursor: ns-resize !important;
}

/* ===== Step 4: tree view sidebar ===== */
/* ===== Step 4: tree view sidebar ===== */

/* Wider sidebar to fit vehicles nested under tenants */
body.view-tree .sidebar { width: 300px; }

/* Title row: title + view toggle side by side */
.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.vt-btn {
  background: transparent;
  border: none;
  color: var(--dim);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
}
.vt-btn:hover { color: var(--text); }
.vt-btn.active {
  background: var(--blue);
  color: #fff;
}

/* Search input */
.sidebar-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.12s;
}
.sidebar-search:focus { border-color: var(--blue); }
.sidebar-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 14px; width: 14px;
  background: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 6l12 12M18 6L6 18' stroke='black' stroke-width='3' stroke-linecap='round'/></svg>") center/80% no-repeat;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 6l12 12M18 6L6 18' stroke='black' stroke-width='3' stroke-linecap='round'/></svg>") center/80% no-repeat;
}

/* Tree container: scrollable */
.tenant-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Tenant group (header + nested vehicles) */
.tenant-group {
  border-bottom: 1px solid #f1f5f9;
}
.tenant-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.tenant-header:hover { background: #f1f5f9; }
.tenant-header.active { background: #dbeafe; border-left: 3px solid var(--blue); padding-left: 9px; }
.tenant-header.all { background: #f5f3ff; border-left: 3px solid var(--purple); padding-left: 9px; }
.tenant-header.all.active { background: #ede9fe; }

.tenant-caret {
  font-size: 10px;
  color: var(--muted);
  width: 10px;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.tenant-group.expanded .tenant-caret { transform: rotate(90deg); }

.tenant-header .tenant-avatar {
  width: 26px; height: 26px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 11px; flex-shrink: 0;
}
.tenant-header .tenant-info { min-width: 0; flex: 1; }
.tenant-header .tenant-name {
  font-weight: 600; font-size: 12px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tenant-header .tenant-meta {
  font-size: 10px; color: var(--muted); margin-top: 1px;
}
.tenant-header .tenant-count {
  font-size: 10px;
  color: var(--dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  flex-shrink: 0;
}

/* Vehicle rows inside a tenant group */
.vehicle-list {
  display: none;
  background: #f1f5f9;
}
.tenant-group.expanded .vehicle-list { display: block; }

.vehicle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 36px; /* indent under tenant */
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
  font-size: 11px;
}
.vehicle-row:hover { background: #f1f5f9; }
.vehicle-row.active { background: #dbeafe; border-left-color: var(--blue); }

.vehicle-row .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.vehicle-row .status-dot.online  { background: var(--green); box-shadow: 0 0 6px #22c55e99; }
.vehicle-row .status-dot.offline { background: #ef4444; }
.vehicle-row:has(.status-dot.offline) .veh-reg { color: #ef4444; }

.vehicle-row .veh-reg {
  font-weight: 700;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vehicle-row .veh-speed {
  font-size: 10px;
  color: var(--dim);
  font-family: var(--mono);
  flex-shrink: 0;
}
.veh-fault-badge { font-size: 10px; cursor: help; flex-shrink: 0; line-height: 1; }
.tbl-fault-badge  { font-size: 10px; cursor: help; margin-left: 3px; }
.vehicle-row .veh-ign {
  font-size: 10px;
  color: var(--amber);
  flex-shrink: 0;
}
.vehicle-row .veh-ign.off { color: var(--muted); }

.tree-empty {
  padding: 20px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* Tree view: hide bottom table, splitter; map grows full height */
body.view-tree .table-panel,
body.view-tree #splitter { display: none !important; }
body.view-tree .tenant-list { display: none !important; }
body.view-tree #tenantTree { display: block; }

/* Table view: keep original layout, hide tree */
body.view-table #tenantTree { display: none !important; }
body.view-table .tenant-list { display: block !important; }
body.view-table .table-panel,
body.view-table #splitter { display: flex; }
body.view-table #splitter { display: block; }


/* ===== Step 4b: filter chips, clickable stat chips ===== */
/* ===== Step 4b: filter chips, clickable stat chips ===== */

/* Sidebar needs flex layout so tree grows and filter bar sticks at bottom */
.sidebar { display: flex; flex-direction: column; }
#tenantTree { flex: 1 1 auto; }

/* Filter chip bar at bottom of sidebar */
.sidebar-filters {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 5px;
}
.filter-row:last-child { margin-bottom: 0; }
.filter-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 48px;
}
.chip-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--dim);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.chip-btn:hover { color: var(--text); background: #f1f5f9; }
.chip-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* Simplified table toolbar */
.table-toolbar-hint {
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

/* Top stat chips: clickable + hover + active highlight */
.chip-clickable { cursor: pointer; transition: background 0.12s, border-color 0.12s; }
.chip-clickable:hover { background: #f1f5f9; }
.chip-clickable.active-filter {
  border: 1px solid var(--blue);
  box-shadow: 0 0 0 1px var(--blue) inset;
}

/* Vehicle row: last-seen small text (Step 4b tweak) */
.vehicle-row .veh-seen {
  font-size: 9px;
  color: var(--muted);
  font-family: var(--mono);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ===== Step 8: vertical splitter (sidebar width) ===== */
/* ===== Step 8: vertical splitter (sidebar width) ===== */
.vsplitter {
  width: 6px;
  background: var(--border);
  cursor: ew-resize;
  flex-shrink: 0;
  transition: background 0.15s ease;
  position: relative;
  user-select: none;
}
.vsplitter::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 36px;
  background: var(--muted);
  border-radius: 2px;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.vsplitter:hover,
.vsplitter.dragging { background: var(--blue); }
.vsplitter:hover::before,
.vsplitter.dragging::before { background: #fff; opacity: 1; }
.vsplitter.hidden { display: none; }

/* Reuse body.dragging-splitter rule so horizontal AND vertical drags disable
   text selection the same way. Add a vertical-cursor override. */
body.dragging-vsplitter,
body.dragging-vsplitter * {
  user-select: none !important;
  cursor: ew-resize !important;
}

/* ===== Step 11: mobile responsive (<=768px) ===== */

/* Hamburger button — hidden on desktop, shown on mobile */
.tb-menu {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  width: 36px; height: 36px;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: all 0.15s;
}
.tb-menu:hover { border-color: var(--blue); color: var(--blue); }

/* Drawer backdrop — fades in behind the drawer on mobile */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

@media (max-width: 768px) {
  /* Show hamburger (tenants use it to toggle the sidebar on mobile) */
  .tb-menu { display: inline-flex; align-items: center; justify-content: center; }

  /* Topbar — tighten spacing, drop badge, shrink refresh to icon */
  .topbar { gap: 8px; padding: 0 10px; height: 48px; }
  .tb-logo { font-size: 13px; }
  .tb-badge { display: none; }
  .mode-btn { padding: 4px 8px; font-size: 11px; }
  .stat-chips { gap: 4px; margin-left: auto; }
  .chip { padding: 4px 8px; font-size: 10px; }
  .chip-lbl { display: none; }
  .chip-val { font-size: 13px; }
  .tb-refresh-label { display: none; }
  .tb-refresh { padding: 5px 9px; font-size: 14px; }

  /* Sidebar becomes a fixed-position drawer that slides in from the left */
  .sidebar,
  body.view-tree .sidebar {
    position: fixed;
    top: 48px;
    left: 0;
    bottom: 0;
    width: 85vw;
    max-width: 320px;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.5);
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .drawer-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* All splitters disabled on mobile — no mouse drag on phones */
  #splitter, #vSplitter, #pbSplitter { display: none !important; }

  /* Table: fixed height instead of drag-to-resize */
  .table-panel { max-height: 40vh; flex: 0 0 auto; }

  /* Step 12: #playbackBar is flex-direction: column — DO NOT add flex-wrap
     here, it causes children to wrap into an invisible second column on
     the right. Just cap height + scroll if content overflows. */
  #playbackBar {
    padding: 0 !important;
    max-height: 55vh !important;
    overflow-y: auto !important;
  }

  /* Step 12: tighter .pb-top on mobile — each input gets its own
     full-width row so Vehicle / From / To / Load are all reachable. */
  .pb-top {
    padding: 6px 10px !important;
    gap: 4px !important;
    flex-wrap: wrap !important;
  }
  .pb-select, .pb-date {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .pb-btn {
    width: 100%;
  }
  .pb-summary {
    margin-left: 0 !important;
    white-space: normal !important;
  }

  /* Step 11b: hide the trip-details table on mobile — takes too much
     vertical space on phones; desktop layout keeps the full table. */
  #pbDaySummary { display: none !important; }
}

/* ===== Step 13: top Playback button "playing" indicator ===== */
/* When playback is actively animating, the top Playback button pulses
   and shows "⏸ Pause" instead of "▶ Playback". Makes "am I playing?"
   obvious from the top of the screen on both desktop and mobile. */
.mode-btn.pb-active.playing {
  background: #a855f7;
  color: #fff;
  border-color: #a855f7;
  animation: pb-top-pulse 1.4s ease-in-out infinite;
}

@keyframes pb-top-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(168, 85, 247, 0);    }
}

/* ===== Step 15: export toast notifications ===== */
/* Small bottom-centre banner used by pbToast() in Masterboard.js.
   Slides up, holds, fades out — total ~3 sec, matches pbToast setTimeout. */
.pb-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  z-index: 2000;
  pointer-events: none;     /* never block the UI below */
  white-space: nowrap;
  animation:
    pb-toast-in  0.25s ease-out both,
    pb-toast-out 0.30s ease-in  2.70s both;
}
.pb-toast.ok  { background: #16a34a; }
.pb-toast.err { background: #dc2626; }

@keyframes pb-toast-in {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to   { opacity: 1; transform: translate(-50%, 0);    }
}
@keyframes pb-toast-out {
  from { opacity: 1; transform: translate(-50%, 0);    }
  to   { opacity: 0; transform: translate(-50%, 20px); }
}

/* Mobile: narrow screens — allow wrap so long messages stay visible */
@media (max-width: 768px) {
  .pb-toast {
    left: 16px;
    right: 16px;
    bottom: 24px;
    transform: none;
    white-space: normal;
    text-align: center;
    animation:
      pb-toast-in-mobile  0.25s ease-out both,
      pb-toast-out-mobile 0.30s ease-in  2.70s both;
  }
  @keyframes pb-toast-in-mobile  { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
  @keyframes pb-toast-out-mobile { from { opacity:1; transform:translateY(0); }    to { opacity:0; transform:translateY(16px); } }
}

/* ===== Step 17: floating/draggable playback bar ===== */
/* Slim header strip above .pb-top. Always in the DOM; when docked it only
   shows the Pop Out button (grip + opacity hidden). When floating, all
   three elements show: grip (drag handle), opacity slider, Dock button. */
.pb-float-header {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  font-size: 11px;
  color: var(--dim);
  user-select: none;
  flex-shrink: 0;
}
.pb-float-grip {
  display: none;
  cursor: move;
  font-size: 16px;
  color: var(--muted);
  padding: 0 6px;
  letter-spacing: -3px;
  line-height: 1;
}
.pb-float-grip:hover { color: #e2e8f0; }
.pb-float-opacity {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--dim);
}
.pb-float-opacity input[type=range] {
  width: 90px; accent-color: #3b82f6; cursor: pointer;
}
#pbFloatOpacityVal { min-width: 34px; text-align: right; color: #e2e8f0; }
.pb-float-spacer { flex: 1; }
#pbFloatToggleBtn { margin-left: auto; }

/* ── Docked mode: collapse the float-header row, overlay Pop Out on pb-top ─
   The header becomes 0-height; the toggle button is absolutely pinned to
   the right edge of pb-top. pb-top gets right padding so summary text
   never slides under the button.                                           */
#playbackBar { position: relative; }

#playbackBar:not(.pb-floating) .pb-float-header {
  position: absolute;
  right: 0; top: 0;
  height: 44px;
  padding: 0 10px;
  background: transparent;
  border: none;
  pointer-events: none;
}
#playbackBar:not(.pb-floating) #pbFloatToggleBtn {
  pointer-events: auto;
}
#playbackBar:not(.pb-floating) .pb-float-spacer { display: none; }
#playbackBar:not(.pb-floating) .pb-top { padding-right: 110px; }

/* ── Floating mode ─────────────────────────────────────────────────────────
   Transforms #playbackBar into a draggable overlay. Opacity is controlled
   by --pb-float-opacity CSS variable (set by JS from the slider). */
#playbackBar.pb-floating {
  position: fixed;
  z-index: 800;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  flex-direction: column;
  background: rgba(248,250,252, var(--pb-float-opacity, 0.92));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  /* No overflow:hidden — would clip the export dropdown menu. */
}
#playbackBar.pb-floating .pb-float-grip,
#playbackBar.pb-floating .pb-float-opacity {
  display: flex;
}

/* Resize handle — visible only when floating. Diagonal stripe pattern. */
.pb-float-resize {
  display: none;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  background: linear-gradient(135deg,
    transparent 0%, transparent 45%,
    #64748b 45%, #64748b 52%,
    transparent 52%, transparent 72%,
    #64748b 72%, #64748b 79%,
    transparent 79%);
  z-index: 810;
  border-bottom-right-radius: 10px;
}
.pb-float-resize:hover {
  background: linear-gradient(135deg,
    transparent 0%, transparent 45%,
    #3b82f6 45%, #3b82f6 52%,
    transparent 52%, transparent 72%,
    #3b82f6 72%, #3b82f6 79%,
    transparent 79%);
}
#playbackBar.pb-floating .pb-float-resize {
  display: block;
}

/* Mobile: no float mode — hide header + button + resize; force docked layout. */
@media (max-width: 768px) {
  #pbFloatHeader { display: none !important; }
  #playbackBar.pb-floating {
    position: static !important;
    width: auto !important;
    height: auto !important;
  }
}
/* Label visibility toggle */
body.labels-hidden .reg-label { display: none; }
