:root {
    --ink: #202c39;
    --paper: #f4f1de;
    --steel: #3d5a80;
    --clay: #e07a5f;
    --leaf: #4d7c59;
    --mint: #d8ead2;
    --line: rgba(32, 44, 57, 0.16);
    --soft: rgba(244, 241, 222, 0.72);
    --white: #fffdf6;
    --shadow: 0 24px 60px rgba(32, 44, 57, 0.14);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--paper);
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        linear-gradient(90deg, rgba(32, 44, 57, 0.06) 1px, transparent 1px),
        linear-gradient(180deg, rgba(32, 44, 57, 0.05) 1px, transparent 1px),
        var(--paper);
    background-size: 38px 38px;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
    min-height: 100vh;
}

.rail {
    display: flex;
    flex-direction: column;
    gap: 28px;
    min-height: 100vh;
    padding: 28px 22px;
    color: var(--paper);
    background: var(--ink);
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
    color: inherit;
    text-decoration: none;
}

.brand img {
    flex: 0 0 auto;
}

.brand strong {
    display: block;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 24px;
    line-height: 1;
    letter-spacing: 0;
}

.brand small,
.eyebrow,
.field-note__label {
    color: rgba(244, 241, 222, 0.68);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.nav-tabs {
    display: grid;
    gap: 8px;
}

.nav-tab {
    width: 100%;
    min-height: 44px;
    border: 0;
    border-left: 3px solid transparent;
    padding: 0 12px;
    color: rgba(244, 241, 222, 0.72);
    text-align: left;
    background: transparent;
}

.nav-tab:hover,
.nav-tab.is-active {
    color: var(--paper);
    border-left-color: var(--clay);
    background: rgba(244, 241, 222, 0.08);
}

.field-note {
    margin-top: auto;
    border-top: 1px solid rgba(244, 241, 222, 0.16);
    padding-top: 20px;
}

.field-note strong {
    display: block;
    margin: 9px 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 22px;
    line-height: 1.2;
}

.field-note p {
    margin: 0;
    color: rgba(244, 241, 222, 0.72);
    line-height: 1.45;
}

.workspace {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.topbar .eyebrow {
    color: var(--steel);
}

h1,
h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    line-height: 1.04;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(34px, 5vw, 68px);
}

h2 {
    font-size: 27px;
}

.search-box {
    display: grid;
    gap: 6px;
    min-width: min(320px, 100%);
}

.search-box label {
    color: var(--steel);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.search-box input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 14px;
    color: var(--ink);
    background: rgba(255, 253, 246, 0.82);
    outline: none;
}

.search-box input:focus {
    border-color: var(--steel);
    box-shadow: 0 0 0 3px rgba(61, 90, 128, 0.16);
}

.view {
    display: none;
}

.view.is-active {
    display: block;
    animation: rise 260ms ease-out both;
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--line);
}

.metric {
    min-height: 92px;
    padding: 18px;
    background: rgba(255, 253, 246, 0.84);
}

.metric span {
    display: block;
    color: var(--steel);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    margin-top: 9px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 35px;
    line-height: 1;
}

.metric--signal strong {
    color: var(--leaf);
}

.metric--urgent strong {
    color: var(--clay);
}

.stage-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0;
}

.stage-pill {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 14px;
    color: var(--ink);
    background: rgba(255, 253, 246, 0.72);
}

.stage-pill.is-active {
    border-color: var(--ink);
    color: var(--paper);
    background: var(--ink);
}

.dispatch-grid {
    display: grid;
    grid-template-columns: minmax(280px, 0.95fr) minmax(360px, 1.35fr);
    gap: 18px;
    align-items: start;
}

.queue-list,
.route-console,
#view-history,
#view-workflow,
#view-team {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 246, 0.84);
    box-shadow: var(--shadow);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 54px;
    border-bottom: 1px solid var(--line);
    padding: 0 16px;
    gap: 12px;
}

.section-title span {
    font-weight: 800;
}

.section-title strong {
    color: var(--steel);
    font-size: 12px;
    text-transform: uppercase;
}

.items-list {
    display: grid;
    max-height: 62vh;
    overflow: auto;
}

.queue-item {
    display: grid;
    gap: 7px;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 15px 16px;
    color: inherit;
    text-align: left;
    background: transparent;
}

.queue-item:hover,
.queue-item.is-selected {
    background: rgba(216, 234, 210, 0.7);
}

.queue-item__head,
.queue-item__foot,
.detail-head,
.history-row,
.exercise-row,
.team-row,
.setting-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.queue-item__head strong {
    font-size: 13px;
}

.queue-item__title {
    font-weight: 800;
    line-height: 1.25;
}

.queue-item__meta,
.queue-item__foot,
.timeline-stop small,
.care-note p,
.exercise-row p,
.team-row p,
.setting-line span,
.history-row p {
    color: rgba(32, 44, 57, 0.68);
    font-size: 13px;
    line-height: 1.4;
}

.queue-item__foot em {
    font-style: normal;
}

.priority,
.status-chip {
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.priority--critical {
    color: #7d2e1f;
    background: rgba(224, 122, 95, 0.22);
}

.priority--high {
    color: #314967;
    background: rgba(61, 90, 128, 0.16);
}

.priority--normal {
    color: #31523a;
    background: rgba(77, 124, 89, 0.16);
}

.progress-line,
.load {
    display: block;
    overflow: hidden;
    width: 100%;
    height: 7px;
    border-radius: 999px;
    background: rgba(32, 44, 57, 0.1);
}

.progress-line i,
.load i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--leaf), var(--clay));
}

.route-console {
    min-height: 600px;
}

.detail-empty,
.empty-state,
.loading {
    padding: 28px;
    color: rgba(32, 44, 57, 0.62);
}

.detail-panel {
    display: grid;
    gap: 18px;
    padding: 18px;
}

.detail-head {
    align-items: start;
}

.detail-head .eyebrow {
    color: var(--steel);
    margin: 0 0 6px;
}

.status-chip--available {
    color: #31523a;
    background: var(--mint);
}

.status-chip--reserved {
    color: #314967;
    background: rgba(61, 90, 128, 0.16);
}

.status-chip--care {
    color: #7d2e1f;
    background: rgba(224, 122, 95, 0.2);
}

.status-chip--delivery {
    color: var(--paper);
    background: var(--ink);
}

.route-map {
    position: relative;
    overflow: hidden;
    min-height: 238px;
    border: 1px solid rgba(32, 44, 57, 0.22);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(61, 90, 128, 0.13), transparent 40%),
        linear-gradient(45deg, rgba(77, 124, 89, 0.18), transparent 55%),
        var(--soft);
}

.map-grid {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(32, 44, 57, 0.12) 1px, transparent 1px),
        linear-gradient(180deg, rgba(32, 44, 57, 0.12) 1px, transparent 1px);
    background-size: 42px 42px;
}

.route-map strong {
    position: absolute;
    left: 16px;
    bottom: 14px;
    max-width: calc(100% - 32px);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--paper);
    background: rgba(32, 44, 57, 0.86);
}

.map-pin {
    position: absolute;
    width: 22px;
    height: 22px;
    border: 4px solid var(--paper);
    border-radius: 50%;
    background: var(--clay);
    box-shadow: 0 0 0 8px rgba(224, 122, 95, 0.2);
    transform: translate(-50%, -50%);
    animation: pulse 1700ms ease-in-out infinite;
}

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

.timeline-stop {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px;
}

.timeline-stop span {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: rgba(32, 44, 57, 0.65);
    background: rgba(32, 44, 57, 0.1);
    font-weight: 800;
}

.timeline-stop.is-done {
    border-color: rgba(77, 124, 89, 0.42);
    background: rgba(216, 234, 210, 0.54);
}

.timeline-stop.is-done span {
    color: var(--paper);
    background: var(--leaf);
}

.timeline-stop strong,
.timeline-stop small {
    display: block;
    overflow-wrap: anywhere;
}

.care-note {
    border-left: 4px solid var(--clay);
    padding: 4px 0 4px 13px;
}

.care-note span {
    color: var(--steel);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.care-note p {
    margin: 5px 0 0;
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.primary-action,
.secondary-action {
    min-height: 42px;
    border-radius: 8px;
    padding: 0 15px;
    font-weight: 800;
}

.primary-action {
    border: 0;
    color: var(--paper);
    background: var(--clay);
}

.primary-action:disabled {
    cursor: default;
    opacity: 0.55;
}

.secondary-action {
    border: 1px solid var(--line);
    color: var(--ink);
    background: rgba(255, 253, 246, 0.9);
}

#view-history,
#view-workflow,
#view-team {
    overflow: hidden;
}

.history-list,
.workflow-panel,
.team-panel {
    display: grid;
    padding: 14px;
}

.history-row,
.exercise-row,
.team-row,
.setting-line {
    border-bottom: 1px solid var(--line);
    padding: 14px 2px;
}

.history-row time {
    width: 160px;
    color: var(--steel);
    font-size: 12px;
    font-weight: 800;
}

.history-row div,
.exercise-row div,
.team-row div:nth-child(2) {
    min-width: 0;
    flex: 1;
}

.history-row p,
.exercise-row p,
.team-row p {
    margin: 4px 0 0;
}

.history-row span {
    display: grid;
    place-items: center;
    min-width: 42px;
    height: 42px;
    border-radius: 50%;
    color: var(--paper);
    background: var(--steel);
    font-weight: 900;
}

.workflow-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 22px;
}

.workflow-layout h2 {
    margin: 6px 0 10px;
    font-size: 24px;
}

.exercise-row span {
    min-width: 82px;
    color: var(--clay);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.exercise-row b {
    min-width: 58px;
    text-align: right;
}

.avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    color: var(--paper);
    background: var(--ink);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 22px;
}

.team-row .load {
    max-width: 180px;
}

.team-row b {
    min-width: 74px;
    text-align: right;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(420px, calc(100vw - 36px));
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--paper);
    background: var(--ink);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%,
    100% {
        box-shadow: 0 0 0 7px rgba(224, 122, 95, 0.18);
    }
    50% {
        box-shadow: 0 0 0 15px rgba(224, 122, 95, 0.05);
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .rail {
        position: sticky;
        top: 0;
        z-index: 3;
        min-height: 0;
        padding: 14px;
    }

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

    .nav-tab {
        min-height: 38px;
        border-left: 0;
        border-bottom: 2px solid transparent;
        padding: 0 6px;
        text-align: center;
    }

    .field-note {
        display: none;
    }

    .workspace {
        padding: 18px 14px;
    }

    .topbar,
    .dispatch-grid,
    .workflow-layout {
        grid-template-columns: 1fr;
        display: grid;
    }

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

    .items-list {
        max-height: none;
    }

    .route-console {
        min-height: 0;
    }

    .timeline {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .brand strong {
        font-size: 20px;
    }

    .brand small {
        display: none;
    }

    h1 {
        font-size: 39px;
    }

    .summary-strip {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: 72px;
    }

    .history-row,
    .exercise-row,
    .team-row {
        align-items: start;
        display: grid;
        grid-template-columns: 1fr;
    }

    .history-row time,
    .exercise-row span,
    .team-row b,
    .team-row .load {
        width: 100%;
        min-width: 0;
        max-width: none;
        text-align: left;
    }
}

