:root {
    --ink: #202c39;
    --paper: #f4f1de;
    --blue: #3d5a80;
    --coral: #e07a5f;
    --mint: #6c9a8b;
    --line: rgba(32, 44, 57, 0.14);
    --muted: rgba(32, 44, 57, 0.64);
    --white: #fffdf7;
    --shadow: 0 20px 60px rgba(32, 44, 57, 0.16);
}

* {
    box-sizing: border-box;
}

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

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

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

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

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

.brand {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    color: inherit;
    text-decoration: none;
}

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

.brand small,
.rail-note,
.eyebrow,
.metric span,
.order-main p,
.phone-top,
.map-head,
.window-row small,
.history-list small,
.person small {
    color: rgba(32, 44, 57, 0.62);
    font-size: 12px;
    letter-spacing: 0;
    text-transform: uppercase;
}

.rail .brand small,
.rail-note {
    color: rgba(244, 241, 222, 0.66);
}

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

.tab {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid rgba(244, 241, 222, 0.12);
    border-radius: 8px;
    color: rgba(244, 241, 222, 0.72);
    background: transparent;
    text-align: left;
    transition: background 180ms ease, color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.tab:hover,
.tab.is-active {
    color: var(--paper);
    border-color: rgba(224, 122, 95, 0.48);
    background: rgba(224, 122, 95, 0.16);
    transform: translateX(2px);
}

.rail-note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: auto;
    line-height: 1.5;
    text-transform: none;
}

.note-dot {
    flex: 0 0 9px;
    width: 9px;
    height: 9px;
    margin-top: 5px;
    border-radius: 999px;
    background: var(--coral);
    box-shadow: 0 0 0 6px rgba(224, 122, 95, 0.16);
}

.workspace {
    display: grid;
    gap: 18px;
    align-content: start;
    min-width: 0;
    padding: 24px;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 340px);
    gap: 20px;
    align-items: end;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--blue);
    font-weight: 800;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2 {
    margin-bottom: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 700;
    line-height: 1.02;
}

h1 {
    max-width: 720px;
    font-size: clamp(36px, 5vw, 72px);
}

h2 {
    font-size: clamp(26px, 3vw, 40px);
}

h3 {
    margin-bottom: 6px;
    font-size: 16px;
    line-height: 1.25;
}

.search {
    display: grid;
    gap: 6px;
}

.search label {
    font-size: 12px;
    color: var(--muted);
}

.search input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--ink);
    background: rgba(255, 253, 247, 0.78);
    outline: none;
}

.search input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px rgba(61, 90, 128, 0.14);
}

.metric-row {
    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-width: 0;
    padding: 16px;
    background: rgba(255, 253, 247, 0.82);
}

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

.metric.accent {
    color: var(--paper);
    background: var(--blue);
}

.metric.accent span {
    color: rgba(244, 241, 222, 0.72);
}

.control-grid {
    display: grid;
    grid-template-columns: minmax(210px, 0.82fr) minmax(360px, 1.5fr) minmax(250px, 0.9fr);
    gap: 18px;
    align-items: stretch;
}

.field-phone,
.panel,
.map-panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 247, 0.86);
    box-shadow: var(--shadow);
}

.field-phone {
    display: flex;
    flex-direction: column;
    min-height: 580px;
    padding: 14px;
    color: var(--paper);
    background:
        linear-gradient(180deg, rgba(32, 44, 57, 0.94), rgba(32, 44, 57, 0.86)),
        var(--ink);
}

.phone-top,
.map-head,
.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.phone-top {
    color: rgba(244, 241, 222, 0.7);
}

.phone-top strong {
    color: var(--paper);
    font-size: 13px;
}

.route-line {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.phone-stop {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) 42px;
    gap: 10px;
    align-items: center;
    min-height: 76px;
    padding: 12px;
    border: 1px solid rgba(244, 241, 222, 0.12);
    border-radius: 8px;
    background: rgba(244, 241, 222, 0.06);
}

.stop-index {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    color: var(--ink);
    background: var(--paper);
    font-size: 12px;
    font-weight: 800;
}

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

.phone-stop small {
    margin-top: 4px;
    color: rgba(244, 241, 222, 0.62);
}

.phone-stop b {
    color: var(--coral);
    font-size: 14px;
    text-align: right;
}

.panel {
    overflow: hidden;
}

.main-panel {
    min-height: 580px;
}

.panel-head {
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.ghost {
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--ink);
    background: transparent;
}

.ghost:hover {
    border-color: var(--coral);
}

.content-stage {
    padding: 14px;
}

.order-board,
.workflow,
.team-grid {
    display: grid;
    gap: 10px;
}

.order-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(130px, 190px);
    gap: 12px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--white);
    transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.order-row:hover {
    transform: translateY(-2px);
    border-color: rgba(61, 90, 128, 0.34);
    box-shadow: 0 12px 26px rgba(32, 44, 57, 0.12);
}

.order-main {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    min-width: 0;
}

.route-badge {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--paper);
    background: var(--ink);
    font-weight: 800;
}

.order-main p {
    margin-bottom: 0;
    overflow-wrap: anywhere;
    text-transform: none;
}

.order-meta {
    display: grid;
    gap: 3px;
    justify-items: end;
    min-width: 0;
    font-size: 13px;
}

.order-meta strong {
    color: var(--blue);
}

.order-meta em {
    color: var(--muted);
    font-style: normal;
}

.progress {
    grid-column: 1 / -1;
    overflow: hidden;
    height: 7px;
    border-radius: 999px;
    background: rgba(32, 44, 57, 0.1);
}

.progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), var(--coral));
    transition: width 220ms ease;
}

.row-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.row-actions button {
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    padding: 7px 10px;
    color: var(--paper);
    background: var(--ink);
}

.row-actions button:nth-child(2) {
    color: var(--ink);
    background: rgba(224, 122, 95, 0.22);
}

.row-actions button:nth-child(3) {
    background: var(--mint);
}

.map-panel {
    display: grid;
    grid-template-rows: auto minmax(260px, 1fr) auto;
    gap: 14px;
    padding: 16px;
}

.map-head {
    color: var(--muted);
}

.map-head strong {
    color: var(--ink);
}

.map {
    position: relative;
    min-height: 280px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(224, 122, 95, 0.16), transparent 36%),
        linear-gradient(45deg, transparent 58%, rgba(61, 90, 128, 0.18)),
        #eef0e2;
}

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

.map-pin {
    position: absolute;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 3px solid var(--white);
    border-radius: 999px;
    color: var(--white);
    background: var(--blue);
    box-shadow: 0 12px 22px rgba(32, 44, 57, 0.24);
    transform: translate(-50%, -50%);
}

.map-pin.done,
.phone-stop.done .stop-index {
    background: var(--mint);
}

.map-pin.ready,
.phone-stop.ready .stop-index {
    background: var(--coral);
}

.map-pin.hold,
.phone-stop.hold .stop-index {
    background: #9b5366;
}

.windows {
    display: grid;
    gap: 8px;
}

.window-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.window-row strong,
.window-row small {
    display: block;
}

.window-row span {
    color: var(--coral);
    font-weight: 800;
}

.history-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.history-list li,
.stage-rule,
.person,
.certificate-list {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: var(--white);
}

.history-list time,
.history-list strong,
.history-list span,
.history-list small {
    display: block;
}

.history-list p {
    margin: 8px 0;
    color: var(--muted);
}

.stage-rule {
    display: grid;
    gap: 8px;
}

.stage-key {
    width: fit-content;
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--paper);
    background: var(--blue);
    font-size: 12px;
}

.stage-rule p {
    margin-bottom: 0;
    color: var(--muted);
}

.rule-bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.test-rule {
    color: var(--blue);
}

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

.person {
    min-width: 0;
}

.person span {
    color: var(--coral);
    font-size: 12px;
    font-weight: 800;
}

.person p {
    margin-bottom: 10px;
    color: var(--muted);
}

.certificate-list {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
    padding: 14px;
    list-style: none;
}

.certificate-list li {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr) 110px;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.certificate-list li:last-child {
    border-bottom: 0;
}

.certificate-list span,
.certificate-list time {
    color: var(--muted);
}

.empty {
    display: grid;
    place-items: center;
    min-height: 260px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
}

.empty.error {
    color: #9b2d20;
}

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

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

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

    .rail {
        min-height: auto;
        padding: 14px;
    }

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

    .rail-note {
        margin-top: 0;
    }

    .control-grid {
        grid-template-columns: minmax(0, 1fr) minmax(280px, 0.8fr);
    }

    .field-phone {
        grid-column: 1 / -1;
        min-height: auto;
    }

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

@media (max-width: 760px) {
    .workspace {
        padding: 14px;
    }

    .topbar,
    .metric-row,
    .control-grid,
    .team-grid {
        grid-template-columns: 1fr;
    }

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

    .metric-row {
        border-radius: 8px;
    }

    .route-line {
        grid-template-columns: 1fr;
    }

    .order-row {
        grid-template-columns: 1fr;
    }

    .order-meta {
        justify-items: start;
    }

    .certificate-list li {
        grid-template-columns: 1fr;
    }
}
