:root {
    --ink: #202c39;
    --paper: #f4f1de;
    --blue: #3d5a80;
    --coral: #e07a5f;
    --mint: #7fb685;
    --line: rgba(32, 44, 57, 0.16);
    --muted: rgba(32, 44, 57, 0.66);
    --shadow: 0 18px 48px rgba(32, 44, 57, 0.16);
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--ink);
}

body {
    margin: 0;
    min-height: 100svh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(32, 44, 57, 0.96) 0, rgba(32, 44, 57, 0.96) 286px, transparent 286px),
        radial-gradient(circle at 82% 8%, rgba(224, 122, 95, 0.20), transparent 30%),
        var(--paper);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.dispatch-rail {
    position: sticky;
    top: 0;
    min-height: 100svh;
    padding: 28px 22px;
    color: var(--paper);
    background:
        linear-gradient(180deg, rgba(61, 90, 128, 0.24), rgba(32, 44, 57, 0)),
        var(--ink);
    overflow: hidden;
}

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

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

.brand em {
    display: block;
    margin-top: 4px;
    color: rgba(244, 241, 222, 0.68);
    font-size: 12px;
    font-style: normal;
}

.tabs {
    display: grid;
    gap: 8px;
    margin-top: 42px;
}

.tab,
.searchbar button,
.action-row button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: inherit;
}

.tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    color: rgba(244, 241, 222, 0.78);
    text-align: left;
}

.tab::after {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: rgba(244, 241, 222, 0.22);
    content: "";
}

.tab.is-active,
.tab:hover {
    background: rgba(244, 241, 222, 0.10);
    color: var(--paper);
}

.tab.is-active::after {
    background: var(--coral);
}

.rail-map {
    position: relative;
    height: 196px;
    margin-top: 54px;
    border: 1px solid rgba(244, 241, 222, 0.14);
    border-radius: 8px;
    background:
        linear-gradient(rgba(244, 241, 222, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(244, 241, 222, 0.07) 1px, transparent 1px);
    background-size: 28px 28px;
}

.map-route {
    position: absolute;
    inset: 32px 38px;
    border-left: 2px solid var(--coral);
    border-bottom: 2px solid var(--coral);
    transform: skew(-12deg);
}

.map-node {
    position: absolute;
    z-index: 1;
    width: 14px;
    height: 14px;
    border: 3px solid var(--paper);
    border-radius: 999px;
    background: var(--coral);
    animation: pulse 2.8s ease-in-out infinite;
}

.node-a { left: 33px; top: 28px; }
.node-b { left: 78px; top: 76px; animation-delay: 0.2s; }
.node-c { right: 54px; bottom: 44px; animation-delay: 0.4s; }
.node-d { right: 28px; top: 36px; animation-delay: 0.6s; }

.rail-note {
    position: absolute;
    right: 22px;
    bottom: 24px;
    left: 22px;
    margin: 0;
    color: rgba(244, 241, 222, 0.72);
    font-size: 13px;
    line-height: 1.45;
}

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

.topbar {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(320px, 580px);
    gap: 22px;
    align-items: end;
    margin-bottom: 16px;
}

.eyebrow,
.mono {
    margin: 0 0 6px;
    color: var(--blue);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

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

h1 {
    font-size: clamp(30px, 4vw, 58px);
    line-height: 0.96;
}

h2 {
    font-size: 31px;
    line-height: 1.05;
}

h3 {
    margin: 0;
    font-size: 16px;
}

.searchbar {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) 132px 112px;
    gap: 8px;
}

.searchbar input,
.searchbar select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: rgba(255, 255, 255, 0.48);
    color: var(--ink);
    outline: none;
}

.searchbar button,
.action-row button {
    background: var(--ink);
    color: var(--paper);
}

.notice {
    min-height: 40px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.42);
    color: var(--muted);
    font-size: 13px;
}

.notice.ok {
    border-color: rgba(127, 182, 133, 0.46);
    color: #315d38;
}

.notice.bad {
    border-color: rgba(224, 122, 95, 0.58);
    color: #8d3a27;
}

.screen {
    display: none;
    animation: rise 260ms ease-out;
}

.screen.is-visible {
    display: block;
}

.control-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 288px;
    gap: 16px;
    align-items: start;
}

.case-board,
.queue-panel,
.mobile-mirror,
.history-list,
.workflow-step,
.team-member {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.50);
    box-shadow: var(--shadow);
}

.case-board {
    min-height: 520px;
    padding: 22px;
}

.case-head,
.section-title {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.stage-badge,
.metric-pill {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 8px 10px;
    background: var(--coral);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.case-summary {
    max-width: 760px;
    margin: 16px 0 0;
    color: var(--muted);
    line-height: 1.55;
}

.route-line {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 28px;
}

.route-stop {
    position: relative;
    min-height: 148px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 44px 12px 12px;
    background: var(--paper);
}

.route-stop::before {
    position: absolute;
    top: 20px;
    right: -11px;
    width: 20px;
    height: 2px;
    background: var(--blue);
    content: "";
}

.route-stop:last-child::before {
    display: none;
}

.route-stop.done {
    background: rgba(127, 182, 133, 0.14);
}

.route-stop.active {
    border-color: var(--coral);
    box-shadow: inset 0 0 0 2px rgba(224, 122, 95, 0.16);
}

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

.route-stop strong,
.route-stop p {
    display: block;
    margin: 0;
}

.route-stop p {
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.finance-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 20px;
}

.finance-cell {
    min-height: 108px;
    border-left: 3px solid var(--blue);
    padding: 12px 12px 10px;
    background: rgba(32, 44, 57, 0.06);
}

.finance-cell span,
.finance-cell em {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
}

.finance-cell strong {
    display: block;
    margin: 8px 0 5px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 24px;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 22px;
}

.action-row button {
    padding: 0 16px;
}

.action-row .primary {
    background: var(--coral);
}

.mobile-mirror {
    grid-column: 2;
    grid-row: span 2;
    padding: 14px;
    background: var(--ink);
}

.phone {
    min-height: 568px;
    border: 1px solid rgba(244, 241, 222, 0.18);
    border-radius: 28px;
    padding: 18px;
    color: var(--paper);
    background:
        linear-gradient(180deg, rgba(61, 90, 128, 0.34), transparent),
        #15202b;
}

.phone-bar,
.phone-ledger div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.phone-bar {
    color: rgba(244, 241, 222, 0.7);
    font-size: 12px;
}

.compact-map {
    position: relative;
    height: 146px;
    margin: 24px 0;
    border: 1px solid rgba(244, 241, 222, 0.12);
    border-radius: 8px;
    background:
        linear-gradient(rgba(244, 241, 222, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(244, 241, 222, 0.06) 1px, transparent 1px);
    background-size: 20px 20px;
}

.compact-map::after {
    position: absolute;
    inset: 26px 26px 34px 48px;
    border-right: 2px solid var(--coral);
    border-bottom: 2px solid var(--coral);
    transform: skew(16deg);
    content: "";
}

.compact-map span {
    position: relative;
    z-index: 1;
    display: inline-block;
    width: 12px;
    height: 12px;
    margin: 24px 0 0 26px;
    border-radius: 999px;
    background: var(--coral);
    box-shadow: 0 0 0 4px rgba(224, 122, 95, 0.16);
}

.phone h3 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 24px;
    line-height: 1.1;
}

.phone p {
    color: rgba(244, 241, 222, 0.68);
    line-height: 1.45;
}

.phone-ledger {
    display: grid;
    gap: 10px;
    margin-top: 24px;
}

.phone-ledger div {
    border-top: 1px solid rgba(244, 241, 222, 0.14);
    padding-top: 10px;
    font-size: 13px;
}

.queue-panel {
    min-height: 288px;
    padding: 18px;
}

.case-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.case-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    width: 100%;
    min-height: 70px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px;
    background: rgba(244, 241, 222, 0.60);
    color: var(--ink);
    text-align: left;
    transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.case-row:hover,
.case-row.is-selected {
    border-color: var(--coral);
    background: #fffaf0;
    transform: translateY(-1px);
}

.row-main strong,
.row-main em,
.row-meta b,
.row-meta i {
    display: block;
}

.row-main em,
.row-meta i {
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
}

.row-meta {
    min-width: 78px;
    text-align: right;
}

.history-list {
    display: grid;
    gap: 0;
    padding: 4px 18px;
}

.history-item {
    display: grid;
    grid-template-columns: 158px minmax(0, 1fr);
    gap: 18px;
    border-bottom: 1px solid var(--line);
    padding: 16px 0;
}

.history-item:last-child {
    border-bottom: 0;
}

.history-item span {
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
}

.history-item p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.45;
}

.section-title {
    margin-bottom: 16px;
}

#caseSelect {
    max-width: 360px;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.56);
}

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

.workflow-step {
    min-height: 260px;
    padding: 18px;
}

.workflow-step > span {
    display: inline-block;
    border-bottom: 2px solid var(--coral);
    padding-bottom: 6px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
}

.workflow-step h3 {
    margin-top: 18px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 23px;
    line-height: 1.1;
}

.workflow-step p {
    color: var(--muted);
    line-height: 1.45;
}

.workflow-step dl {
    display: grid;
    gap: 8px;
    margin: 18px 0 0;
}

.workflow-step div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

dt,
dd {
    margin: 0;
    font-size: 12px;
}

dt {
    color: var(--muted);
}

dd {
    text-align: right;
    font-weight: 800;
}

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

.team-member {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 14px;
    min-height: 142px;
    padding: 16px;
}

.avatar {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 999px;
    background: var(--blue);
    color: var(--paper);
    font-weight: 900;
}

.team-member p {
    margin: 6px 0 0;
    color: var(--muted);
}

.team-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.team-metrics span {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 8px;
    background: rgba(244, 241, 222, 0.66);
    font-size: 12px;
}

.empty {
    margin: 0;
    color: var(--muted);
}

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

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.16);
    }
}

@media (max-width: 1180px) {
    body {
        background: var(--paper);
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .dispatch-rail {
        position: static;
        min-height: auto;
        padding: 16px;
    }

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

    .rail-map,
    .rail-note {
        display: none;
    }

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

    .mobile-mirror {
        grid-column: auto;
        grid-row: auto;
    }

    .phone {
        min-height: 420px;
    }
}

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

    .topbar {
        gap: 14px;
    }

    h1 {
        font-size: 34px;
    }

    h2 {
        font-size: 26px;
    }

    .searchbar,
    .route-line,
    .finance-strip,
    .workflow-grid,
    .team-grid {
        grid-template-columns: 1fr;
    }

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

    .case-board,
    .queue-panel {
        padding: 14px;
    }

    .case-head,
    .section-title {
        display: grid;
        gap: 10px;
    }

    .history-item {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    #caseSelect {
        width: 100%;
        max-width: none;
    }

    .route-stop {
        min-height: 112px;
    }

    .route-stop::before {
        top: auto;
        right: auto;
        bottom: -11px;
        left: 24px;
        width: 2px;
        height: 20px;
    }
}

