:root {
    --bg: #0b1220;
    --panel: #151f33;
    --panel-2: #111a2b;
    --line: rgba(255, 255, 255, .07);
    --ink: #e7eef8;
    --muted: #8493ad;
    --teal: #2dd4bf;
    --cyan: #34d3e6;
    --blue: #3b82f6;
    --green: #16a34a;
    --amber: #f59e0b;
    --red: #f87171;
    --grad: linear-gradient(180deg, #2dd4bf 0%, #3b82f6 100%);
    --grad-h: linear-gradient(90deg, #2dd4bf 0%, #3b82f6 100%);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); }

.app { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
    width: 72px; flex: 0 0 72px;
    background: var(--panel-2); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; align-items: center;
    padding: 18px 0; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
    width: 40px; height: 40px; border-radius: 11px; background: var(--grad);
    color: #04121a; font-weight: 800; font-size: 20px;
    display: grid; place-items: center; margin-bottom: 22px;
}
.sidebar .nav {
    width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
    color: var(--muted); text-decoration: none; transition: background .15s, color .15s;
}
.sidebar .nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar .nav:hover { color: var(--ink); background: rgba(255, 255, 255, .04); }
.sidebar .nav.active { color: var(--teal); background: rgba(45, 212, 191, .12); }
.sidebar .nav.bottom { margin-top: auto; }

/* ---- Main / topbar ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 20px; padding: 16px 26px; border-bottom: 1px solid var(--line); }
.brand-name { font-weight: 800; letter-spacing: .06em; font-size: 15px; }
.brand-name span { color: var(--teal); }
.search { flex: 1; max-width: 440px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); font: inherit; outline: none; }
.search input::placeholder { color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad); color: #04121a; font-weight: 700; display: grid; place-items: center; }

.content { padding: 22px 26px 40px; }
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head h1 span { color: var(--muted); font-weight: 400; }
.page-head .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 14px; }

/* ---- Buttons ---- */
.button, button.button { display: inline-block; border: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: .5rem .9rem; border-radius: 9px; background: var(--grad-h); color: #04121a; text-decoration: none; }
.button:hover { filter: brightness(1.08); }
.button.alt { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.button.small { padding: .28rem .6rem; font-size: 12px; }

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 18px 16px; position: relative; overflow: hidden; }
.tile::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--grad); opacity: .9; }
.tile-ico { font-size: 18px; color: var(--teal); }
.tile-ico.moving { color: var(--green); }
.tile-ico.warn { color: var(--amber); }
.tile-num { font-size: 34px; font-weight: 800; line-height: 1.1; margin: 6px 0 2px; letter-spacing: -.01em; }
.tile-lbl { font-size: 13px; font-weight: 600; }
.tile-lbl span { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---- Cards / grids ---- */
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid-hero { grid-template-columns: 2fr 1fr; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.card-num { font-size: 30px; font-weight: 800; color: var(--teal); line-height: 1; }
.card-num span { font-size: 15px; color: var(--muted); margin-left: 4px; }
.card-title { font-size: 14px; font-weight: 600; margin-top: 4px; }
.card-title.big { font-size: 15px; }
.card-title span { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---- SVG chart ---- */
.chart { width: 100%; height: auto; display: block; margin-top: 6px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { transition: opacity .15s; }
.chart .bar:hover { opacity: .82; }
.chart .bar-val { fill: var(--teal); font-size: 12px; font-weight: 700; }
.chart .bar-lbl { fill: var(--muted); font-size: 11px; }

.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut { width: 180px; height: 180px; flex: 0 0 auto; }
.donut-track { fill: none; stroke: rgba(255, 255, 255, .06); stroke-width: 20; }
.donut circle { stroke-linecap: butt; }
.donut-num { fill: var(--ink); font-size: 34px; font-weight: 800; }
.donut-sub { fill: var(--muted); font-size: 11px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.legend b { color: var(--ink); margin-left: 6px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---- Progress bars ---- */
.bars { display: flex; flex-direction: column; gap: 13px; margin-top: 8px; }
.prow { display: grid; grid-template-columns: 130px 1fr 56px; align-items: center; gap: 12px; }
.plabel { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptrack { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.pfill { height: 100%; border-radius: 999px; background: var(--grad-h); }
.pfill.low { background: linear-gradient(90deg, var(--amber), #ef4444); }
.pval { font-size: 12.5px; color: var(--muted); text-align: right; }
.pval.low { color: var(--red); font-weight: 700; }
.more { display: inline-block; margin-top: 14px; color: var(--teal); text-decoration: none; font-size: 13px; font-weight: 600; }
.more:hover { text-decoration: underline; }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 26px; }

/* ---- Tables ---- */
.fleet-table { width: 100%; border-collapse: collapse; margin-top: .5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.fleet-table th, .fleet-table td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); font-size: 13px; }
.fleet-table thead th { color: var(--muted); font-weight: 600; background: var(--panel-2); }
.fleet-table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.fleet-table .inactive-row { opacity: .5; }
.fleet-table .caps .cap { display: inline-block; font-size: .65rem; font-weight: 700; background: rgba(45, 212, 191, .14); color: var(--teal); padding: .1rem .35rem; border-radius: 4px; margin-right: .2rem; }
.fleet-table .yes { color: var(--green); font-weight: 600; }
.fleet-table .no { color: var(--muted); }
.muted { color: var(--muted); }
.fleet-hint { color: var(--muted); font-size: .85rem; max-width: 70ch; line-height: 1.5; }

/* ---- Forms ---- */
.fleet-filter-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; margin: .5rem 0 1rem; }
label { color: var(--ink); }
.fleet-filter-form label { display: flex; flex-direction: column; font-size: .78rem; color: var(--muted); gap: .25rem; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: .45rem .6rem; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); }
.fleet-caps { border: 1px solid var(--line); border-radius: 10px; padding: .7rem 1rem; margin: 1rem 0; }
.fleet-caps legend { padding: 0 .4rem; color: var(--muted); font-size: .85rem; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin-right: 1.2rem; }
.form-actions { margin-top: 1rem; display: flex; gap: .5rem; align-items: center; }
form label { display: block; margin: .8rem 0 .3rem; font-size: 13px; }
form input[type=text], form input[type=month], form input[type=date] { min-width: 260px; }

/* ---- Live map ---- */
.fleet-topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.fleet-legend { display: flex; align-items: center; gap: .9rem; font-size: .85rem; color: var(--muted); }
.fleet-legend .lg { display: inline-flex; align-items: center; gap: .35rem; }
.fleet-legend .lg::before { content: ''; width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.fleet-legend .moving::before { background: var(--green); }
.fleet-legend .idle::before { background: var(--cyan); }
.fleet-legend .offline::before { background: var(--muted); }
.fleet-updated { color: var(--muted); font-size: .8rem; margin: .25rem 0 .5rem; }

.fleet-live { display: flex; gap: 1rem; height: 70vh; min-height: 420px; margin-top: .5rem; }
.fleet-map { flex: 1 1 65%; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); z-index: 0; }
.fleet-list { flex: 1 1 35%; max-width: 440px; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.fleet-list-head { display: flex; gap: .5rem; align-items: center; padding: .6rem; border-bottom: 1px solid var(--line); }
.fleet-list-head input { flex: 1; }
.fleet-count { font-size: .8rem; color: var(--muted); min-width: 1.5rem; text-align: center; }
#fleet-list-items { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.fleet-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.fleet-item:hover { background: rgba(255, 255, 255, .03); }
.fleet-item.active { background: rgba(45, 212, 191, .1); }
.fleet-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.fleet-item .fi-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.fleet-item .fi-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-item .fi-sub { font-size: .78rem; color: var(--muted); }
.fleet-item .fi-meta { font-size: .78rem; color: var(--ink); white-space: nowrap; }
.fleet-item.status-offline { opacity: .55; }
.fleet-item .fi-detail { background: none; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 0 .2rem; flex: 0 0 auto; line-height: 1; }
.fleet-item .fi-detail:hover { color: var(--teal); }

/* ---- Detail panel ---- */
.fleet-detail { position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 92vw; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0, 0, 0, .5); transform: translateX(100%); transition: transform .25s ease; z-index: 1200; overflow-y: auto; }
.fleet-detail.open { transform: translateX(0); }
.fleet-detail-inner { padding: 1rem 1.1rem 2rem; }
.fleet-detail-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); opacity: 0; visibility: hidden; transition: opacity .2s; z-index: 1100; }
.fleet-detail-backdrop.open { opacity: 1; visibility: visible; }
.fd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.fd-title { font-size: 1.1rem; font-weight: 700; }
.fd-sub { color: var(--muted); font-size: .82rem; margin-top: .1rem; }
.fd-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); }
.fd-close:hover { color: var(--ink); }
.fd-stats { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 1rem 0 .4rem; }
.fd-stats div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; }
.fd-stats span { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.fd-stats strong { font-size: .95rem; }
.fd-loc { color: var(--ink); font-size: .85rem; margin: .3rem 0 0; }
.fd-empty { color: var(--muted); font-size: .85rem; }
.fd-section-title { font-weight: 700; margin: 1.2rem 0 .5rem; border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
.fd-section-title span { font-weight: 400; color: var(--muted); font-size: .8rem; }
.fd-trips, .fd-loads { list-style: none; margin: 0; padding: 0; }
.fd-trips li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.fd-trip-route { font-size: .82rem; }
.fd-arrow { color: var(--muted); margin: 0 .25rem; }
.fd-trip-meta { font-size: .75rem; color: var(--muted); margin-top: .15rem; }
.fd-loads li { padding: .3rem 0; font-size: .82rem; color: var(--ink); }
.fd-badge { display: inline-block; font-size: .65rem; font-weight: 700; border-radius: 4px; padding: .1rem .4rem; margin-right: .4rem; }
.fd-badge.load { background: rgba(22, 163, 74, .2); color: #4ade80; }
.fd-badge.unload { background: rgba(248, 113, 113, .18); color: var(--red); }
.fd-actions { margin-top: 1.2rem; }

@media (max-width: 900px) {
    .kpis { grid-template-columns: repeat(2, 1fr); }
    .grid-hero, .grid-2 { grid-template-columns: 1fr; }
    .prow { grid-template-columns: 110px 1fr 48px; }
    .fleet-live { flex-direction: column; height: auto; }
    .fleet-map { height: 52vh; }
    .fleet-list { max-width: none; height: 40vh; }
}
