:root {
    --ink: #16212f;
    --muted: #627083;
    --line: #d9e0e8;
    --paper: #ffffff;
    --band: #f3f6f9;
    --accent: #0f766e;
    --accent-strong: #0b5d57;
    --warn: #b45309;
    --danger: #b42318;
    --ok: #16803c;
    --focus: #2563eb;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--band);
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 28px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
}

.brand-block {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 18px;
    min-width: 0;
    flex: 1;
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}

.main-nav {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.main-nav a:hover {
    color: var(--accent-strong);
    background: #e7f4f2;
}

.main-nav a.is-active {
    color: var(--accent-strong);
    border-color: #b7d9d5;
    background: #e7f4f2;
}

.text-link {
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.text-link:hover {
    color: var(--accent-strong);
    text-decoration: underline;
}

.panel-note {
    margin: 12px 16px 16px;
    color: var(--muted);
    font-size: 13px;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 16px 16px;
}

.pager span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.topbar h1,
.login-panel h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    white-space: nowrap;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f7f9fb;
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
}

.top-actions a,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

button.secondary,
.top-actions a {
    background: var(--paper);
    color: var(--accent);
}

button:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

button.secondary:hover,
.top-actions a:hover {
    background: #e7f4f2;
    color: var(--accent-strong);
}

.shell {
    width: min(1500px, 100%);
    margin: 0 auto;
    padding: 20px 28px 40px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

body.portal-vendor .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.portal-client .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.summary-grid article,
.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.summary-grid article {
    min-height: 82px;
    padding: 14px 16px;
}

.summary-grid span,
.panel-head span,
label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.summary-grid strong {
    display: block;
    margin-top: 10px;
    font-size: 24px;
}

.summary-grid strong.is-alert {
    color: var(--warn);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
    margin-bottom: 16px;
    padding: 14px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.toolbar > label {
    flex: 1 1 140px;
    min-width: 140px;
    max-width: 220px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
}

.toolbar.compact {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 10px;
    margin-bottom: 12px;
    padding: 0;
    border: 0;
    background: transparent;
}

.toolbar.compact > label {
    flex: 1 1 140px;
    min-width: 140px;
    max-width: 220px;
}

label {
    display: grid;
    gap: 6px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fbfcfd;
    border: 1px solid #cbd5df;
    border-radius: 6px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--focus);
    outline: 2px solid rgba(37, 99, 235, .16);
}

.work-grid {
    display: grid;
    grid-template-columns: minmax(320px, .85fr) minmax(420px, 1.15fr);
    gap: 16px;
    margin-bottom: 16px;
}

#tripDashboard {
    margin-bottom: 16px;
}

#invoiceSection.list-only {
    grid-template-columns: 1fr;
}

.panel {
    min-width: 0;
    padding: 16px;
}

.shell > .panel {
    margin-bottom: 16px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-head h2 {
    margin: 0;
    font-size: 17px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.wide {
    grid-column: 1 / -1;
}

.table-wrap {
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.table-wrap.tight {
    max-height: 430px;
}

table {
    width: 100%;
    min-width: 1100px;
    border-collapse: collapse;
    table-layout: fixed;
}

.trip-table {
    min-width: 1180px;
}

.trip-table .col-date { width: 6.5rem; }
.trip-table .col-slot { width: 6.5rem; }
.trip-table .col-group { width: 5rem; }
.trip-table .col-driver { width: 8rem; }
.trip-table .col-truck { width: 6.5rem; }
.trip-table .col-container { width: 9rem; }
.trip-table .col-size { width: 3.5rem; }
.trip-table .col-line { width: 4.25rem; }
.trip-table .col-depot { width: 4.5rem; }
.trip-table .col-fasah { width: 6rem; }
.trip-table .col-datetime { width: 6.5rem; }
.trip-table .col-actions { width: 8.5rem; }

.trip-table .cell-actions {
    overflow: visible;
}

.row-actions {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.row-actions button {
    min-height: 30px;
    padding: 4px 8px;
    font-size: 12px;
}

.doc-links {
    display: inline-flex;
    gap: 6px;
}

.doc-link {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.doc-link:hover {
    text-decoration: underline;
}

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

label .text-link {
    display: inline-block;
    margin-top: 6px;
}

button.danger {
    background: var(--paper);
    border-color: #f0b4ae;
    color: var(--danger);
}

button.danger:hover {
    background: #fef3f2;
    border-color: var(--danger);
    color: var(--danger);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal.is-hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(22, 33, 47, .45);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(720px, 100%);
    max-height: min(90vh, 900px);
    overflow: auto;
    padding: 16px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.trip-table .cell-container {
    overflow: visible;
    text-overflow: clip;
}

.trip-table .cell-size {
    text-align: center;
}

.trip-table .cell-datetime {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
}

.container-id {
    display: inline-block;
    max-width: 100%;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
}

.size-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.4rem;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef3f7;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
}

.datetime-cell {
    display: grid;
    gap: 2px;
    line-height: 1.2;
}

.datetime-date {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.datetime-time {
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .02em;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th {
    color: var(--muted);
    background: #f7f9fb;
    font-size: 12px;
    text-transform: uppercase;
}

td {
    font-size: 13px;
}

td.empty-state {
    padding: 28px 16px;
    color: var(--muted);
    text-align: center;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-weight: 600;
}

.table-wrap.is-loading {
    opacity: .55;
    pointer-events: none;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 74px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge.accepted,
.badge.paid,
.badge.active {
    color: var(--ok);
    background: #e9f7ef;
}

.badge.rejected,
.badge.overdue,
.badge.inactive {
    color: var(--danger);
    background: #fdebea;
}

.badge.pending,
.badge.draft,
.badge.sent,
.badge.unpaid {
    color: var(--warn);
    background: #fff4df;
}

#toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: min(420px, calc(100vw - 40px));
    padding: 12px 14px;
    border-radius: 8px;
    color: white;
    background: var(--ink);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity .16s ease, transform .16s ease;
}

#toast.show {
    opacity: 1;
    transform: translateY(0);
}

#toast.error {
    background: var(--danger);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-panel {
    width: min(420px, 100%);
    padding: 24px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-form {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.error {
    color: var(--danger);
    font-weight: 700;
}

.is-hidden {
    display: none;
}

@media (max-width: 1100px) {
    .summary-grid,
    .work-grid {
        grid-template-columns: 1fr 1fr;
    }

    #invoiceSection.list-only {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar,
    .top-actions,
    .brand-block {
        align-items: stretch;
        flex-direction: column;
    }

    .brand-text .eyebrow,
    .topbar h1 {
        max-width: none;
        white-space: normal;
    }

    .main-nav {
        flex-wrap: wrap;
    }

    .shell,
    .topbar {
        padding-left: 14px;
        padding-right: 14px;
    }

    .summary-grid,
    .work-grid,
    .form-grid,
    .form-grid.cols-3,
    .form-grid.cols-4 {
        grid-template-columns: 1fr;
    }

    .toolbar > label,
    .toolbar.compact > label {
        max-width: none;
    }
}
