/*
 * gTracker admin panel.
 *
 * Design tokens and component styles follow the Gigant house system used in
 * Qapan, so the two panels feel like one product: cyan brand mark, dark navy
 * shell by default, and a light theme that flips only the token values.
 */

:root {
    --brand:        #35c2da;   /* Gigant cyan, from the logo mark */
    --brand-dark:   #1d9fb6;
    --brand-soft:   rgba(53, 194, 218, .12);
    --sidebar-w:    236px;
    --sidebar-w-sm: 64px;
    --radius:       10px;

    --logo-icon:   39px;
    --logo-text-h: 25px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, sans-serif;
    --mono: "SF Mono", SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

/* ---- Dark theme (default) ------------------------------------------------ */
:root, :root[data-theme="dark"] {
    --bg:          #0d1520;
    --bg-elevated: #14202e;
    --panel:       #16222f;
    --panel-2:     #0f1a25;
    --border:      #223141;
    --border-soft: #1a2733;
    --text:        #e8eef5;
    --text-2:      #93a7bd;
    --text-3:      #6b7f95;
    --sidebar-bg:  #101a25;
    --input-bg:    #0b131c;
    --green:       #2ea043;
    --amber:       #d29922;
    --red:         #e5534b;
    --shadow:      0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.24);
    --logo-invert: 1;
    --icon-invert: 1;
    --map-bg:      #0b131c;
}

/* ---- Light theme --------------------------------------------------------- */
:root[data-theme="light"] {
    --bg:          #f5f7fa;
    --bg-elevated: #ffffff;
    --panel:       #ffffff;
    --panel-2:     #f8fafc;
    --border:      #dfe6ee;
    --border-soft: #eaeff5;
    --text:        #17232f;
    --text-2:      #5a6b7d;
    --text-3:      #8496a8;
    --sidebar-bg:  #ffffff;
    --input-bg:    #ffffff;
    --green:       #1a7f37;
    --amber:       #9a6700;
    --red:         #cf222e;
    --shadow:      0 1px 2px rgba(16,32,48,.06), 0 6px 18px rgba(16,32,48,.07);
    --logo-invert: 0;
    --icon-invert: 0;
    --map-bg:      #e8eef5;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14.5px/1.55 var(--font);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .92em; }

[x-cloak] { display: none !important; }

/* ---- Layout shell -------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width .18s ease, flex-basis .18s ease;
    z-index: 20;
}
:root.sidebar-collapsed .sidebar {
    width: var(--sidebar-w-sm);
    flex-basis: var(--sidebar-w-sm);
}

.brand-row {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    min-height: calc(var(--logo-icon) + 28px);
}
.brand-row .icon { flex: 0 0 auto; }
.brand-row .icon img { height: var(--logo-icon); width: auto; display: block; }
.brand-row .word { overflow: hidden; }
/* The wordmark is black artwork loaded via <img>, so currentColor inside the
   SVG cannot inherit the page colour — invert it to white on dark. */
.brand-row .word img {
    height: var(--logo-text-h); width: auto; display: block;
    filter: invert(var(--logo-invert));
}
:root.sidebar-collapsed .brand-row { padding-left: 0; padding-right: 0; justify-content: center; }
:root.sidebar-collapsed .brand-row .word { display: none; }

.nav-group { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-label {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--text-3); font-weight: 700; padding: 10px 10px 6px;
}
:root.sidebar-collapsed .nav-label { opacity: 0; height: 8px; padding: 0; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; margin-bottom: 2px;
    border-radius: 8px; color: var(--text-2);
    font-size: 14px; font-weight: 500;
    white-space: nowrap; text-decoration: none;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--brand-soft); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item .ic { flex: 0 0 18px; width: 18px; height: 18px; display: grid; place-items: center; }
.nav-item .ic svg { width: 17px; height: 17px; stroke-width: 1.9; }
.nav-item .count {
    margin-left: auto; font-size: 11px; font-weight: 700;
    background: var(--red); color: #fff;
    border-radius: 20px; padding: 1px 7px; min-width: 20px; text-align: center;
}
:root.sidebar-collapsed .nav-item { justify-content: center; padding: 10px 0; }
:root.sidebar-collapsed .nav-item .lbl,
:root.sidebar-collapsed .nav-item .count { display: none; }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding: 10px; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 8px; margin-bottom: 6px;
    overflow: hidden;
}
.avatar {
    flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #04222a; font-weight: 700; font-size: 12.5px;
    display: grid; place-items: center; text-transform: uppercase;
}
.user-chip .who { min-width: 0; }
.user-chip .nm {
    font-size: 13px; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-chip .rl { font-size: 11px; color: var(--text-3); }
:root.sidebar-collapsed .user-chip { justify-content: center; padding: 8px 0; }
:root.sidebar-collapsed .user-chip .who { display: none; }

/* ---- Main column --------------------------------------------------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: calc(var(--logo-icon) + 28px);
    flex: 0 0 calc(var(--logo-icon) + 28px);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 15;
}
.icon-btn {
    width: 34px; height: 34px; flex: 0 0 34px;
    border: 1px solid var(--border); background: transparent;
    color: var(--text-2); border-radius: 8px;
    display: grid; place-items: center; cursor: pointer; padding: 0;
    transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.icon-btn svg { width: 17px; height: 17px; stroke-width: 2; }
.page-title { font-size: 15.5px; font-weight: 650; }
.topbar .spacer { margin-left: auto; }

.live-pill {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 600; color: var(--red);
    background: color-mix(in srgb, var(--red) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
    padding: 5px 11px; border-radius: 20px;
}
.live-pill .dot {
    width: 7px; height: 7px; border-radius: 50%; background: var(--red);
    animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.content { padding: 24px 20px 60px; width: 100%; }

/* ---- Typography ---------------------------------------------------------- */
h1 { font-size: 21px; margin: 0 0 5px; font-weight: 680; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 4px; font-weight: 650; }
.sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 20px; }

/* ---- Panels -------------------------------------------------------------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.panel.flush { padding: 0; overflow: hidden; }
.panel + .panel { margin-top: 16px; }
.panel-title { font-size: 15px; font-weight: 650; margin: 0 0 4px; }
.panel-head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--border-soft);
}
.panel-head h2 { margin: 0; }
.panel-head .spacer { margin-left: auto; }

/* ---- Stat cards ---------------------------------------------------------- */
.stat-grid {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    margin-bottom: 18px;
}
.stat {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    box-shadow: var(--shadow);
}
.stat .k {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-3); font-weight: 700;
}
.stat .v {
    font-size: 26px; font-weight: 700; margin-top: 6px;
    letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.stat .v.brand { color: var(--brand); }
.stat .v.green { color: var(--green); }
.stat .v.amber { color: var(--amber); }
.stat .v.red   { color: var(--red); }
.stat .u { font-size: 13px; font-weight: 600; color: var(--text-3); margin-left: 3px; }

/* ---- Buttons ------------------------------------------------------------- */
button, .btn {
    font: inherit; font-weight: 600; font-size: 13.5px;
    padding: 8px 15px; border: 1px solid transparent; border-radius: 8px;
    background: var(--brand); color: #062730;
    cursor: pointer; text-decoration: none; display: inline-block;
    transition: filter .12s, opacity .12s;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-green { background: var(--green); color: #fff; }
.btn-red   { background: var(--red);   color: #fff; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.btn-sm { font-size: 12px; padding: 5px 11px; font-weight: 550; }
.btn-link {
    background: none; border: none; padding: 0; color: var(--text-2);
    font-size: 12.5px; font-weight: 550; cursor: pointer;
}
.btn-link:hover { color: var(--brand); filter: none; }
.btn-link.danger:hover { color: var(--red); }

/* ---- Forms --------------------------------------------------------------- */
input[type=text], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=time],
input[type=email], input[type=search], input[type=tel], input[type=url],
select, textarea {
    font: inherit; width: 100%; padding: 9px 11px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
input[type=date], input[type=datetime-local], input[type=time] {
    min-height: 40px; -webkit-appearance: none; appearance: none;
}
input[type=date]::-webkit-calendar-picker-indicator,
input[type=datetime-local]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator {
    cursor: pointer; opacity: .6;
    filter: invert(var(--icon-invert, 1));
}
input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
input[type=range] { width: 100%; accent-color: var(--brand); padding: 0; }
input[type=checkbox] { accent-color: var(--brand); width: 15px; height: 15px; }

label { display: block; font-size: 12.5px; color: var(--text-2);
        margin: 12px 0 5px; font-weight: 550; }
label.inline {
    display: flex; align-items: center; gap: 9px; margin: 10px 0;
    font-size: 13.5px; color: var(--text); cursor: pointer;
}
label.inline input { width: auto; margin: 0; }
.req { color: var(--red); }
.hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.field-err { font-size: 11.5px; color: var(--red); margin-top: 5px; }

.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(2, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.form-actions {
    display: flex; gap: 9px; margin-top: 22px;
    padding-top: 18px; border-top: 1px solid var(--border-soft);
}

/* ---- Filter bar ---------------------------------------------------------- */
.filters {
    display: flex; flex-wrap: wrap; gap: 9px; align-items: flex-end;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.filters .f { min-width: 150px; }
.filters .f label { margin-top: 0; }
.filters .spacer { margin-left: auto; }

/* ---- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--text-3); font-size: 11px; text-transform: uppercase;
     letter-spacing: .05em; font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td.num { font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline; }
td.actions > * + * { margin-left: 12px; }
.empty { text-align: center; color: var(--text-3); padding: 44px 10px; }

/* ---- Tags ---------------------------------------------------------------- */
.tag {
    font-size: 11px; padding: 2.5px 9px; border-radius: 20px; font-weight: 600;
    background: var(--border); color: var(--text-2); display: inline-block;
    white-space: nowrap;
}
.tag.on     { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.tag.off    { background: var(--border); color: var(--text-3); }
.tag.warn   { background: color-mix(in srgb, var(--amber) 20%, transparent); color: var(--amber); }
.tag.brand  { background: var(--brand-soft); color: var(--brand); }
.tag.danger { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.muted { color: var(--text-2); }
.dim   { color: var(--text-3); }
.mono  { font-family: var(--mono); font-size: 12px; }

/* ---- Alerts -------------------------------------------------------------- */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert-err  { background: color-mix(in srgb, var(--red) 12%, transparent);
              border: 1px solid color-mix(in srgb, var(--red) 45%, transparent); }
.alert-ok   { background: color-mix(in srgb, var(--green) 12%, transparent);
              border: 1px solid color-mix(in srgb, var(--green) 45%, transparent); }
.alert-warn { background: color-mix(in srgb, var(--amber) 12%, transparent);
              border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent); }
.alert ul { margin: 0; padding-left: 18px; }

/* ---- Feed list (alerts, activity) ---------------------------------------- */
.feed { display: flex; flex-direction: column; }
.feed-item {
    display: flex; gap: 11px; padding: 11px 18px;
    border-bottom: 1px solid var(--border-soft);
}
.feed-item:last-child { border-bottom: 0; }
.feed-item .sev {
    flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px;
}
.sev-critical { background: var(--red); }
.sev-warning  { background: var(--amber); }
.sev-info     { background: var(--text-3); }
.feed-item .body { min-width: 0; flex: 1; }
.feed-item .t { font-size: 13.5px; font-weight: 600; }
.feed-item .m { font-size: 12.5px; color: var(--text-2); margin-top: 1px; }
.feed-item .w { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }

/* ---- Maps ---------------------------------------------------------------- */
.leaflet-container { background: var(--map-bg); font: inherit; }
.map { width: 100%; border-radius: var(--radius); overflow: hidden;
       border: 1px solid var(--border); }
.map-tall { height: 70vh; min-height: 420px; }
.map-mid  { height: 60vh; min-height: 380px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: var(--panel); color: var(--text);
    box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.leaflet-bar a, .leaflet-bar a:hover {
    background: var(--panel); color: var(--text); border-color: var(--border);
}
.leaflet-tooltip {
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border); box-shadow: var(--shadow);
}
.leaflet-tooltip-left::before { border-left-color: var(--border); }
.leaflet-tooltip-right::before { border-right-color: var(--border); }

.legend {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 11px 16px; margin-top: 14px;
    font-size: 12px; color: var(--text-2); box-shadow: var(--shadow);
}
.legend .k { display: flex; align-items: center; gap: 7px; }
.legend .swatch { width: 11px; height: 11px; border-radius: 50%; }
.legend .line { width: 22px; height: 3px; border-radius: 2px; }
.legend .spacer { margin-left: auto; }

/* ---- Split layout (map + side list) -------------------------------------- */
.split { display: grid; gap: 16px; grid-template-columns: 2.4fr 1fr; }
.split-wide { grid-template-columns: 2fr 1fr; }
.side-list { max-height: 62vh; overflow-y: auto; }

.fleet-row {
    display: block; width: 100%; text-align: left; cursor: pointer;
    background: none; border: none; border-bottom: 1px solid var(--border-soft);
    padding: 11px 16px; color: inherit; font: inherit; border-radius: 0;
}
.fleet-row:hover { background: var(--panel-2); filter: none; }
.fleet-row .top { display: flex; align-items: center; gap: 8px; }
.fleet-row .plate { font-weight: 650; font-size: 13.5px; }
.fleet-row .dot { width: 8px; height: 8px; border-radius: 50%; margin-left: auto; }
.fleet-row .meta { font-size: 12px; color: var(--text-3); margin-top: 2px;
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fleet-row .stats { font-size: 12px; color: var(--text-2); margin-top: 4px;
                    font-variant-numeric: tabular-nums; }

/* ---- Playback ------------------------------------------------------------ */
.playback {
    display: flex; align-items: center; gap: 14px;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px; margin-top: 14px;
    box-shadow: var(--shadow);
}
.playback input[type=range] { flex: 1; }
.playback select { width: auto; }
.playback-label {
    font-size: 12.5px; color: var(--text-2); margin-top: 10px;
    font-variant-numeric: tabular-nums;
}

/* ---- Bars (report charts) ------------------------------------------------ */
.bar-row + .bar-row { margin-top: 13px; }
.bar-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar-track { height: 8px; border-radius: 5px; background: var(--border); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: var(--brand); }

/* ---- Pagination ---------------------------------------------------------- */
.pagination { display: flex; gap: 5px; list-style: none; padding: 0; margin: 16px 0 0;
              flex-wrap: wrap; align-items: center; font-size: 13px; }
.pagination li span, .pagination li a {
    display: block; padding: 6px 11px; border-radius: 7px;
    border: 1px solid var(--border); color: var(--text-2);
}
.pagination li a:hover { background: var(--brand-soft); color: var(--brand);
                         border-color: var(--brand); text-decoration: none; }
.pagination li.active span { background: var(--brand); color: #062730;
                             border-color: var(--brand); font-weight: 650; }
.pagination li.disabled span { opacity: .4; }
.pagination svg { width: 14px; height: 14px; }

/* ---- Login --------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .marks {
    display: flex; align-items: center; justify-content: center; gap: 11px;
    margin-bottom: 16px;
}
.login-brand .marks .ic img { height: 52px; display: block; }
.login-brand .marks .wd img { height: 32px; display: block;
                              filter: invert(var(--logo-invert)); }
.login-brand h1 { font-size: 19px; margin-bottom: 3px; }
.login-brand p { color: var(--text-2); font-size: 13.5px; margin: 0; }

/* ---- Responsive logo ----------------------------------------------------- */
@media (max-width: 1100px) { :root { --logo-icon: 35px; --logo-text-h: 22px; } }
@media (max-width: 820px)  { :root { --logo-icon: 32px; --logo-text-h: 20px; } }
@media (max-width: 480px)  { :root { --logo-icon: 28px; --logo-text-h: 18px; } }

@media (max-width: 1000px) {
    .split, .split-wide { grid-template-columns: 1fr; }
    .side-list { max-height: 340px; }
}

/* ---- Mobile -------------------------------------------------------------- */
.scrim { display: none; }
@media (max-width: 820px) {
    .sidebar {
        position: fixed; left: 0; top: 0;
        transform: translateX(-100%); transition: transform .2s ease;
        width: var(--sidebar-w); flex-basis: var(--sidebar-w);
    }
    :root.sidebar-open .sidebar { transform: translateX(0); }
    :root.sidebar-collapsed .sidebar {
        width: var(--sidebar-w); flex-basis: var(--sidebar-w);
    }
    :root.sidebar-collapsed .nav-item { justify-content: flex-start; padding: 9px 11px; }
    :root.sidebar-collapsed .nav-item .lbl,
    :root.sidebar-collapsed .nav-item .count,
    :root.sidebar-collapsed .brand-row .word,
    :root.sidebar-collapsed .user-chip .who { display: block; }
    :root.sidebar-collapsed .nav-label { opacity: 1; height: auto; padding: 10px 10px 6px; }
    :root.sidebar-open .scrim {
        display: block; position: fixed; inset: 0;
        background: rgba(0,0,0,.5); z-index: 19;
    }
    .content { padding: 18px 14px 50px; }
    .form-grid { grid-template-columns: 1fr; }
}

/* ---- Route alternatives on the map --------------------------------------- */
/* A summary pinned to each option's midpoint, so the choices are told apart
   even where the roads run close together. */
.route-badge {
    display: inline-block;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    padding: 4px 10px;
    border-radius: 20px;
    font: 600 11.5px/1 var(--font);
    font-variant-numeric: tabular-nums;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
}
.route-badge:hover { border-color: var(--brand); color: var(--brand); }
.route-badge.is-selected {
    background: var(--brand);
    color: #062730;
    border-color: var(--brand);
}
