/* ==========================================================================
   Record patterns used instead of tables.
   rec-*    : row cards (one record per card, fields wrap on narrow screens)
   tile-*   : card grids for people, drivers, rules and jobs
   route-*  : load cards (collection -> delivery)
   timeline : dated history (payments, credits, promises, emails, charges)
   receipt  : totals and pay calculations
   ========================================================================== */

.tone-danger  { --tone: #d9534f; --tone-bg: #fdecec; --tone-ink: #a52a26; }
.tone-warning { --tone: #e0a030; --tone-bg: #fdf4e3; --tone-ink: #8a5a06; }
.tone-success { --tone: var(--app-teal); --tone-bg: var(--app-teal-soft); --tone-ink: #24785f; }
.tone-info    { --tone: #6c8cd5; --tone-bg: #edf2fc; --tone-ink: #2f4f9a; }
.tone-muted   { --tone: #9aa5ad; --tone-bg: #f0f2f4; --tone-ink: #4d5860; }

.pill {
    display: inline-block;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    background: var(--tone-bg, #f0f2f4);
    color: var(--tone-ink, #4d5860);
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
}

.rec-label {
    display: block;
    color: var(--app-muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Row cards */
.rec-list {
    display: grid;
    gap: 0.6rem;
}

.rec {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 1.5rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--app-line);
    border-left: 4px solid var(--tone, var(--app-line));
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.rec-link:hover,
.rec-link:focus-within {
    border-color: var(--app-teal);
    border-left-color: var(--tone, var(--app-teal));
    box-shadow: 0 6px 18px rgba(20, 35, 48, 0.08);
    transform: translateY(-1px);
}

.rec-link .stretched-link:focus-visible { outline: none; }
.rec-link:has(.stretched-link:focus-visible) { outline: 2px solid var(--app-teal); outline-offset: 2px; }

.rec-main {
    flex: 1 1 14rem;
    min-width: 0;
}

.rec-title {
    color: var(--app-ink);
    font-weight: 700;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.rec-sub {
    color: var(--app-muted);
    font-size: 0.86rem;
    overflow-wrap: anywhere;
}

.rec-field {
    flex: 0 1 auto;
    min-width: 6.5rem;
    font-size: 0.9rem;
}

.rec-amount {
    margin-left: auto;
    font-size: 1.05rem;
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}

.rec-chevron {
    color: var(--app-muted);
    font-size: 1.4rem;
    line-height: 1;
}

/* Controls inside a linked card sit above its card-wide link. */
.rec-actions {
    position: relative;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.rec-avatar {
    display: grid;
    flex: 0 0 2.6rem;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 50%;
    background: var(--tone-bg, var(--app-teal-soft));
    color: var(--tone-ink, var(--app-teal));
    font-weight: 700;
}

.rec-muted { opacity: 0.7; }

/* Big number at the start of a row card, e.g. days overdue. */
.rec-counter {
    display: flex;
    flex: 0 0 3.6rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 3.4rem;
    border-radius: 10px;
    background: var(--tone-bg, var(--app-canvas));
    color: var(--tone-ink, var(--app-ink));
    line-height: 1.05;
}

.rec-counter strong { font-size: 1.3rem; }
.rec-counter span { font-size: 0.66rem; text-transform: uppercase; }

.rec-meter-field { flex: 1 1 13rem; }

.rec-meter {
    height: 0.45rem;
    margin: 0.3rem 0;
    overflow: hidden;
    border-radius: 999px;
    background: var(--app-canvas);
}

.rec-meter > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--tone, var(--app-teal));
}

/* Tile grid */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16.5rem), 1fr));
    gap: 0.85rem;
}

.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--app-line);
    border-top: 4px solid var(--tone, var(--app-line));
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.tile-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.tile-head > div { min-width: 0; }

.tile-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    background: var(--app-canvas);
    font-size: 0.9rem;
}

.tile-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: auto;
}

/* Route (load) cards */
.route-list {
    display: grid;
    gap: 0.6rem;
}

.route {
    position: relative;
    display: grid;
    grid-template-columns: 4.2rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.route-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 3.4rem;
    border-radius: 10px;
    background: var(--app-canvas);
    line-height: 1.1;
    text-align: center;
}

.route-date strong { font-size: 1.25rem; }
.route-date span { color: var(--app-muted); font-size: 0.68rem; text-transform: uppercase; }

.route-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.9rem;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
}

.route-path {
    position: relative;
    display: grid;
    gap: 0.3rem;
    padding-left: 1.1rem;
    font-size: 0.86rem;
}

.route-path::before {
    position: absolute;
    top: 0.55rem;
    bottom: 0.55rem;
    left: 0.28rem;
    border-left: 2px dashed var(--app-line);
    content: "";
}

.route-stop { position: relative; overflow-wrap: anywhere; }

.route-stop::before {
    position: absolute;
    top: 0.4rem;
    left: -1.1rem;
    width: 0.6rem;
    height: 0.6rem;
    border: 2px solid var(--app-teal);
    border-radius: 50%;
    background: var(--app-surface);
    content: "";
}

.route-stop.is-drop::before { border-color: var(--app-ink); background: var(--app-ink); }

.route-money {
    text-align: right;
    white-space: nowrap;
}

.route-money strong { display: block; font-size: 1.05rem; }

/* Timeline */
.timeline {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline-item {
    position: relative;
    padding: 0 0 1rem 1.6rem;
}

.timeline-item::before {
    position: absolute;
    top: 0.35rem;
    left: 0.2rem;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--tone, var(--app-teal));
    box-shadow: 0 0 0 3px var(--tone-bg, var(--app-teal-soft));
    content: "";
}

.timeline-item:not(:last-child)::after {
    position: absolute;
    top: 1.2rem;
    bottom: 0.1rem;
    left: 0.52rem;
    border-left: 2px solid var(--app-line);
    content: "";
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.25rem 1rem;
}

.timeline-when {
    color: var(--app-muted);
    font-size: 0.8rem;
}

.timeline-amount {
    font-weight: 700;
    white-space: nowrap;
}

.timeline-body {
    color: var(--app-muted);
    font-size: 0.86rem;
    overflow-wrap: anywhere;
}

/* Receipt */
.receipt {
    width: 100%;
    max-width: 27rem;
    margin-left: auto;
    padding: 0.85rem 1rem;
    border: 1px dashed #c9d8cf;
    border-radius: var(--app-radius);
    background: var(--app-canvas);
    font-size: 0.92rem;
}

.receipt-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.25rem 0;
}

.receipt-row > span:last-child { font-weight: 600; white-space: nowrap; }
.receipt-row.is-minor { padding-left: 0.75rem; color: var(--app-muted); font-size: 0.85rem; }

.receipt-row.is-total {
    margin-top: 0.35rem;
    padding-top: 0.55rem;
    border-top: 1px solid #c9d8cf;
    font-size: 1.05rem;
    font-weight: 700;
}

/* Route sheet rows (DPD): the sheet's columns as labelled cells that wrap on narrow screens. */
.sheet-list {
    display: grid;
    gap: 0.6rem;
}

.sheet-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(5.6rem, 1fr));
    align-items: start;
    gap: 0.55rem 0.9rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--app-line);
    border-left: 4px solid var(--tone, var(--app-line));
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.sheet-cell {
    min-width: 0;
    font-size: 0.9rem;
}

.sheet-value {
    display: block;
    overflow-wrap: anywhere;
}

.sheet-strong .sheet-value { font-weight: 700; }

/* A pill in a narrow sheet cell wraps instead of running into the next column. */
.sheet-value .pill { white-space: normal; overflow-wrap: normal; }

.sheet-total .sheet-value {
    color: var(--tone-ink, var(--app-ink));
    font-size: 1.05rem;
    font-weight: 700;
}

.sheet-reg {
    display: inline-block;
    padding: 0 0.35rem;
    border: 1px solid #c9a400;
    border-radius: 4px;
    background: #ffd400;
    color: #111111;
    font-family: "Arial Narrow", Arial, sans-serif;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.sheet-action {
    align-self: center;
    justify-self: end;
}

.sheet-note {
    grid-column: 1 / -1;
    color: var(--app-muted);
    font-size: 0.82rem;
}

/* Wide screens: the eleven sheet columns on one line, like the route sheet itself. */
@media (min-width: 1200px) {
    .sheet-row {
        grid-template-columns: 0.8fr 0.9fr 0.9fr 0.7fr 1.1fr 0.6fr 1fr 1.2fr 0.7fr 0.9fr 0.9fr auto;
        gap: 0.4rem 0.7rem;
    }

    .sheet-cell .rec-label { white-space: nowrap; }

    /* DPD Portal rows have twelve columns. */
    .sheet-row.is-portal {
        grid-template-columns: 1.1fr 0.7fr 0.85fr 0.75fr 0.75fr 0.75fr 0.8fr 0.75fr 0.95fr 0.6fr 0.7fr 1.1fr auto;
    }

    .sheet-row.is-portal .sheet-cell .rec-label { white-space: normal; }
}

@media (max-width: 575.98px) {
    .rec { gap: 0.5rem 1rem; }
    .sheet-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .rec-amount { margin-left: 0; text-align: left; }
    .route { grid-template-columns: 3.6rem minmax(0, 1fr); }
    .route-money { grid-column: 2; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
    .rec { transition: none; }
    .rec-link:hover, .rec-link:focus-within { transform: none; }
}

/* How a DPD day's Total was reached: "day rate £90.00" or "110 × £1.00". */
.sheet-basis {
    display: block;
    color: var(--app-muted);
    font-size: 0.7rem;
    font-weight: 400;
}

/* Page toolbar: icon buttons at the top right of a page that open a form panel or start a download. */
.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.page-actions .icon-btn {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.15rem;
}

/* The button whose panel is open stays highlighted. */
.page-actions .btn[aria-expanded="true"] {
    background: #000000;
    border-color: #000000;
    color: #ffffff;
}

/* Report tables (e.g. FD-wise revenue on the DPD dashboard). */
.report-table thead th {
    color: var(--app-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom-color: var(--app-line);
}

.report-table tfoot th {
    border-top: 2px solid var(--app-ink);
    border-bottom: 0;
}

/* Weekly operations dashboard */
.ops-tabs { gap: 0.35rem; flex-wrap: wrap; }
.ops-tabs .nav-link { border-radius: 999px; color: var(--app-ink); background: var(--app-surface); border: 1px solid var(--app-line); }
.ops-tabs .nav-link.active { color: #fff; background: var(--app-teal); border-color: var(--app-teal); }

.ops-kpi-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin: 0.15rem 0 0.25rem; }
.ops-change { color: var(--app-ink); }

.ops-untracked {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    padding: 0.7rem 0.9rem;
    border: 1px dashed var(--app-line);
    border-radius: var(--app-radius);
    color: var(--app-muted);
    font-size: 0.88rem;
}
.ops-untracked strong { color: var(--app-ink); }

.ops-actions { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.35rem; }

.ops-worked { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.ops-worked .fi { color: var(--app-teal); }
.ops-worked.is-pending .fi { color: #8a5a06; }
.ops-attendance td, .ops-attendance th { white-space: nowrap; }

.ops-state { color: var(--app-ink); border: 2px solid transparent !important; }
.ops-state.is-active { border-color: var(--app-teal) !important; }

/* Day strip: one series, Monday to Sunday, bars on a shared baseline with 4px rounded tops. */
.day-strip { margin: 0; }
.day-strip-bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.day-strip-col { text-align: center; border-radius: 6px; outline-offset: 2px; }
.day-strip-col:hover, .day-strip-col:focus { background: var(--app-canvas); }
.day-strip-track { height: 7rem; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--app-line); }
.day-strip-track span { display: block; width: 62%; max-width: 2.6rem; border-radius: 4px 4px 0 0; background: var(--app-teal); }
.day-strip-day { margin-top: 0.3rem; font-size: 0.75rem; color: var(--app-muted); }
.day-strip-value { font-size: 0.85rem; font-weight: 600; color: var(--app-ink); }

@media print {
    .tab-content > .tab-pane { display: block !important; opacity: 1 !important; margin-bottom: 1.5rem; break-inside: avoid-page; }
}

/* Home: one tile per area */
.home-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 2.5rem; }
.home-logo { height: 5.5rem; width: auto; }
.home-account { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1.25rem; }
.home-tile {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-height: 15rem;
    padding: 1.75rem;
    justify-content: space-between;
    border: 1px solid var(--app-line);
    border-top: 5px solid var(--home-accent, var(--app-teal));
    border-radius: var(--app-radius);
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
    color: var(--app-ink);
    text-decoration: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
a.home-tile:hover, a.home-tile:focus { transform: translateY(-2px); color: var(--app-ink); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.1); }
.home-cx { --home-accent: #282837; }
.home-dpd { --home-accent: #d2042d; }
.home-report { --home-accent: #1f1f1f; }
.home-tile-icon { font-size: 2.6rem; color: var(--home-accent); line-height: 1; }
.home-tile-title { font-size: 1.6rem; font-weight: 700; flex: 1; }
.home-tile-text { color: var(--app-muted); flex: 1; }
.home-tile-access { font-size: 0.85rem; font-weight: 600; }
.home-tile.is-locked { opacity: 0.55; border-top-color: var(--app-line); }
.home-tile.is-locked .home-tile-icon { color: var(--app-muted); }
.home-page { max-width: 72rem; margin: 0 auto; min-height: calc(100vh - 7rem); display: flex; flex-direction: column; justify-content: center; }

/* Sign-in page logo */
.login-logo { display: block; width: min(100%, 22rem); height: auto; margin: 1rem auto 1.75rem; }

/* Payment reminder day picker */
.day-chip { min-width: 3.6rem; }

/* Import from CSV / Excel (every add form) */
.import-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.import-columns { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0.4rem 1rem; }
