:root {
  --bg: #F6F4F1;
  --surface: #FFFFFF;
  --ink: #1C1917;
  --muted: #6B635D;
  --line: #E7E2DC;
  --accent: #0F766E;
  --accent-dark: #0B5F58;
  --accent-soft: #E3F4F1;
  --danger: #B91C1C;
  --danger-soft: #FDECEC;
  --ok: #166534;
  --ok-soft: #E7F5EC;
  --st-moving: #16A34A;
  --st-idle: #D97706;
  --st-stopped: #DC2626;
  --st-offline: #94A3B8;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -0.2px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Anchors the hidden labels so they never widen the page. */
label, .table-wrap, th { position: relative; }
.error { color: var(--danger); font-size: 13.5px; font-weight: 600; min-height: 1em; margin: 6px 0 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 700; color: #3F3A36; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select { height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font: inherit; color: var(--ink); background: #fff; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.btn { height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfc7bf; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: #f3c4c4; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .6; cursor: progress; }
.count { display: inline-block; min-width: 24px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; text-align: center; margin-left: 6px; vertical-align: 3px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; align-self: center; }
.login-card h1 { text-align: center; font-size: 22px; letter-spacing: 1px; }
.login-card h1 span { color: var(--accent); }
.login-card .muted { text-align: center; margin: -8px 0 4px; }

/* Shell : floating rail (style I2) */
.shell { min-height: 100vh; background: #EEF1EF; }
.rail { position: fixed; left: 16px; top: 16px; bottom: 16px; width: 76px; z-index: 1000; background: var(--accent); border-radius: 22px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 0; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.rail-logo { width: 44px; height: 44px; border-radius: 12px; box-shadow: 0 0 0 2px rgba(255,255,255,.35); margin-bottom: 14px; }
.nav-item { width: 60px; padding: 8px 0; border: 0; border-radius: 14px; background: transparent; color: #CDEDE8; font: inherit; font-size: 11px; font-weight: 800; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.nav-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-item[aria-current="page"] { background: #fff; color: var(--accent); }
.rail-user { margin-top: auto; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.rail-user svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail-user:hover { background: rgba(255,255,255,.3); }
.content { padding: 22px 24px 32px 116px; min-width: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.search { margin: 0 0 10px; }
.empty { padding: 24px 4px; text-align: center; }

/* Vehicles : full-screen map with floating cards */
.view-map { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; z-index: 1; }
.float-card { background: rgba(255,255,255,.97); border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.14); }
.float-side { position: absolute; left: 108px; top: 16px; bottom: 16px; width: 380px; z-index: 500; display: flex; flex-direction: column; gap: 12px; }
.head-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.head-card .search { margin: 0; }
.head-row { display: flex; align-items: center; gap: 8px; }
.head-row h1 { font-size: 21px; flex: 1; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tile { border: 2px solid transparent; border-radius: 12px; padding: 7px 4px; display: flex; flex-direction: column; align-items: center; cursor: pointer; font: inherit; }
.tile b { font-size: 18px; }
.tile span { font-size: 11px; font-weight: 700; }
.tile[aria-pressed="true"] { border-color: currentColor; }
.list-card { flex: 1; min-height: 0; padding: 10px; overflow-y: auto; }
.vehicle-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.vehicle-list .group-btn { width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; margin-top: 4px; border: 0; border-radius: 12px; background: #F3F5F4; font: inherit; font-size: 13px; font-weight: 800; color: var(--ink); cursor: pointer; text-align: left; }
.vehicle-list .group-btn .count { margin-left: auto; }
.vehicle-list li:first-child .group-btn { margin-top: 0; }
.vehicle-list .v-btn { width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; padding: 10px; border-radius: 12px; border: 1.5px solid transparent; background: transparent; font: inherit; color: var(--ink); cursor: pointer; }
.vehicle-list .v-btn:hover { background: var(--bg); }
.vehicle-list .v-btn[aria-current="true"] { background: var(--accent-soft); border-color: var(--accent); }
.vehicle-list .v-btn.off { opacity: .55; }
.vehicle-list .dot { width: 10px; height: 10px; }
.v-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.v-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-side { font-weight: 800; white-space: nowrap; }
.float-top { position: absolute; top: 16px; right: 16px; z-index: 500; display: flex; gap: 8px; }
.pill-select { flex-direction: row; align-items: center; gap: 8px; height: 44px; padding: 0 6px 0 14px; background: #fff; border-radius: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: 13.5px; font-weight: 800; color: var(--ink); }
.pill-select select { height: 34px; border: 0; background: var(--bg); font-weight: 700; }
.map-layers { display: flex; align-items: center; background: #fff; border-radius: 12px; padding: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.layer { height: 36px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-size: 13px; font-weight: 800; color: var(--muted); cursor: pointer; }
.layer.on { background: var(--accent-soft); color: var(--accent); }
.fiche { position: absolute; right: 16px; bottom: 16px; width: 430px; z-index: 500; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.fiche-close { position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
.fiche-close:hover { background: var(--bg); }
.fiche-head { display: flex; align-items: center; gap: 12px; padding-right: 26px; }
.fiche-head > div:first-child { flex: 1; min-width: 0; }
.fiche-name { font-size: 17px; font-weight: 800; }
.fiche-speed { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.fiche-speed b { font-size: 30px; color: var(--ink); }
.fiche-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fiche-stats > div { background: #F3F5F4; border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.fiche-stats span { font-size: 11px; font-weight: 700; color: var(--muted); }
.fiche-actions { display: flex; gap: 8px; }
.fiche-actions .btn { flex: 1; }
.btn.danger-soft { background: var(--danger-soft); border-color: var(--danger-soft); color: var(--danger); }
.btn.ok-soft { background: var(--ok-soft); border-color: var(--ok-soft); color: var(--ok); }
.car-marker { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; }
.car-marker svg { width: 14px; height: 14px; fill: #fff; }
.leaflet-popup-content { font: 13.5px/1.45 system-ui, sans-serif; margin: 10px 14px; }
.leaflet-control-zoom { margin-right: 16px !important; margin-bottom: 16px !important; }

/* Users view */
.layout { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.accounts { flex: 1 1 300px; max-width: 400px; }
.detail { flex: 999 1 480px; min-width: 0; }
.account-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: calc(100vh - 230px); overflow-y: auto; }
.account-list button { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; background: transparent; font: inherit; color: var(--ink); cursor: pointer; }
.account-list button:hover { background: var(--bg); }
.account-list button[aria-current="true"] { background: var(--accent-soft); border-color: #bfe5df; }
.account-list .name { font-weight: 700; display: block; }
.account-list .sub { font-size: 12.5px; color: var(--muted); }
.account-list .off { color: var(--danger); font-weight: 700; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.detail-head p { margin: 4px 0 0; }
.pill { padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.pill.stock { background: #EEF1F5; color: #475569; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1 1 240px; }

/* Devices view */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.filters .search { margin: 0; }
.table-wrap { overflow-x: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid #F0EBE5; white-space: nowrap; }
th { font-size: 12.5px; color: var(--muted); font-weight: 700; background: #FBFAF8; }
tr:last-child td { border-bottom: 0; }
td.right { text-align: right; }
td .btn + .btn { margin-left: 6px; }
.mono { font-variant-numeric: tabular-nums; }

dialog { border: 0; border-radius: 18px; padding: 24px; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(28,25,23,.45); }
dialog form { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.row input { flex: 1; min-width: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); z-index: 2000; }

@media (max-width: 760px) {
  .rail { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 68px; flex-direction: row; justify-content: space-around; border-radius: 18px 18px 0 0; padding: 0 8px; }
  .rail-logo { display: none; }
  .rail-user { margin: 0; }
  .content { padding: 16px 16px 90px; }
  .float-side { left: 12px; right: 12px; width: auto; top: 70px; bottom: auto; max-height: 45vh; }
  .float-top { left: 12px; right: 12px; top: 12px; }
  .fiche { left: 12px; right: 12px; width: auto; bottom: 80px; }
  .accounts { max-width: none; }
}

/* Trackers table: two-line cells and icon actions so every column fits */
.cell-main { font-weight: 700; }
.cell-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
tr.row-off td { color: var(--muted); }
th.right { text-align: right; }
.icon-actions { display: inline-flex; gap: 6px; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--bg); }
.icon-btn.transfer { color: var(--accent); }
.icon-btn.off { color: #92400E; }
.icon-btn.on { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-soft); }
.icon-btn.delete { color: var(--danger); }
.icon-btn.delete:hover { background: var(--danger-soft); }
#view-devices th, #view-devices td { padding: 10px 10px; }
#view-devices td .pill.off { display: inline-block; margin-top: 4px; font-size: 11.5px; padding: 2px 8px; }

/* Account rows: the row opens the account, the icons act on it directly */
.account-list .account-row { display: flex; align-items: center; gap: 6px; }
.account-list .account-row > button { flex: 1; min-width: 0; }
.accounts { flex: 1 1 380px; max-width: 460px; }
.account-list .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Trackers table: actions behind a "⋯" menu */
.menu-wrap { position: relative; display: inline-block; }
.dots-btn { width: 36px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: 20px; font-weight: 800; line-height: 1; color: var(--ink); cursor: pointer; }
.dots-btn:hover, .dots-btn[aria-expanded="true"] { background: var(--bg); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 180px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.16); padding: 6px; display: flex; flex-direction: column; text-align: left; }
.menu-item { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; font: inherit; font-size: 14px; font-weight: 700; color: var(--ink); cursor: pointer; }
.menu-item:hover { background: var(--bg); }
.menu-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.menu-item.transfer svg { color: var(--accent); }
.menu-item.off svg { color: #92400E; }
.menu-item.on { color: var(--ok); }
.menu-item.delete { color: var(--danger); }
.menu-item.delete:hover { background: var(--danger-soft); }
#view-devices .table-wrap { overflow: visible; }
