:root {
    --bg: #0f172a;
    --sidebar-bg: #111827;
    --surface: #ffffff;
    --content-bg: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.12);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--content-bg);
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

h1 {
    font-size: 1.6rem;
    margin: 0 0 1rem;
}

h2 {
    font-size: 1.15rem;
    margin: 1.75rem 0 0.75rem;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.muted {
    color: var(--muted);
}

/* ---------- Layout ---------- */

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

.sidebar {
    background: var(--sidebar-bg);
    color: #e5e7eb;
    width: 240px;
    flex-shrink: 0;
    padding: 1.25rem 0.75rem;
}

main {
    flex: 1;
    min-width: 0;
}

.content {
    padding: 1.5rem;
    max-width: 1200px;
}

/* ---------- Nav ---------- */

.nav-brand {
    display: flex;
    flex-direction: column;
    padding: 0 0.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.75rem;
}

.nav-brand .logo {
    font-size: 1.5rem;
}

.nav-brand .title {
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
}

.nav-brand .subtitle {
    font-size: 0.8rem;
    color: #94a3b8;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.75rem;
    border-radius: 0.5rem;
    color: #cbd5e1;
    font-weight: 500;
    white-space: nowrap;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent);
    color: #fff;
}

.nav-link .icon {
    font-size: 1.05rem;
}

/* ---------- Cards (dashboard) ---------- */

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    color: var(--text);
}

.card:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.card-label {
    color: var(--muted);
    font-size: 0.9rem;
}

.status-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.status-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
}

.status-count {
    font-weight: 700;
}

/* ---------- Tables ---------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow-x: auto;
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

table.data th,
table.data td {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.data th {
    background: #f8fafc;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    position: sticky;
    top: 0;
}

table.data tbody tr:last-child td {
    border-bottom: none;
}

table.data tbody tr:hover {
    background: #f8fafc;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-grey { background: #e2e8f0; color: #475569; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }

.alert {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
}

/* ---------- Buttons ---------- */

.btn-primary,
.btn-secondary,
.btn-sm,
.btn-move {
    font-family: inherit;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    padding: 0.55rem 1rem;
    font-size: 0.95rem;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    padding: 0.55rem 1rem;
    font-size: 0.95rem;
}

.btn-secondary:hover {
    border-color: var(--accent);
}

.btn-sm {
    background: var(--surface);
    color: var(--accent);
    border-color: var(--border);
    padding: 0.3rem 0.7rem;
    font-size: 0.82rem;
    white-space: nowrap;
}

.btn-sm:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-sm:disabled,
.btn-move:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ---------- Form controls ---------- */

.field-label {
    display: block;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    font-weight: 700;
    margin: 1rem 0 0.35rem;
}

.select,
.input,
.textarea {
    width: 100%;
    max-width: 32rem;
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}

.textarea {
    resize: vertical;
    min-height: 3.5rem;
}

.select:focus,
.input:focus,
.textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Tighter, full-bleed variants for inputs sitting inside repeating rows/grids. */
.field-label.tight {
    margin-top: 0.5rem;
}

.input.compact,
.select.compact {
    max-width: none;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
}

/* A header row with the page heading on the left and a primary action on the right. */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-head h1 {
    margin-bottom: 0;
}

.btn-danger {
    font-family: inherit;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    border: 1px solid #fecaca;
    background: #fee2e2;
    color: #b91c1c;
    padding: 0.3rem 0.7rem;
    font-size: 0.82rem;
    white-space: nowrap;
}

.btn-danger:hover {
    border-color: #f87171;
}

.btn-danger:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.row-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

/* A wider modal for the multi-section client editor. */
.modal.modal-wide {
    max-width: 44rem;
}

.modal-scroll {
    max-height: 70vh;
    overflow-y: auto;
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
}

/* A repeating sub-record (a location row, a phone row) inside a form. */
.subrow {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem 0.75rem;
    align-items: start;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.75rem;
    margin-bottom: 0.6rem;
}

.subrow .subrow-fields {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}

.subrow-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.4rem 0.6rem;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1.5rem 0 0.5rem;
}

.section-head h3 {
    margin: 0;
    font-size: 0.95rem;
}

.inline-note {
    font-size: 0.82rem;
    color: var(--muted);
}

/* ---------- Result banner ---------- */

.banner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.7rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border: 1px solid;
}

.banner-ok {
    background: #dcfce7;
    border-color: #bbf7d0;
    color: #15803d;
}

.banner-err {
    background: #fee2e2;
    border-color: #fecaca;
    color: #b91c1c;
}

.banner-warn {
    font-size: 0.88rem;
    font-weight: 600;
}

.banner-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    font-size: 1rem;
    opacity: 0.7;
}

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}

.modal {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    width: 100%;
    max-width: 30rem;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.25);
}

.modal h2 {
    margin: 0 0 0.25rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.5rem;
}

/* ---------- Route reorder list ---------- */

.route-list {
    list-style: none;
    margin: 1rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 48rem;
}

.route-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 0.6rem;
    padding: 0.6rem 0.85rem;
}

.route-item.is-pickup { border-left-color: #1d4ed8; }
.route-item.is-dropoff { border-left-color: #b45309; }

.route-seq {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 999px;
    background: var(--content-bg);
    color: var(--muted);
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.route-job {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
}

.route-addr {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-move {
    display: flex;
    gap: 0.3rem;
    margin-left: auto;
    flex-shrink: 0;
}

.btn-move {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
    line-height: 1;
}

.btn-move:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.route-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1rem;
}

/* ---------- Blazor error UI ---------- */

#blazor-error-ui {
    background: #fef3c7;
    border-top: 1px solid #fcd34d;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.1);
    display: none;
    left: 0;
    padding: 0.75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 0.75rem;
}

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
    .page {
        flex-direction: column;
        min-height: 100dvh;
    }

    .sidebar {
        width: 100%;
        padding: 0.75rem;
        position: sticky;
        top: 0;
        z-index: 20;
    }

    .nav-brand {
        flex-direction: row;
        align-items: baseline;
        gap: 0.5rem;
        padding-bottom: 0.6rem;
        margin-bottom: 0.6rem;
    }

    .nav-brand .subtitle {
        display: none;
    }

    /* Horizontal, swipeable nav strip — no JS hamburger needed. */
    .nav-links {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-links::-webkit-scrollbar {
        display: none;
    }

    .nav-link {
        padding: 0.55rem 0.85rem;
    }

    .content {
        padding: 1rem;
    }

    /* Reflow each table row into a stacked card with inline labels. */
    table.data thead {
        display: none;
    }

    table.data,
    table.data tbody,
    table.data tr,
    table.data td {
        display: block;
        width: 100%;
    }

    table.data tr {
        border-bottom: 8px solid var(--content-bg);
        padding: 0.35rem 0;
    }

    table.data td {
        border: none;
        padding: 0.3rem 1rem;
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        text-align: right;
    }

    table.data td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        text-align: left;
        text-transform: uppercase;
        font-size: 0.72rem;
        letter-spacing: 0.03em;
        padding-top: 0.1rem;
    }

    table.data tbody tr:hover {
        background: transparent;
    }
}
