:root {
  --bg: #0b1020;
  --bg-soft: #121a33;
  --panel: #16203c;
  --panel-2: #1c2950;
  --line: #263255;
  --text: #e7ecf6;
  --muted: #9aa7c7;
  --brand: #4f8cff;
  --brand-2: #22d3ee;
  --accent: #34d399;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem 1.1rem; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: .95rem; cursor: pointer; transition: .15s ease;
  white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #05122b; }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-ghost { background: rgba(255, 255, 255, .06); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: rgba(255, 255, 255, .12); }

/* ---------- top bar (public) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 2rem; backdrop-filter: blur(10px);
  background: rgba(11, 16, 32, .6); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.15rem; letter-spacing: .2px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--brand-2), var(--brand));
  box-shadow: 0 0 0 4px rgba(79, 140, 255, .18); }
.brand span b { color: var(--brand-2); }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden;
  padding: 5.5rem 2rem 6rem; text-align: center;
  background:
    radial-gradient(1100px 500px at 50% -10%, rgba(79, 140, 255, .28), transparent 60%),
    radial-gradient(700px 400px at 85% 20%, rgba(34, 211, 238, .18), transparent 60%),
    var(--bg);
}
.hero .eyebrow {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .35rem .85rem; border-radius: 999px; font-size: .82rem; font-weight: 600;
  color: var(--brand-2); background: rgba(34, 211, 238, .1); border: 1px solid rgba(34, 211, 238, .25);
  margin-bottom: 1.4rem;
}
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); line-height: 1.05; margin: 0 auto 1.1rem; max-width: 900px; }
.hero h1 .grad { background: linear-gradient(120deg, var(--brand-2), var(--brand)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; margin: 0 auto 2rem; }
.hero .cta { display: flex; gap: .9rem; justify-content: center; flex-wrap: wrap; }

/* map preview strip */
.map-strip {
  margin: 3.5rem auto 0; max-width: 1050px; height: 260px; border-radius: 20px;
  border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden;
  background:
    linear-gradient(transparent 0 0),
    conic-gradient(from 0deg at 20% 30%, rgba(79,140,255,.10), transparent 25%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.035) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 1px, transparent 1px 42px),
    var(--bg-soft);
  position: relative;
}
.map-strip .route { position: absolute; inset: 0; }
.map-strip .pin { position: absolute; width: 16px; height: 16px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 0 0 6px rgba(79,140,255,.15); }

/* ---------- features ---------- */
.features { max-width: 1050px; margin: -2.5rem auto 4rem; padding: 0 2rem;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; position: relative; z-index: 2; }
.card { background: linear-gradient(180deg, var(--panel), var(--bg-soft)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.card .ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(79, 140, 255, .14); color: var(--brand-2); font-size: 1.3rem; margin-bottom: .9rem; }
.card h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .93rem; line-height: 1.5; }

.footer { text-align: center; color: var(--muted); padding: 2rem; border-top: 1px solid var(--line); font-size: .85rem; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem;
  background: radial-gradient(900px 500px at 50% -10%, rgba(79,140,255,.25), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line); border-radius: 18px; padding: 2.2rem; box-shadow: var(--shadow); }
.auth-card .brand { justify-content: center; margin-bottom: 1.6rem; }
.auth-card h2 { text-align: center; margin: 0 0 .3rem; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 1.6rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .4rem; }
.field input { width: 100%; padding: .75rem .9rem; border-radius: 10px; border: 1px solid var(--line);
  background: #0d1428; color: var(--text); font-size: 1rem; outline: none; transition: .15s; }
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,140,255,.2); }
.auth-card .btn { width: 100%; justify-content: center; margin-top: .4rem; }
.alert { background: rgba(248, 113, 113, .12); border: 1px solid rgba(248, 113, 113, .35);
  color: #fecaca; padding: .7rem .9rem; border-radius: 10px; font-size: .88rem; margin-bottom: 1.1rem; }
.back-link { display: block; text-align: center; margin-top: 1.2rem; color: var(--muted); font-size: .85rem; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 260px 1fr; grid-template-rows: 60px 1fr; height: 100vh; }
.app-top { grid-column: 1 / 3; display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.3rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.app-top .right { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: .9rem; }
.app-top .left { display: flex; align-items: center; gap: .6rem; }
.nav-toggle { display: none; background: transparent; border: none; color: var(--text);
  cursor: pointer; padding: 4px; line-height: 0; }
.nav-toggle:hover { color: var(--brand-2); }
.sidebar-backdrop { display: none; position: fixed; inset: 60px 0 0 0;
  background: rgba(3, 7, 18, .55); z-index: 1100; }
.sidebar-backdrop.open { display: block; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #05122b; }

.sidebar { background: var(--bg-soft); border-right: 1px solid var(--line); padding: 1rem .7rem; overflow-y: auto; }
.nav-group { margin-bottom: .4rem; }
.nav-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
  padding: .8rem .8rem .4rem; }
.nav-item { display: flex; align-items: center; gap: .7rem; padding: .62rem .8rem; border-radius: 10px;
  color: var(--muted); font-weight: 500; cursor: pointer; }
.nav-item:hover { background: rgba(255, 255, 255, .05); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, rgba(79,140,255,.22), rgba(34,211,238,.14));
  color: #fff; border: 1px solid rgba(79,140,255,.3); }
.nav-item . i { width: 20px; text-align: center; }
.nav-children { margin-left: .8rem; border-left: 1px solid var(--line); padding-left: .3rem; }
.nav-children .nav-item { font-size: .9rem; }
.tag-soon { margin-left: auto; font-size: .62rem; padding: .1rem .4rem; border-radius: 6px;
  background: rgba(255,255,255,.07); color: var(--muted); }

.content { position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; }
.map-overlay { position: absolute; top: 14px; left: 14px; z-index: 500;
  background: rgba(18, 26, 51, .9); border: 1px solid var(--line); border-radius: 12px;
  padding: .8rem 1rem; box-shadow: var(--shadow); min-width: 190px; backdrop-filter: blur(6px); }
.map-overlay h4 { margin: 0 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat { display: flex; align-items: baseline; gap: .4rem; }
.stat .n { font-size: 1.6rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .85rem; }
.leaflet-popup-content { font-size: .85rem; }
.leaflet-tooltip.imei-label { background: rgba(11, 16, 32, .82); color: #e7ecf6; border: 1px solid var(--line);
  border-radius: 6px; font-size: .72rem; font-weight: 600; padding: 1px 6px; box-shadow: none;
  font-variant-numeric: tabular-nums; }
.leaflet-tooltip.imei-label::before { display: none; }
.dev-pin { background: transparent; border: none; }
.dev-pin svg { display: block; }

/* device marker colour picker */
.color-dot { display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.35); vertical-align: middle; }
.swatches { display: flex; gap: 9px; flex-wrap: wrap; margin-top: .3rem; }
.swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px rgba(255,255,255,.15) inset; transition: transform .1s; }
.swatch:hover { transform: scale(1.1); }
.swatch.sel { border-color: #fff; box-shadow: 0 0 0 3px var(--brand); }
.icon-choices { display: flex; gap: 8px; flex-wrap: wrap; margin-top: .3rem; }
.icon-choice { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  cursor: pointer; border: 2px solid var(--line); background: #0d1428; transition: transform .1s; }
.icon-choice:hover { transform: scale(1.06); border-color: var(--brand); }
.icon-choice.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--brand); }
.marker-prev { display: inline-flex; vertical-align: middle; }

/* password show/hide toggle (eye icon) */
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 34px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: 4px; display: inline-flex; align-items: center; line-height: 0; }
.pw-toggle:hover { color: var(--brand-2); }
.pw-toggle svg { display: block; }

/* info icon + click popover */
.info-tip { position: relative; display: inline-flex; }
.info-btn { background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: 2px; display: inline-flex; line-height: 0; }
.info-btn:hover, .info-tip.open .info-btn { color: var(--brand-2); }
.info-btn svg { display: block; }
.info-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; width: 250px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem .85rem; font-size: .82rem; line-height: 1.5; color: var(--text);
  box-shadow: var(--shadow); display: none; }
.info-tip.open .info-pop { display: block; }

/* search field clear (×) button */
.search-wrap { position: relative; display: inline-flex; }
.search-wrap .filter-input { padding-right: 30px; }
.search-clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 1.25rem; line-height: 1; padding: 0 5px; display: none; }
.search-clear:hover { color: var(--brand-2); }
.search-wrap.has-value .search-clear { display: block; }
.filter-input::-webkit-search-cancel-button { display: none; }

/* geofence list cards (left of the map) */
.gf-card { padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: .6rem; background: var(--panel); cursor: pointer; }
.gf-card:hover { border-color: var(--brand); }
.gf-card.active { border-color: var(--brand); background: var(--panel-2); }
.gf-top { display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: .92rem; margin-bottom: .55rem; gap: .5rem; }
.gf-top .hint { font-weight: 500; }
.gf-actions { display: flex; gap: .4rem; align-items: center; }

@media (max-width: 820px) {
  .features { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; }
  .sidebar { position: fixed; top: 60px; left: 0; bottom: 0; width: 250px; z-index: 1200;
    transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto; }
  .sidebar.open { transform: translateX(0); }
  .app-top { padding: 0 .9rem; }
  .app-top .right > span { display: none; }
}

/* ---------- inner pages ---------- */
.content.scroll { overflow-y: auto; }
.page { padding: 1.6rem 1.8rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .25rem; }
.toolbar { display: flex; gap: .7rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.1rem; }
.toolbar .field { margin: 0; }
.toolbar label { font-size: .72rem; }

.panel { background: linear-gradient(180deg, var(--panel), var(--bg-soft)); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.panel.pad { padding: 1.3rem; }

/* stat cards row */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.stat-card { background: linear-gradient(180deg, var(--panel), var(--bg-soft)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.stat-card .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.stat-card .v { font-size: 1.9rem; font-weight: 800; margin-top: .3rem; }
.stat-card .v small { font-size: .9rem; font-weight: 600; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; background: var(--panel); }
table.table th, table.table td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.table th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; background: var(--bg-soft); position: sticky; top: 0; }
table.table tbody tr:hover { background: rgba(255, 255, 255, .04); }
table.table td.mono, table.table .mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty { padding: 2.5rem; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge.on { background: rgba(52, 211, 153, .16); color: #6ee7b7; }
.badge.off { background: rgba(148, 163, 184, .16); color: #cbd5e1; }
.badge.admin { background: rgba(79, 140, 255, .18); color: #93c5fd; }

/* forms */
select, input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search] {
  padding: .6rem .75rem; border-radius: 10px; border: 1px solid var(--line);
  background: #0d1428; color: var(--text); font-size: .92rem; outline: none;
}
select:focus, input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,140,255,.2); }
.btn-sm { padding: .42rem .8rem; font-size: .82rem; }
.btn-danger { background: rgba(248, 113, 113, .15); border-color: rgba(248,113,113,.4); color: #fecaca; }
.btn-danger:hover { background: rgba(248, 113, 113, .28); }

.flashes { margin-bottom: 1.2rem; display: grid; gap: .6rem; }
.flash { padding: .7rem .95rem; border-radius: 10px; font-size: .88rem; border: 1px solid; }
.flash.success { background: rgba(52,211,153,.12); border-color: rgba(52,211,153,.35); color: #a7f3d0; }
.flash.error { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.35); color: #fecaca; }
.flash.info { background: rgba(79,140,255,.12); border-color: rgba(79,140,255,.35); color: #bfdbfe; }

/* split layout (list + map) */
.split { display: grid; grid-template-columns: 360px 1fr; gap: 1.1rem; height: calc(100vh - 60px - 3.2rem); }
.split .list-col { overflow-y: auto; }
.split .map-col { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.split .map-col .lmap { position: absolute; inset: 0; }
.trip { padding: .8rem .95rem; border: 1px solid var(--line); border-radius: 12px; margin-bottom: .6rem; cursor: pointer; background: var(--panel); }
.trip:hover { border-color: var(--brand); }
.trip.active { border-color: var(--brand); background: var(--panel-2); }
.trip .t-top { display: flex; justify-content: space-between; font-weight: 700; font-size: .9rem; }
.trip .t-sub { color: var(--muted); font-size: .8rem; margin-top: .3rem; display: flex; gap: .8rem; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .9rem; align-items: end; }
.form-grid .field { margin: 0; }
.hint { color: var(--muted); font-size: .8rem; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; height: auto; } .split .map-col { height: 60vh; } }

/* ---------- modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(3, 7, 18, .6); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal { width: 100%; max-width: 430px; background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 1.6rem; }
.modal h3 { margin: 0 0 .3rem; }
.modal .sub { color: var(--muted); font-size: .85rem; margin-bottom: 1.2rem; }
.modal .field input { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.4rem; }
.filter-input { min-width: 240px; }
.modal.modal-wide { max-width: 780px; }
.map-full { position: relative; height: calc(100vh - 60px - 3.2rem - 118px); min-height: 420px;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.map-full .lmap { position: absolute; inset: 0; }
.filter-note { color: var(--muted); font-size: .78rem; margin-top: .3rem; }
tr.filtered-out { display: none; }

/* ---------- permissions grid ---------- */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-top: .5rem; }
.perm-col { border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; background: var(--panel); }
.perm-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .6rem; }
.perm-check { display: flex; align-items: center; gap: .55rem; padding: .32rem 0; font-size: .9rem; cursor: pointer; }
.perm-check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- bar chart (km per day) ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 300px; padding: 22px 2px 0; overflow-x: auto; }
.bar-wrap { display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  flex: 1 0 26px; min-width: 26px; height: 100%; }
.bar { width: 62%; min-height: 2px; border-radius: 6px 6px 0 0; position: relative;
  background: linear-gradient(180deg, var(--brand-2), var(--brand)); transition: filter .12s; }
.bar-wrap:hover .bar { filter: brightness(1.18); }
.bar-val { position: absolute; top: -17px; left: 50%; transform: translateX(-50%);
  font-size: .68rem; color: var(--muted); white-space: nowrap; }
.bar-lbl { margin-top: 7px; font-size: .66rem; color: var(--muted); white-space: nowrap;
  transform: rotate(-35deg); transform-origin: center; }
