:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1d2330;
    --muted: #667085;
    --border: #dfe3ea;
    --accent: #1f5fbf;
    --accent-text: #ffffff;
    --sidebar: #172033;
    --sidebar-text: #c9d2e3;
    --sidebar-active: #ffffff;
    --danger: #c0262d;
    --danger-bg: #fdecec;
    --warn: #9a5b00;
    --warn-bg: #fff4dc;
    --ok: #1e7b3a;
    --hot-bg: #fff1f0;
    --done: #8a93a3;
    --radius: 6px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f141d;
        --surface: #171e2a;
        --surface-2: #1d2533;
        --text: #e4e8ef;
        --muted: #8e98aa;
        --border: #2a3344;
        --accent: #5b9bff;
        --accent-text: #0b1220;
        --sidebar: #0b1019;
        --sidebar-text: #9aa6bb;
        --danger: #ff7b7b;
        --danger-bg: #3a1a1c;
        --warn: #f0b44c;
        --warn-bg: #3a2c12;
        --ok: #6fd08c;
        --hot-bg: #2e1a1a;
        --done: #5f687a;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
h1:focus { outline: none; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: .92em; }
.nowrap { white-space: nowrap; }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1rem .75rem;
    gap: 1.25rem;
}

.brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: 0 .5rem; }
.brand span, .login-card h1 span { font-weight: 400; opacity: .75; margin-left: .15rem; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { text-transform: uppercase; font-size: .72rem; letter-spacing: .06em; padding: 0 .5rem .25rem; opacity: .7; }
.nav-group a { color: var(--sidebar-text); padding: .4rem .5rem; border-radius: var(--radius); }
.nav-group a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav-group a.active { background: rgba(255,255,255,.12); color: var(--sidebar-active); }

.nav-user { margin-top: auto; padding: 0 .5rem; font-size: .88rem; }
.nav-user-name { color: #fff; margin-bottom: .25rem; }
.link-button { background: none; border: 0; padding: 0; color: var(--sidebar-text); cursor: pointer; font: inherit; text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 3rem; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .5rem 1rem; gap: .5rem 1rem; }
    .nav-group { flex-direction: row; gap: .25rem; }
    .nav-label { display: none; }
    .nav-user { margin: 0 0 0 auto; display: flex; gap: .75rem; align-items: center; }
    .nav-user-name { margin: 0; }
    .content { padding: 1rem; }
}

/* ---- page head / toolbar ---- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head .toolbar { margin-bottom: 0; }

input, select, button {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .38rem .6rem;
}
input.wide { width: min(480px, 100%); }
button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .6; cursor: default; }
button.primary, a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
a.button { display: inline-block; padding: .38rem .6rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); line-height: normal; }
a.button:not(.primary):hover { background: var(--surface-2); }
a.button:hover { text-decoration: none; }

.check { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); }
.check input { padding: 0; }
/* Edit order: Chassis to use tick boxes (the company's list) */
.chassis-to-use { border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .7rem .6rem; margin: .8rem 0 0; }
.chassis-to-use legend { padding: 0 .3rem; color: var(--muted); font-size: .9em; }
.chassis-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .35rem .8rem; }
.chassis-grid .check { color: var(--text); }

.segmented { display: inline-flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.segmented button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.alert { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: 1rem; }

/* ---- grids ---- */
.table-wrap {
    overflow: auto;
    max-height: calc(100vh - 150px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table.grid { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.grid th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    text-align: left;
    font-weight: 600;
    padding: .45rem .6rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    z-index: 1;
}
table.grid td { padding: .38rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tr.clickable { cursor: pointer; }
table.grid td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.grid td.notes { max-width: 280px; color: var(--muted); }
table.grid td.empty { text-align: center; color: var(--muted); padding: 2rem; }

tr.row-hot { background: var(--hot-bg); }
tr.row-done td { color: var(--done); }
tr.row-oos td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

.exp-past { color: var(--danger); font-weight: 600; }
.exp-soon { color: var(--warn); font-weight: 600; }

.badge {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .03em;
    padding: 1px 5px;
    margin-left: 4px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    vertical-align: middle;
}
.badge.hot { background: var(--danger); color: #fff; border-color: var(--danger); }
.status { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* ---- order detail ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
dl.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem 1.25rem; margin: 0; }
.field dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field dd { margin: .1rem 0 0; }
.notes-block { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.notes-block p { margin: .25rem 0 0; white-space: pre-wrap; }

/* ---- login / error ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
    width: min(360px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.login-card h1 { margin-bottom: .25rem; }
.login-card label { font-size: .85rem; color: var(--muted); margin-top: .35rem; }
.login-card button { margin-top: .75rem; padding: .55rem; }
.login-card p { margin: 0 0 .25rem; }

/* ---- Blazor error bar ---- */
#blazor-error-ui {
    background: var(--warn-bg);
    color: var(--text);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* ---- modal ---- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(10, 15, 25, .45);
    display: grid; place-items: start center;
    padding: 8vh 1rem 1rem; overflow: auto;
}
.modal {
    width: min(520px, 100%);
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .75rem; }
.modal-foot { padding: .75rem 1.1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.icon-button { border: 0; background: none; font-size: 1rem; padding: .2rem .4rem; color: var(--muted); }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem 1rem; }
.form-row { display: flex; flex-direction: column; gap: .25rem; }
.form-row label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .38rem .6rem; min-height: 4rem; }
.hint { font-size: .82rem; color: var(--muted); }
.warn-box { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: .5rem .7rem; font-size: .88rem; }

/* ---- toast ---- */
.toast {
    position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
    background: var(--sidebar); color: #fff; border-radius: var(--radius);
    padding: .65rem 1rem; box-shadow: 0 6px 24px rgba(0,0,0,.3); max-width: min(420px, calc(100vw - 2rem));
}
.toast.error { background: var(--danger); }

/* ---- pick list (driver picker) ---- */
.pick-list { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.pick-item { display: flex; justify-content: space-between; gap: .75rem; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: .5rem .7rem; background: var(--surface); }
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover:not(:disabled) { background: var(--surface-2); }
.pick-item.selected { background: var(--accent); color: var(--accent-text); }
.pick-item .meta { color: var(--muted); font-size: .85rem; }
.pick-item.selected .meta { color: inherit; opacity: .85; }
.small-button { padding: .15rem .55rem; font-size: .82rem; }
.pend-button { padding: .1rem .45rem; font-size: .8rem; font-weight: 700; background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); border-radius: 4px; cursor: pointer; white-space: nowrap; }
.right { text-align: right; }
th.right { text-align: right; }
.total-row td { font-weight: 600; background: var(--surface-2); border-bottom: 0; }
.sub-head { font-size: .95rem; margin: .5rem 0 .25rem; }
.num-input { width: 6.5rem; padding: .25rem .4rem; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-bg); }

/* ---- quotes ---- */
.quote-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.quote-card { max-width: 560px; margin-bottom: 1rem; }
.quote-card h2 { margin: 0 0 .25rem; }
.quote-lines { margin: .75rem 0 0; }
.quote-lines div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; border-bottom: 1px solid var(--border); }
.quote-lines dt { color: var(--text); }
.quote-lines dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.quote-total { font-weight: 700; font-size: 1.1rem; border-bottom: 0 !important; padding-top: .5rem !important; }
details summary { cursor: pointer; margin-top: .75rem; color: var(--muted); }

/* Driver / truck detail pages and imaging lists */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.card-title { margin: 0 0 .75rem; font-size: 1rem; }
.imaging .page-head { margin-bottom: .5rem; }
table.grid td.file-name { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.grid tr.clickable:hover td { background: var(--surface-2); }
.leg-pick { display: flex; flex-direction: column; gap: .35rem; }
.leg-pick label { display: flex; gap: .5rem; align-items: baseline; }

/* Rate quote (trip) */
.linkish { background: none; border: 0; padding: .15rem 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.linkish:hover:not(:disabled) { text-decoration: underline; background: none; }
.linkish:disabled { color: var(--muted); cursor: default; }
.rq-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.rq-left { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.rq-trip { display: flex; flex-direction: column; gap: .3rem; }
.rq-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: .45rem; }
.rq-box { width: 100%; }
.rq-stop { display: flex; gap: .4rem; align-items: center; }
.rq-stop .rq-box { flex: 1; }
.rq-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-top: .3rem; }
.rq-row .rq-label { margin: 0 .3rem 0 0; }
.rq-money { width: 6rem; }
.rq-summary { font-weight: 600; }
.rq-warn { color: var(--warn); }
.rq-lines { margin-top: .5rem; border-top: 1px solid var(--border); }
.rq-line { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.rq-line .num { white-space: nowrap; }
.rq-total { font-weight: 700; font-size: 1.1rem; border-bottom: 0; }
.rq-sub { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 1.1rem 0 .3rem; }
.rq-acc div { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; padding: .15rem 0; }
table.grid tr.row-picked td { background: var(--surface-2); font-weight: 600; }
@media (max-width: 860px) { .rq-layout { grid-template-columns: 1fr; } }

/* Target + Tracked empties */
.te-ok { color: var(--ok); font-weight: 600; }
.tg-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tg-cards .card { margin: 0; }
.tg-big { font-size: 1.05rem; font-weight: 600; }
.tg-bad { color: var(--danger); font-weight: 600; }

/* New order */
.lp { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.lp-picked { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .55rem; background: var(--surface); }
.lp-name { font-weight: 600; }
.lp-list { max-height: 260px; }
.lp-prepull { margin-top: .75rem; }
.nl-legs { margin: 0 0 .5rem; padding-left: 1.3rem; display: flex; flex-direction: column; gap: .3rem; }
.nl-actions { margin-top: 1rem; }
.nl-created { margin-left: .4rem; }

/* Customers */
.cf-wide { grid-column: span 2; }
.cf-short { width: 7rem; }
.cf-checks { display: flex; flex-wrap: wrap; gap: 1rem; margin: .5rem 0; }
@media (max-width: 640px) { .cf-wide { grid-column: auto; } }

/* Billing */
table.grid th.num { text-align: right; }
table.grid td.num { text-align: right; }
table.grid .check-col { width: 2rem; text-align: center; }
table.grid tr.group-row td { background: var(--surface-2); border-top: 2px solid var(--border); }
table.grid tr.selected td { background: var(--warn-bg); }
.bill-flags { display: flex; flex-wrap: wrap; gap: .25rem; }
.bill-filter { margin-bottom: .75rem; flex-wrap: wrap; }
.bill-date { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; color: var(--muted); }
.bill-bar { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
            margin-top: .75rem; padding: .65rem .9rem; background: var(--surface); border: 1px solid var(--border);
            border-radius: var(--radius); box-shadow: 0 -4px 14px rgba(0, 0, 0, .08); }
.bill-bar .link-button { color: var(--accent); }
.bill-done { margin-bottom: 1rem; }
.bill-warnings { margin: 0 0 .5rem; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .4rem; }
.audit-why { min-width: 16rem; }
.audit-why .badge { margin: 0 .25rem .2rem 0; }
.audit-issue { font-size: .85rem; line-height: 1.3; }
.inv-emails { list-style: none; margin: .25rem 0 .5rem; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.inv-emails li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-size: .9rem; }
.inv-email-add { display: flex; flex-wrap: wrap; gap: .4rem; }
.inv-email-add input { flex: 1 1 10rem; min-width: 0; }
.dup-top { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: .5rem; }
.dup-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .25rem .75rem; }

/* Driver uploads review: list + preview side by side (stacked on narrow screens). */
.uploads-split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.uploads-preview { position: sticky; top: .5rem; }
.uploads-preview iframe { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.grid tr.selected td { background: var(--accent-bg, rgba(37, 99, 235, .08)); }
@media (max-width: 900px) { .uploads-split { grid-template-columns: 1fr; } .uploads-preview iframe { height: 60vh; } }

/* Driver board: drivers down the side, Monday - Saturday across (the offices' dispatch sheet). */
.board-wrap { max-height: 78vh; }
.driver-board th { position: sticky; top: 0; z-index: 1; }
.driver-board td.board-cell { min-width: 9.5rem; max-width: 14rem; font-size: .82rem; line-height: 1.25; cursor: pointer; vertical-align: top; }
.driver-board td.board-cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.driver-board .board-note { font-weight: 700; }
.driver-board .board-today { box-shadow: inset 0 0 0 9999px rgba(255, 214, 102, .18); }
.driver-board .board-yellow { background: #fff29d; color: #222; }
.driver-board .board-red { background: #ffc7c7; color: #222; }
.driver-board .board-green { background: #c6efce; color: #222; }
.driver-board .board-gray { background: #dcdcdc; color: #222; }
.driver-board .board-cancelled { color: var(--muted); text-decoration: line-through; }
.driver-board .board-hot { font-weight: 700; }
.driver-board tr.board-group td { background: var(--border); font-weight: 700; letter-spacing: .04em; }
