:root {
    --navy: #123c69;
    --blue: #1769aa;
    --blue-dark: #125a91;
    --ink: #24323d;
    --muted: #5d6d7a;
    --line: #e6edf3;
    --bg: #eef3f8;
    --card: #fff;
    --green: #2e7d32;
    --amber: #c48700;
    --red: #c62828;
    --radius: 14px;
    --shadow: 0 2px 10px #123c6912;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0;
    font-family: "Segoe UI", system-ui, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.45;
}
a { color: var(--blue); }
h1, h2, h3, h4 { color: var(--navy); letter-spacing: -.02em; }
h1 { margin: 0; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 18px; }
h3 { margin: 0 0 12px; font-size: 16px; }
h4 { margin: 0 0 10px; font-size: 14px; }
p { margin: 0 0 10px; }
small { color: var(--muted); }

.topnav {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    padding: 10px 5%;
    background: linear-gradient(90deg, var(--navy), #16497d);
    color: #fff;
    box-shadow: 0 4px 16px #0b24403a;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    letter-spacing: .02em;
    margin-right: 8px;
}
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: #fff;
    color: var(--navy);
    font-size: 11px;
    font-weight: 800;
}
.topnav a { color: #fff; text-decoration: none; font-weight: 600; font-size: 14px; }
.topnav > a:hover, .nav-menu > a:hover { opacity: .86; }
.nav-links { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.nav-user {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.nav-user-name { font-weight: 700; }
.nav-user-role {
    background: #ffffff22;
    border: 1px solid #ffffff33;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
}
.nav-logout {
    display: inline-flex;
    align-items: center;
    background: #0d2b4d;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
}
.nav-logout:hover { background: #081c33; }
.nav-menu { position: relative; }
.nav-menu > a { display: block; padding: 6px 0; }
.nav-submenu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 230px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 28px #123c6930;
    padding: 6px 0;
    z-index: 50;
}
.nav-menu:hover .nav-submenu,
.nav-menu:focus-within .nav-submenu { display: block; }
.nav-submenu a {
    display: block;
    color: var(--ink);
    padding: 9px 14px;
    white-space: nowrap;
    font-weight: 600;
}
.nav-submenu a:hover { background: #eef4f8; color: var(--navy); }

main { max-width: 1120px; margin: 24px auto 40px; padding: 0 18px; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 18px;
}
.page-head .page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.card {
    background: var(--card);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card.narrow { max-width: 640px; }
.card.pad-0 { padding: 0; overflow: hidden; }
.card.pad-0 h2, .card.pad-0 h3 { padding: 16px 20px 0; }
.hint { color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat { font-size: 28px; color: var(--blue); font-weight: 800; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: transparent; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: .05em;
    text-transform: uppercase;
    font-weight: 700;
    background: #f7fafc;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8fbfe; }
.table-actions { white-space: nowrap; }
.dash-ref, .table-link { font-weight: 700; color: var(--navy); text-decoration: none; }
.dash-ref:hover, .table-link:hover { text-decoration: underline; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 12px; }
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    margin: 6px 0 0;
    box-sizing: border-box;
    border: 1px solid #c9d6e0;
    border-radius: 8px;
    font: inherit;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid #1769aa55;
    border-color: var(--blue);
}
textarea { min-height: 88px; resize: vertical; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.form-actions .btn, .form-actions button { margin: 0; }

button, .btn {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--blue);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    min-height: 40px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .02em;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
    box-shadow: 0 1px 2px #123c6926;
    transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
button:hover, .btn:hover { background: var(--blue-dark); }
button:active, .btn:active { transform: translateY(1px); box-shadow: none; }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.btn.alt { background: #5d6d7a; }
.btn.alt:hover { background: #4a5863; }
.btn.warn { background: var(--red); }
.btn.warn:hover { background: #a51f1f; }
button:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline .btn, .inline button { flex: 0 0 auto; }
.inline form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
.inline form input { flex: 1; min-width: 180px; margin: 0; }
.inline form button { margin: 0; }
.search-bar { margin-bottom: 16px; }
.search-bar input { margin: 0; }
table .btn, table button { min-height: 34px; padding: 7px 12px; font-size: 13px; margin: 2px 2px 2px 0; }
table form { display: inline; }
button + .btn, .btn + .btn, .btn + button, button + button { margin-left: 6px; }
.card > .btn { margin: 0 8px 8px 0; }
.form-actions button + .btn, .form-actions .btn + .btn { margin-left: 0; }

.alert {
    padding: 12px 14px;
    background: #e8f5e9;
    color: #256029;
    border-radius: 10px;
    margin-bottom: 16px;
    border: 1px solid #c8e6c9;
}
.alert.error, .error { background: #ffebee; color: #b71c1c; border-color: #ffcdd2; }

.status-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em;
    background: #e8f2f9;
    color: var(--blue);
    white-space: nowrap;
}
.status-delivered, .status-closed, .status-active, .status-y { background: #e8f5e9; color: var(--green); }
.status-on_delivery, .status-out_for_delivery { background: #e3f2fd; color: #1565c0; }
.status-assigned { background: #fff8e1; color: #f57f17; }
.status-failed, .status-inactive, .status-n { background: #ffebee; color: var(--red); }
.status-open, .status-created, .status-found { background: #e8f2f9; color: var(--blue); }

.kv {
    display: grid;
    grid-template-columns: minmax(140px, 200px) 1fr;
    gap: 8px 16px;
    margin: 0;
}
.kv dt { margin: 0; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kv dd { margin: 0; }
@media (max-width: 640px) {
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dt { margin-top: 8px; }
}

.pod-photo { display: block; margin: 14px 0; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.pod-photo img {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    background: #f3f6f8;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 6px;
}

.dash-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 72%, #2a86c4 100%);
    color: #fff;
    padding: 22px 24px;
    border-radius: 16px;
    margin-bottom: 20px;
    box-shadow: 0 10px 28px #123c6930;
}
.dash-hero h1 { margin: 0 0 6px; font-size: 26px; color: #fff; }
.dash-hero p { margin: 0; opacity: .88; font-size: 14px; }
.dash-hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.dash-chip {
    display: inline-flex;
    align-items: center;
    background: #ffffff1f;
    border: 1px solid #ffffff33;
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .03em;
}
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; margin-bottom: 20px; }
.dash-stat {
    position: relative;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px 18px 15px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: transform .12s ease, box-shadow .12s ease;
}
.dash-stat:hover { transform: translateY(-2px); box-shadow: 0 8px 18px #123c6918; }
.dash-stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.dash-stat small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.dash-stat .stat { margin-top: 8px; font-size: 32px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; color: var(--navy); }
.dash-stat-total::before { background: var(--navy); }
.dash-stat-pending::before { background: #e6a817; }
.dash-stat-pending .stat { color: var(--amber); }
.dash-stat-delivery::before { background: var(--blue); }
.dash-stat-delivered::before { background: var(--green); }
.dash-stat-delivered .stat { color: var(--green); }
.dash-stat-bags::before { background: #6a1b9a; }
.dash-stat-bags .stat { color: #6a1b9a; }
.dash-panel { padding: 0; overflow: hidden; }
.dash-panel h3 { margin: 0; padding: 16px 20px 12px; font-size: 16px; }
.dash-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; padding: 0 16px 16px; }
.dash-action {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #f6f9fc;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--navy);
    transition: background .12s ease, border-color .12s ease;
}
.dash-action:hover { background: #eef5fb; border-color: #b9d3e6; }
.dash-action strong { font-size: 15px; }
.dash-action span { font-size: 13px; color: var(--muted); font-weight: 400; }
.dash-empty { margin: 0; padding: 8px 20px 20px; color: var(--muted); }
.dash-table th { background: transparent; }
.dash-table td, .dash-table th { padding: 12px 20px; }
.driver-empty { text-align: center; padding: 28px 18px; }
.driver-empty p { margin: 0; color: var(--muted); }

body.driver-app .topnav { padding: 10px 12px; gap: 10px; }
body.driver-app main { max-width: 480px; margin: 12px auto; padding: 0 12px 28px; }
body.driver-app h1 { margin: 8px 0 16px; font-size: 24px; }
body.driver-app .btn, body.driver-app button { width: 100%; min-height: 48px; padding: 14px 16px; font-size: 16px; border-radius: 10px; }
body.driver-app .card > .btn { margin: 12px 0 0; }
body.driver-app button + .btn, body.driver-app .btn + .btn, body.driver-app .btn + button, body.driver-app button + button { margin-left: 0; }
body.driver-app .nav-logout { width: auto; min-height: 0; padding: 6px 12px; font-size: 13px; }
body.driver-app .nav-user-name, body.driver-app .nav-user-role { display: none; }
body.driver-app .driver-tasks { display: grid; gap: 14px; }
body.driver-app .driver-task { margin-bottom: 0; border-radius: 14px; }
body.driver-app .driver-task h2 { margin: 8px 0 4px; font-size: 20px; color: var(--navy); word-break: break-all; }
body.driver-app .driver-name { font-size: 18px; font-weight: 700; margin: 0 0 6px; }
body.driver-app .driver-meta { margin: 0 0 8px; color: var(--muted); }
body.driver-app .driver-address { margin: 0; color: var(--ink); line-height: 1.4; }
body.driver-app .driver-task-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
body.driver-app .driver-distance { font-weight: 700; color: #1769aa; white-space: nowrap; }
body.driver-app .driver-badge {
    display: inline-block;
    background: #e8f2f9;
    color: var(--blue);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .03em;
}
body.driver-app .driver-phones { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
body.driver-app .btn-call, body.driver-app .btn-wa {
    flex: 1 1 calc(50% - 8px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 42px;
    padding: 8px 10px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none;
    box-sizing: border-box;
    box-shadow: none;
}
body.driver-app .btn-call { background: #eef5fa; color: var(--blue); border: 1px solid #c5d9e8; }
body.driver-app .btn-call:hover { background: #dceaf4; }
body.driver-app .btn-wa { background: #e7f8ee; color: #128c7e; border: 1px solid #a6dfc0; }
body.driver-app .btn-wa:hover { background: #d3f1de; }
body.driver-app .dash-hero { margin-bottom: 16px; padding: 18px; }
body.driver-app .dash-hero h1 { font-size: 22px; margin: 0 0 6px; }
.driver-task .driver-badge.status-assigned, .driver-badge.status-assigned { background: #fff8e1; color: #f57f17; }
.driver-task .driver-badge.status-on_delivery, .driver-task .driver-badge.status-out_for_delivery,
.driver-badge.status-on_delivery, .driver-badge.status-out_for_delivery { background: #e3f2fd; color: #1565c0; }
.driver-task .driver-badge.status-failed, .driver-badge.status-failed { background: #ffebee; color: var(--red); }
.driver-task .driver-badge.status-delivered, .driver-badge.status-delivered { background: #e8f5e9; color: var(--green); }

.driver-task-screen h1 { margin: 0 0 6px; font-size: 22px; }
.driver-task-screen h2 { margin: 0 0 12px; font-size: 18px; }
.driver-status { margin: 0 0 16px; color: var(--blue); font-weight: 700; }
.driver-back { margin: 0 0 10px; }
.driver-back a { color: var(--blue); font-weight: 700; text-decoration: none; }
.driver-task-screen .driver-name { font-size: 20px; font-weight: 700; margin: 0 0 8px; }
.driver-task-screen .driver-address { white-space: pre-wrap; margin: 12px 0; }
.gps-status { background: #eef4f8; padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; color: var(--muted); font-size: 13px; }
.driver-history { padding-left: 18px; margin: 0; }
.driver-history li { margin: 0 0 10px; }
#pod-preview {
    display: block;
    width: 100%;
    max-height: 280px;
    object-fit: contain;
    background: #f3f6f8;
    margin: 8px 0 14px;
    border-radius: 10px;
}
body.driver-app .driver-task-screen .btn,
body.driver-app .driver-task-screen button { margin-top: 8px; width: 100%; }
body.driver-app .driver-task-screen .btn-call,
body.driver-app .driver-task-screen .btn-wa { width: auto; margin-top: 0; }

@media (max-width: 640px) {
    .dash-hero { padding: 18px; }
    .dash-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-stat-bags { grid-column: 1 / -1; }
    .dash-table td, .dash-table th { padding: 10px 12px; }
    h1 { font-size: 22px; }
    .topnav { padding: 10px 12px; }
}
