/* Operating Permits product page. Builds on site.css and the shared product page pieces in time.css.
   Colour roles: green is cleared to operate, amber is a minor defect with a repair pending,
   red is out of service (used nowhere else on the page), and grey is a lapsed permit. */

/* The stop and lapsed tokens live in site.css, shared with the Patrol page */

.permit-hero .hero-copy h1 {
    max-width: 13ch;
}

/* Walk-around figure */

.walkaround {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 0 var(--line), 0 24px 48px -24px rgba(20, 33, 61, 0.28);
    overflow: hidden;
}

.walk-stage {
    position: relative;
    margin: 18px 22px 4px;
}

.walk-svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.walk-path {
    fill: none;
    stroke: var(--line);
    stroke-width: 2;
    stroke-dasharray: 4 6;
}

.walk-seg {
    fill: none;
    stroke: var(--verified);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 0;
}

.walkaround.is-walking .walk-seg {
    transition: stroke-dashoffset 0.7s ease-in-out;
}

.walk-seg.is-pending {
    stroke-dashoffset: 1;
}

.truck-box {
    fill: var(--base);
    stroke: var(--ink-soft);
    stroke-width: 2;
}

.truck-cab {
    fill: var(--signal-soft);
    stroke: var(--ink-soft);
    stroke-width: 2;
}

.truck-glass {
    fill: var(--signal);
    opacity: 0.35;
}

.truck-wheel {
    fill: var(--ink);
}

.truck-tag {
    fill: var(--green);
}

.stations {
    position: absolute;
    inset: 0;
}

.station {
    position: absolute;
    transform: translate(-50%, -50%);
}

.station span {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--verified);
    background: var(--verified);
    color: var(--surface);
    font-size: 0.75rem;
    font-weight: 700;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.station.is-defect span {
    border-color: var(--escalate);
    background: var(--escalate);
}

.station.is-pending span {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink-soft);
}

.station.is-current span {
    border-color: var(--signal);
    background: var(--surface);
    color: var(--signal);
    box-shadow: 0 0 0 5px var(--signal-soft);
}

/* Checklist that ticks as the walk progresses */

.walk-list {
    padding: 6px 0;
    border-top: 1px solid var(--line);
}

.walk-item {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
    padding: 7px 22px;
    font-size: 0.88rem;
    transition: opacity 0.3s ease;
}

.walk-zone {
    font-weight: 600;
}

.walk-result {
    font-size: 0.8rem;
    color: var(--ink-soft);
    text-align: right;
}

.walk-item.is-defect .walk-result {
    color: var(--escalate);
    font-weight: 600;
}

.walk-mark {
    position: relative;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--verified);
}

.walk-mark::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid var(--surface);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.walk-item.is-defect .walk-mark {
    background: var(--escalate);
}

.walk-item.is-defect .walk-mark::after {
    content: "!";
    left: 0;
    top: 0;
    width: 16px;
    height: 16px;
    border: 0;
    transform: none;
    color: var(--surface);
    font-size: 0.65rem;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
}

.walk-item.is-pending {
    opacity: 0.35;
}

.walk-item.is-pending .walk-mark {
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--line);
}

.walk-item.is-pending .walk-mark::after,
.walk-item.is-pending .walk-result {
    visibility: hidden;
}

/* The permit */

.permit {
    margin: 4px 22px 18px;
    padding: 16px 18px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--verified);
    background: var(--verified-soft);
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

.permit-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.permit-unit {
    font-variation-settings: "wdth" 118;
    font-weight: 700;
    font-size: 1.2rem;
}

.permit-sub {
    font-size: 0.82rem;
    color: var(--ink-soft);
}

.permit-badge {
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--verified);
    color: var(--surface);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.permit-validity {
    margin-top: 14px;
}

.permit-bar {
    height: 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--verified) 18%, transparent);
    overflow: hidden;
}

.permit-fill {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: var(--verified);
    transition: width 0.9s ease-out;
}

.permit-until {
    margin-top: 8px;
    font-size: 0.85rem;
}

.permit[data-state="checking"] {
    border-color: var(--line);
    background: var(--base);
}

.permit[data-state="checking"] .permit-badge {
    background: var(--signal-soft);
    color: var(--signal);
}

.permit[data-state="checking"] .permit-fill {
    width: 0;
}

.walkaround .timecard-caption {
    border-top: 1px solid var(--line);
}

/* Permit states */

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

.state-card {
    position: relative;
    padding: 22px 20px 24px;
    border-radius: var(--radius-sm);
    border-top: 4px solid var(--tone);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
}

.state-card p:last-child {
    margin-top: 10px;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

.state-name {
    font-variation-settings: "wdth" 112;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--tone);
}

.state-when {
    margin-top: 2px;
    font-weight: 600;
    font-size: 0.9rem;
}

.state-valid { --tone: var(--verified); }
.state-minor { --tone: var(--escalate); }
.state-major { --tone: var(--stop); }
.state-due { --tone: var(--lapsed); }

/* Checklist zones: numbered because they are the walk order */

.checklist-section {
    padding-top: 0;
}

.zones {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
    counter-reset: zone;
}

.zones li {
    position: relative;
    padding: 26px 24px 28px 64px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    counter-increment: zone;
}

.zones li::before {
    content: counter(zone);
    position: absolute;
    left: 22px;
    top: 24px;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--verified);
    color: var(--verified);
    font-size: 0.85rem;
    font-weight: 700;
}

.zones p {
    margin-top: 6px;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

/* Yard board states, on top of the board in time.css */

.state.is-minor {
    background: var(--escalate-soft);
    color: var(--escalate);
}

.state.is-major {
    background: var(--stop-soft);
    color: var(--stop);
}

.state.is-due {
    background: var(--lapsed-soft);
    color: var(--lapsed);
}

.yard-rows li {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr) auto 64px;
}

/* Repair loop: the second step is the moment the unit comes off the road */

.repair-loop .loop-escalate .loop-step {
    border-color: var(--stop);
    color: var(--stop);
}

.reg-note {
    max-width: 820px;
    margin-top: 28px;
    font-size: 0.875rem;
    color: var(--ink-soft);
}

/* Responsive */

@media (max-width: 1080px) {
    .states {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .zones {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .states,
    .zones {
        grid-template-columns: minmax(0, 1fr);
    }

    .walk-stage {
        margin: 14px 12px 4px;
    }

    .station span {
        width: 22px;
        height: 22px;
        font-size: 0.7rem;
    }

    .walk-item {
        grid-template-columns: 18px minmax(0, 1fr);
        padding: 7px 16px;
    }

    .walk-result {
        grid-column: 2;
        text-align: left;
    }

    .permit {
        margin: 4px 16px 16px;
    }

    .permit-head {
        flex-direction: column;
    }

    .yard-rows li {
        grid-template-columns: minmax(0, 1fr) auto;
    }
}
