* {
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

body {
    margin: 0;
    background: linear-gradient(180deg, #f5f8ff 0%, #eef3fb 100%);
    color: #1f2937;
}

.container {
    max-width: 1180px;
    margin: 24px auto 36px;
    padding: 0 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #0f3f8a 0%, #1e63c6 100%);
    color: #fff;
    padding: 16px 18px;
    border-radius: 12px;
    box-shadow: 0 8px 18px rgba(16, 63, 138, 0.25);
}

.header h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0.2px;
}

.card {
    background: #fff;
    border-radius: 12px;
    padding: 18px;
    margin-top: 16px;
    border: 1px solid #dbe6f4;
    box-shadow: 0 8px 18px rgba(38, 78, 145, 0.08);
}

.app-shell {
    margin-top: 16px;
    display: grid;
    grid-template-columns: 230px 1fr;
    gap: 16px;
    align-items: start;
}

.sidebar {
    position: sticky;
    top: 16px;
    margin-top: 0;
    padding: 12px;
}

.main-content .card {
    margin-top: 0;
}

.main-content .card + .card {
    margin-top: 16px;
}

h2, h3 {
    margin-top: 4px;
    color: #143d7a;
}

form {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 4px;
    font-size: 14px;
}

input, select, textarea, button {
    padding: 10px 11px;
    font-size: 14px;
    border-radius: 8px;
    border: 1px solid #c9d7ec;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: #2d6fd2;
    box-shadow: 0 0 0 3px rgba(45, 111, 210, 0.15);
    outline: none;
}

button {
    cursor: pointer;
    border: 1px solid #2d6fd2;
    background: #2d6fd2;
    color: #fff;
    font-weight: 600;
}

button:hover {
    background: #235cb0;
    border-color: #235cb0;
}

.tabs {
    margin-top: 0;
    display: grid;
    gap: 8px;
}

.tabs button {
    text-align: left;
    background: #eef3fb;
    color: #1e3d73;
    border: 1px solid #d0ddf2;
}

.tabs button.active {
    background: #114a9f;
    color: #fff;
    border: 1px solid #114a9f;
    box-shadow: 0 4px 10px rgba(17, 74, 159, 0.25);
}

.nav-group {
    border: 1px solid #d0ddf2;
    border-radius: 10px;
    background: #f7faff;
    padding: 8px;
    display: grid;
    gap: 6px;
}

.nav-group-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #4f6282;
    padding: 2px 4px;
}

.tabs .nav-child {
    margin-left: 8px;
}

.driver-portal-link {
    display: inline-block;
    margin-top: 10px;
    color: #114a9f;
    text-decoration: none;
    font-weight: 700;
}

.driver-portal-link:hover {
    text-decoration: underline;
}

.kpis {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    margin-bottom: 16px;
}

.kpi {
    background: linear-gradient(135deg, #f7fbff 0%, #edf4ff 100%);
    border: 1px solid #dce8f7;
    padding: 12px;
    border-radius: 10px;
}

.kpi span {
    display: block;
    font-size: 13px;
    color: #55667f;
}

.kpi strong {
    font-size: 28px;
    color: #0d3770;
}

.inline-form {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-items: end;
}

.compact-filter {
    margin-bottom: 10px;
}

.quick-ranges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 12px;
}

.quick-range-btn {
    padding: 7px 10px;
    font-size: 12px;
}

.section-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.order-subtitle {
    margin: 2px 0 12px;
    color: #4f6282;
}

.order-form {
    display: grid;
    gap: 12px;
    max-width: 980px;
}

.order-section {
    border: 1px solid #dbe6f4;
    border-radius: 10px;
    background: #f8fbff;
    padding: 12px;
}

.order-section h4 {
    margin: 0 0 10px;
    color: #17427f;
}

.order-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
}

.order-grid.two-col {
    grid-template-columns: minmax(240px, 420px) minmax(220px, 320px);
    justify-content: start;
}

.order-grid.three-col {
    grid-template-columns: repeat(3, minmax(160px, 240px));
    justify-content: start;
}

.order-section textarea[name="notes"] {
    max-width: 680px;
}

.order-submit-btn {
    justify-self: end;
    min-width: 170px;
}

.statement-kpis {
    margin-top: 16px;
}

.dashboard-accordion {
    margin-bottom: 12px;
    border: 1px solid #d6e3f5;
    border-radius: 12px;
    background: linear-gradient(180deg, #f9fcff 0%, #f4f9ff 100%);
    overflow: hidden;
    box-shadow: 0 6px 14px rgba(27, 68, 130, 0.08);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.dashboard-accordion:hover {
    box-shadow: 0 10px 20px rgba(27, 68, 130, 0.12);
    transform: translateY(-1px);
}

.dashboard-accordion summary {
    list-style: none;
    cursor: pointer;
    padding: 12px 14px;
    font-weight: 700;
    color: #123f7d;
    background: linear-gradient(135deg, #eef5ff 0%, #e7f0ff 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.dashboard-accordion summary::-webkit-details-marker {
    display: none;
}

.dashboard-accordion summary::after {
    content: "+";
    font-size: 18px;
    line-height: 1;
    font-weight: 700;
    color: #245da9;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid #c6d9f6;
    background: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(35, 82, 153, 0.16);
    transition: transform 0.2s ease, background 0.2s ease;
}

.dashboard-accordion[open] summary::after {
    content: "-";
    transform: rotate(180deg);
    background: #edf4ff;
}

.dashboard-accordion table {
    margin-top: 0;
    border-top: 1px solid #dce8f8;
}

.dashboard-accordion[open] summary {
    border-bottom-color: #dce8f8;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
}

th, td {
    border: 1px solid #e5edf8;
    padding: 9px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f0f5fd;
    color: #17427f;
    font-weight: 700;
}

tbody tr:nth-child(even) {
    background: #f9fbff;
}

tbody tr:hover {
    background: #edf4ff;
}

.clickable-row {
    cursor: pointer;
}

.clickable-row td:first-child {
    color: #114a9f;
    font-weight: 700;
    text-decoration: underline;
}

#signatureCanvas {
    width: 100%;
    max-width: 640px;
    border: 2px dashed #8fb0dc;
    border-radius: 8px;
    background: #fff;
    touch-action: none;
}

.signature-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.dispatch-board {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 12px;
    margin: 10px 0 14px;
}

.dispatch-column h4 {
    margin: 0 0 8px;
    color: #143d7a;
}

.drop-zone {
    background: #f8fbff;
    border: 2px dashed #b8cdeb;
    border-radius: 10px;
    min-height: 160px;
    padding: 8px;
}

.drop-zone.drag-over {
    border-color: #2d6fd2;
    background: #eef5ff;
}

.job-card {
    background: #ffffff;
    border: 1px solid #d7e4f6;
    border-left: 4px solid #2d6fd2;
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 8px;
    cursor: grab;
}

.job-card:active {
    cursor: grabbing;
}

.job-card .job-ref {
    font-weight: 700;
    color: #114a9f;
}

.job-card .job-meta {
    font-size: 12px;
    color: #4b5f7e;
}

.drivers-board {
    display: grid;
    gap: 8px;
}

.driver-node {
    border: 1px solid #d5e3f6;
    border-radius: 10px;
    background: #f8fbff;
    overflow: hidden;
}

.driver-node summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    color: #17427f;
    background: #edf4ff;
}

.driver-node summary::-webkit-details-marker {
    display: none;
}

.driver-node .driver-count {
    font-size: 12px;
    color: #315589;
}

.driver-drop-zone {
    border-top: 1px solid #d5e3f6;
    border-left: 2px dashed #b8cdeb;
    border-radius: 10px;
    min-height: 80px;
    padding: 8px;
    margin: 8px;
    background: #fff;
}

.driver-drop-zone.drag-over {
    border-left-color: #2d6fd2;
    background: #eef5ff;
}

.diary-list {
    display: grid;
    gap: 12px;
    margin-top: 8px;
}

.diary-day {
    border: 1px solid #dbe6f4;
    border-radius: 10px;
    background: #f8fbff;
    overflow: hidden;
}

.diary-day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #edf4ff;
    color: #17427f;
    border-bottom: 1px solid #dbe6f4;
}

.diary-entries {
    display: grid;
    gap: 8px;
    padding: 10px;
}

.diary-entry {
    border: 1px solid #d7e4f6;
    border-radius: 8px;
    background: #fff;
    padding: 9px 10px;
}

.diary-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.diary-job-ref {
    font-weight: 700;
    color: #114a9f;
}

.diary-status {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 999px;
    border: 1px solid transparent;
}

.diary-status.is-assigned {
    background: #fff8e7;
    color: #895400;
    border-color: #f2d598;
}

.diary-status.is-unassigned {
    background: #f2f5fb;
    color: #315589;
    border-color: #cfdcf1;
}

.diary-status.is-completed {
    background: #eafaf0;
    color: #17603b;
    border-color: #bfe5cc;
}

.diary-meta {
    margin-top: 5px;
    color: #4b5f7e;
    font-size: 13px;
}

.diary-empty {
    margin: 8px 0;
    color: #4f6282;
}

.hidden {
    display: none;
}

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1100;
    display: grid;
    gap: 8px;
    width: min(360px, calc(100vw - 24px));
}

.toast {
    border-radius: 10px;
    padding: 11px 12px;
    box-shadow: 0 10px 20px rgba(20, 45, 87, 0.22);
    border: 1px solid #d7e4f6;
    background: #ffffff;
    color: #163a71;
    font-weight: 600;
}

.toast-success {
    border-color: #bfe5cc;
    background: #ecfbf2;
    color: #166238;
}

.toast-error {
    border-color: #f3c3c3;
    background: #fff0f0;
    color: #8a1f1f;
}

.secondary-btn {
    background: #eef3fb;
    color: #1e3d73;
    border: 1px solid #d0ddf2;
}

.secondary-btn:hover {
    background: #e4ecf9;
    border-color: #bfd1ef;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(21, 39, 67, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-card {
    width: min(920px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #dbe6f4;
    box-shadow: 0 16px 40px rgba(12, 37, 75, 0.25);
    padding: 16px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.modal-header h3 {
    margin: 0;
}

.customer-modal-form {
    display: grid;
    gap: 12px;
}

.modal-section {
    border: 1px solid #dbe6f4;
    border-radius: 10px;
    background: #f8fbff;
    padding: 12px;
}

.modal-section h4 {
    margin: 0 0 10px;
    color: #17427f;
}

.modal-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
    margin-bottom: 10px;
}

.modal-grid:last-child {
    margin-bottom: 0;
}

.modal-grid.two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.modal-grid.three-col {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.modal-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 4px;
}

@media print {
    .tabs,
    .sidebar,
    #logoutBtn,
    #loginView,
    #orderTab,
    #returnsTab,
    #ordersTab {
        display: none !important;
    }

    #statementTab {
        display: block !important;
        box-shadow: none;
        border: none;
    }
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .tabs {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .tabs button {
        text-align: center;
    }

    .dispatch-board {
        grid-template-columns: 1fr;
    }

    .modal-grid.two-col,
    .modal-grid.three-col,
    .order-grid.two-col,
    .order-grid.three-col {
        grid-template-columns: 1fr;
    }
}
