:root {
    --brand: #146c43;
    --brand-dark: #0d3d27;
    --brand-deep: #0a2e1e;
    --accent: #f2a900;
    --ink: #16231d;
    --muted: #52645a;
    --bg: #f3f6f4;
    --card: #ffffff;
    --line: #e2e8e4;
    --danger: #c0392b;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(16, 45, 32, .06);
}

/* High-contrast light theme for the authenticated admin area. */
.app-body {
    --bg: #f7faf8;
    --ink: #0b1f14;
    --muted: #3f5548;
    --card: #ffffff;
    --line: #c7d8ce;
    --brand: #0b5d36;
    --brand-dark: #083d24;
    --brand-deep: #062b19;
    --shadow: 0 8px 24px rgba(8, 61, 36, .08);
    background: var(--bg);
    color: var(--ink);
}

* { box-sizing: border-box; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: .94rem;
}

a { text-decoration: none; }

h1, h2, h3, h4, h5 { font-weight: 700; letter-spacing: -.02em; }

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: 264px;
    flex: 0 0 264px;
    background: #ffffff;
    border-right: 1px solid var(--line);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    padding: 20px 16px;
    box-shadow: 6px 0 24px rgba(8, 61, 36, .04);
    transition: transform .25s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 18px; border-bottom: 1px solid var(--line); }
.sidebar-brand strong { display: block; font-size: 1.12rem; color: var(--ink); letter-spacing: -.02em; }
.sidebar-brand small { color: var(--muted); font-size: .74rem; display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--accent), #ffc94d);
    color: #3a2a00; font-size: 1.2rem; flex: 0 0 40px;
}
.brand-mark.large { width: 58px; height: 58px; font-size: 1.7rem; border-radius: 16px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding-top: 16px; }
.sidebar-nav::-webkit-scrollbar { width: 0; }
.nav-label { display: block; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); padding: 6px 10px; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    color: #233a2c; padding: 10px 12px; border-radius: 11px;
    margin-bottom: 3px; font-weight: 600; font-size: .88rem;
    transition: background .15s, color .15s;
}
.nav-item i { font-size: 1.02rem; width: 20px; text-align: center; }
.nav-item:hover { background: #e8f3ed; color: var(--brand-dark); }
.nav-item.active { background: var(--brand); color: #ffffff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-dot { margin-left: auto; background: var(--danger); color: #fff; font-size: .68rem; padding: 2px 7px; border-radius: 20px; }
.sidebar-footer { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
    background: var(--brand); color: #ffffff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .8rem;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta strong { display: block; color: var(--ink); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--muted); font-size: .72rem; text-transform: capitalize; }
.sidebar-logout { color: var(--muted); padding: 2px 4px; }
.sidebar-logout:hover { color: var(--ink); }

/* ---------- Main ---------- */
.main-area { flex: 1; margin-left: 264px; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 76px; display: flex; align-items: center; gap: 14px;
    padding: 0 28px; background: #ffffff;
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1020;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 1.22rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title span { font-size: .74rem; }
.topbar-actions { display: flex; gap: 6px; }
.btn-icon {
    width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
    background: #f2f7f4; color: var(--ink); display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: #e4efe8; }
.notify-dot {
    position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff;
    font-size: .6rem; min-width: 17px; height: 17px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.content { padding: 26px 28px 48px; }

.app-body .text-muted { color: var(--muted) !important; }
.app-body .table { --bs-table-color: var(--ink); --bs-table-hover-color: var(--ink); }
.app-body .card { color: var(--ink); }

.sidebar-backdrop { display: none; }

/* ---------- Cards / layout ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--card); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); padding: 16px 20px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-body { padding: 20px; }
.card-title { font-size: .95rem; margin: 0; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.section-head h2 { font-size: 1.05rem; margin: 0; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: .82rem; }

.kpi { padding: 18px; height: 100%; position: relative; overflow: hidden; }
.kpi .kpi-icon {
    width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    background: #e8f3ed; color: var(--brand); font-size: 1.15rem; margin-bottom: 14px;
}
.kpi .kpi-label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.kpi .kpi-sub { color: var(--muted); font-size: .76rem; margin-top: 4px; }
.kpi.alert-kpi .kpi-icon { background: #fdecea; color: var(--danger); }
.kpi.warn-kpi .kpi-icon { background: #fdf3dd; color: #8a5a00; }

/* ---------- Tables ---------- */
.table { margin: 0; --bs-table-bg: transparent; }
.table > :not(caption) > * > * { padding: 12px 14px; vertical-align: middle; }
.table thead th { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tbody tr { border-bottom: 1px solid #f0f4f1; }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: #f8fbf9; }
.table-responsive { border-radius: var(--radius); }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: .82rem; }

/* ---------- Badges ---------- */
.badge-status {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 30px; font-size: .72rem; font-weight: 700;
    text-transform: capitalize; white-space: nowrap;
}
.badge-status.success { background: #e6f5ec; color: #147a45; }
.badge-status.info { background: #e7f1fb; color: #1d6fa5; }
.badge-status.warning { background: #fdf3dd; color: #7a4f00; }
.badge-status.danger { background: #fdecea; color: #b02a1c; }
.badge-status.secondary { background: #eef1ef; color: #5d6c64; }

/* ---------- Buttons ---------- */
.btn-brand { background: var(--brand); color: #fff; border: 0; font-weight: 600; border-radius: 10px; }
.btn-brand:hover, .btn-brand:focus { background: #0f5736; color: #fff; }
.btn-outline-brand { border: 1px solid var(--brand); color: var(--brand); border-radius: 10px; font-weight: 600; }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }
.btn-sm { border-radius: 8px; }
.btn-ghost { background: #f1f5f2; border: 1px solid var(--line); color: var(--ink); border-radius: 9px; }
.btn-ghost:hover { background: #e6eee9; }

/* ---------- Forms ---------- */
.form-label { font-size: .78rem; font-weight: 700; color: #40544a; margin-bottom: 5px; }
.form-control, .form-select { border-radius: 10px; border-color: #d8e2dc; padding: 9px 12px; font-size: .9rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(20,108,67,.12); }
.input-group-text { background: #f4f8f5; border-color: #d8e2dc; color: var(--muted); }
.form-text { font-size: .74rem; }
.invalid-feedback { display: block; }
.required::after { content: " *"; color: var(--danger); }

/* ---------- Tanks ---------- */
.tank-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; background: #fbfdfc; }
.tank-name { font-weight: 700; font-size: .85rem; }
.tank-kind { font-size: .65rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tank-value { font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; }
.tank-bar { height: 10px; border-radius: 20px; background: #e6ece8; overflow: hidden; margin: 8px 0 6px; }
.tank-fill { height: 100%; border-radius: 20px; background: linear-gradient(90deg, #1a8a57, #37b97c); }
.tank-fill.low { background: linear-gradient(90deg, #c0392b, #e67e22); }
.tank-fill.mid { background: linear-gradient(90deg, #b97c00, #f2a900); }

/* ---------- Alerts / timeline ---------- */
.alert-item { display: flex; gap: 12px; padding: 13px 0; border-bottom: 1px solid #f0f4f1; }
.alert-item:last-child { border-bottom: 0; }
.alert-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: 0 0 9px; background: var(--muted); }
.alert-dot.danger { background: var(--danger); box-shadow: 0 0 0 4px #fdecea; }
.alert-dot.warning { background: #d99a00; box-shadow: 0 0 0 4px #fdf3dd; }
.alert-dot.info { background: #2a86c8; box-shadow: 0 0 0 4px #e7f1fb; }
.alert-item strong { font-size: .85rem; display: block; }
.alert-item small { color: var(--muted); font-size: .74rem; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: #e3ebe6; }
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before {
    content: ""; position: absolute; left: -21px; top: 4px; width: 10px; height: 10px;
    border-radius: 50%; background: var(--brand); border: 2px solid #fff; box-shadow: 0 0 0 2px #cfe5d9;
}
.timeline-item strong { font-size: .85rem; }
.timeline-item small { color: var(--muted); font-size: .73rem; display: block; }

/* ---------- Misc ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; background: #eef4f0; color: #375244; border-radius: 30px; padding: 5px 12px; font-size: .76rem; font-weight: 600; }
.chip-live { background: #ffffff; color: var(--brand-dark); border: 1px solid #b7d8c7; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.muted { color: var(--muted); }
.metric { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed #e8eee9; font-size: .85rem; }
.metric:last-child { border-bottom: 0; }
.metric span:first-child { color: var(--muted); }
.metric strong { text-align: right; }
.empty-state { text-align: center; padding: 38px 18px; color: var(--muted); }
.empty-state i { font-size: 2rem; display: block; margin-bottom: 8px; opacity: .45; }
.app-alert { border: 0; border-radius: 12px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: flex-start; }
.app-alert i { font-size: 1.1rem; margin-top: 1px; }
.app-alert > div { flex: 1; }

.map-box { height: 300px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.map-box.small { height: 220px; }
.leaflet-container { font-family: inherit; }

.photo-thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }
.evidence-box { border: 1px dashed #cfded5; border-radius: 12px; padding: 12px; background: #fafdfb; }

.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.source-cell { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fbfdfc; }
.source-cell span { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.source-cell strong { font-size: 1.1rem; }
.source-cell.missing { border-style: dashed; color: var(--muted); }

.ledger-hash { font-family: Consolas, monospace; font-size: .68rem; word-break: break-all; color: #567267; }
.hero-strip { background: #e8f5ee; background: linear-gradient(120deg, #f2fbf6, #e8f5ee 60%, #dff0e7); color: var(--ink); border: 1px solid #b7d8c7; border-left: 6px solid var(--brand); border-radius: 18px; padding: 24px; position: relative; overflow: hidden; }
.hero-strip::after { content: ""; position: absolute; right: -40px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: rgba(242,169,0,.16); }
.hero-strip h2 { font-size: 1.3rem; }
.hero-strip p { color: #2f4a3b; margin: 0; font-size: .88rem; }

/* ---------- Auth ---------- */
.auth-body { background: #0b2e1e; min-height: 100vh; }
.auth-shell { display: grid; grid-template-columns: 1.05fr .95fr; min-height: 100vh; }
.auth-brand {
    padding: 64px 60px; color: #e8f5ee;
    background: #0a2e1e;
    background: radial-gradient(900px 500px at 10% 0%, rgba(242,169,0,.18), transparent 60%), linear-gradient(150deg, #0a2e1e, #0e442c 65%, #105235);
    display: flex; flex-direction: column; justify-content: center;
}
.auth-brand h1 { font-size: 2.6rem; color: #fff; margin: 18px 0 8px; }
.auth-brand .lead { color: #b9d9c8; font-size: 1.02rem; max-width: 460px; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 14px; }
.auth-points li { display: flex; gap: 12px; align-items: center; color: #d7ebdf; font-size: .9rem; }
.auth-points i { width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.08); display: flex; align-items: center; justify-content: center; color: var(--accent); }
.auth-foot { margin-top: 36px; font-size: .74rem; color: #8fb7a2; letter-spacing: .04em; }
.auth-panel { background: #f6f8f7; display: flex; align-items: center; justify-content: center; padding: 40px 28px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h2 { font-size: 1.6rem; }
.demo-box { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 18px; }
.demo-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.demo-grid > div { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font-size: .72rem; }
.demo-grid strong { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); }
.demo-grid code { display: block; font-size: .72rem; color: var(--ink); }
.demo-grid span { color: var(--muted); }

/* ---------- Public / tracking ---------- */
.public-body { background: #eef3f0; min-height: 100vh; display: flex; flex-direction: column; }
.public-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: #0c3523; color: #fff; }
.public-brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 800; letter-spacing: -.02em; }
.public-tag { font-size: .76rem; color: #a9cbb8; display: inline-flex; gap: 6px; align-items: center; }
.public-main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 26px 20px 50px; }
.public-footer { display: flex; justify-content: space-between; padding: 16px 24px; color: #7d9187; font-size: .74rem; border-top: 1px solid #dbe4df; }
.error-page { text-align: center; padding: 70px 20px; }
.error-code { font-size: 4rem; font-weight: 900; color: var(--brand); letter-spacing: -.05em; }
.track-hero { background: #0d3d27; background: linear-gradient(125deg, #0d3d27, #176b46); border-radius: 18px; padding: 26px; color: #fff; }
.track-hero h1 { font-size: 1.5rem; color: #fff; }
.track-hero .meta { display: flex; flex-wrap: wrap; gap: 8px 22px; color: #c3e2d2; font-size: .8rem; }
.track-hero .meta strong { color: #fff; }
.track-steps { display: flex; gap: 6px; margin-top: 20px; }
.track-step { flex: 1; height: 6px; border-radius: 10px; background: rgba(255,255,255,.18); }
.track-step.done { background: var(--accent); }
.pod-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

/* ---------- Driver app ---------- */
.driver-body { background: #eef3f0; min-height: 100vh; padding-bottom: 78px; }
.offline-banner { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 1090; max-width: min(92vw, 620px); padding: 10px 14px; border-radius: 12px; box-shadow: 0 10px 30px rgba(6, 25, 16, .22); font-size: .875rem; font-weight: 600; text-align: center; background: #e8f5ee; color: #0c3523; border: 1px solid #b7ddc9; }
.offline-banner[data-tone="warning"] { background: #fff4d6; color: #6b4b00; border-color: #f0d48a; }
.offline-banner[data-tone="info"] { background: #e8f5ee; color: #0c3523; border-color: #b7ddc9; }
.driver-topbar { background: #0c3523; color: #fff; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1030; }
.driver-main { padding: 16px; max-width: 720px; margin: 0 auto; }
.driver-nav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 1030; }
.driver-nav a { flex: 1; text-align: center; padding: 9px 0 11px; color: #7c8d84; font-size: .66rem; display: flex; flex-direction: column; gap: 2px; }
.driver-nav a i { font-size: 1.2rem; }
.driver-nav a.active { color: var(--brand); font-weight: 700; }
.trip-card { border: 1px solid var(--line); border-radius: 16px; background: #fff; padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.trip-card h3 { font-size: 1rem; margin: 0 0 4px; }
.trip-route { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.trip-route .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.trip-route .line { flex: 1; height: 1px; background: #dbe4df; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(6,25,16,.5); z-index: 1035; }
    .content { padding: 18px 16px 40px; }
    .topbar { padding: 0 16px; height: 66px; }
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-panel { min-height: 100vh; }
}
@media (max-width: 575.98px) {
    .kpi .kpi-value { font-size: 1.4rem; }
    .section-head { align-items: flex-start; }
    .demo-grid { grid-template-columns: 1fr; }
    .track-hero { padding: 20px; }
}
