:root {
    --ink: #1f2933;
    --paper: #fbfbf2;
    --blue: #4c6fff;
    --orange: #f9703e;
    --line: rgba(31, 41, 51, .16);
    --muted: rgba(31, 41, 51, .62);
    --panel: #ffffff;
    --shadow: 0 24px 80px rgba(31, 41, 51, .14);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        linear-gradient(90deg, rgba(76, 111, 255, .08) 1px, transparent 1px),
        linear-gradient(rgba(31, 41, 51, .07) 1px, transparent 1px),
        var(--paper);
    background-size: 42px 42px;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.rail {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px;
    background: var(--ink);
    color: var(--paper);
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.brand {
    color: inherit;
    text-decoration: none;
    display: grid;
    grid-template-columns: 46px 1fr;
    align-items: center;
    gap: 12px;
}

.brand strong {
    display: block;
    font-size: 20px;
    line-height: 1.05;
}

.brand small,
.mono {
    color: currentColor;
    opacity: .68;
    font-size: 11px;
    line-height: 1.3;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

.tab {
    border: 1px solid rgba(251, 251, 242, .16);
    background: transparent;
    color: var(--paper);
    min-height: 42px;
    padding: 0 12px;
    text-align: left;
    border-radius: 8px;
    transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.tab:hover,
.tab.is-active {
    background: rgba(251, 251, 242, .1);
    border-color: rgba(251, 251, 242, .44);
    transform: translateX(2px);
}

.rail-graph {
    display: grid;
    grid-template-columns: 22px 1fr 22px 1fr 22px;
    align-items: center;
    margin-top: auto;
}

.rail-graph span {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--paper);
}

.rail-graph span:first-child {
    background: var(--blue);
}

.rail-graph span:last-child {
    background: var(--orange);
}

.rail-graph i {
    height: 2px;
    background: rgba(251, 251, 242, .5);
}

.rail-status {
    border-top: 1px solid rgba(251, 251, 242, .18);
    padding-top: 16px;
}

.rail-status strong {
    display: block;
    margin-top: 6px;
    word-break: break-word;
}

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

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.eyebrow {
    margin: 0 0 7px;
    color: var(--muted);
    font-size: 13px;
}

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

h1 {
    margin-bottom: 0;
    font-size: clamp(32px, 5vw, 68px);
    line-height: .94;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 7px;
    font-size: 20px;
    line-height: 1.15;
    letter-spacing: 0;
}

.toolbar,
.filters,
.dialog-actions,
.inline-fields {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.icon-button {
    border: 0;
    border-radius: 8px;
    min-height: 42px;
    padding: 0 14px;
    background: var(--blue);
    color: white;
    box-shadow: 0 12px 28px rgba(76, 111, 255, .26);
    transition: transform .18s ease, box-shadow .18s ease;
}

.primary-button:hover,
.ghost-button:hover,
.icon-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 34px rgba(31, 41, 51, .2);
}

.icon-button {
    width: 42px;
    padding: 0;
    background: var(--ink);
}

.ghost-button {
    width: 100%;
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
    box-shadow: none;
}

.summary-row {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    margin-bottom: 18px;
    background: var(--ink);
    border: 1px solid var(--ink);
    box-shadow: var(--shadow);
}

.metric {
    min-height: 112px;
    padding: 16px;
    background: var(--paper);
}

.metric strong {
    display: block;
    margin: 7px 0 3px;
    font-size: clamp(30px, 4vw, 58px);
    line-height: .9;
    letter-spacing: 0;
}

.metric small {
    color: var(--muted);
}

.metric-load {
    background: #eef1ff;
}

.metric-hot {
    background: #fff0e9;
}

.view {
    display: none;
}

.view.is-visible {
    display: block;
    animation: rise .22s ease-out both;
}

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

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

.flow-node {
    position: relative;
    min-height: 122px;
    overflow: hidden;
    padding: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .72);
}

.flow-node strong,
.flow-node small {
    position: relative;
    z-index: 1;
    display: block;
}

.flow-node small {
    margin-top: 8px;
    color: var(--muted);
}

.spark {
    position: absolute;
    inset: auto 0 0 0;
    height: var(--heat);
    background: linear-gradient(180deg, rgba(76, 111, 255, .1), rgba(249, 112, 62, .28));
    transition: height .28s ease;
}

.work-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    align-items: start;
}

.table-zone,
.inspector,
.timeline-zone,
.create-panel,
.doc-list,
.finance-list {
    background: rgba(255, 255, 255, .78);
    border: 1px solid var(--line);
}

.table-zone,
.timeline-zone,
.create-panel {
    padding: 18px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.section-head p {
    margin-bottom: 0;
    color: var(--muted);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    min-height: 40px;
    padding: 9px 11px;
}

textarea {
    resize: vertical;
}

.filters input {
    width: min(320px, 100%);
}

.filters select {
    width: 170px;
}

.case-table {
    overflow-x: auto;
}

.case-row {
    width: 100%;
    min-width: 840px;
    display: grid;
    grid-template-columns: 150px minmax(240px, 1.4fr) 120px 130px 150px 110px;
    align-items: center;
    gap: 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    padding: 12px 8px;
    text-align: left;
}

.case-row:not(.case-row-head):hover,
.case-row.is-selected {
    background: rgba(76, 111, 255, .08);
}

.case-row-head {
    position: sticky;
    top: 0;
    z-index: 1;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
    background: #fff;
}

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

.case-row small {
    margin-top: 3px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.stage,
.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 0 9px;
    background: #eef1ff;
    color: var(--blue);
    font-style: normal;
}

.heat {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 7px;
    border-radius: 50%;
    background: #99a3ad;
    box-shadow: 0 0 0 4px rgba(153, 163, 173, .16);
}

.heat-critical {
    background: var(--orange);
    box-shadow: 0 0 0 4px rgba(249, 112, 62, .18);
}

.heat-high {
    background: #e0b000;
    box-shadow: 0 0 0 4px rgba(224, 176, 0, .16);
}

.heat-medium {
    background: var(--blue);
    box-shadow: 0 0 0 4px rgba(76, 111, 255, .14);
}

.inspector {
    position: sticky;
    top: 138px;
    padding: 18px;
}

.inspector h2 {
    font-size: 25px;
}

.inspector p {
    color: var(--muted);
    line-height: 1.5;
}

dl {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 10px;
    margin: 18px 0;
}

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

dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.timeline-zone {
    margin-top: 18px;
}

.timeline {
    display: grid;
    gap: 10px;
}

.event {
    display: grid;
    grid-template-columns: 16px 1fr;
    gap: 10px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.event:first-child {
    border-top: 0;
}

.event-dot {
    width: 12px;
    height: 12px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--orange);
    box-shadow: 0 0 0 5px rgba(249, 112, 62, .14);
}

.event p,
.event small {
    margin: 4px 0 0;
    color: var(--muted);
}

.create-panel {
    max-width: 780px;
    display: grid;
    gap: 14px;
}

.create-panel label {
    display: grid;
    gap: 7px;
    color: var(--muted);
}

.create-panel label input,
.create-panel label select,
.create-panel label textarea {
    color: var(--ink);
}

.inline-fields {
    align-items: stretch;
}

.inline-fields label {
    flex: 1 1 160px;
}

.form-intro p,
.form-status {
    color: var(--muted);
}

.doc-list,
.finance-list {
    overflow: hidden;
}

.doc-row,
.finance-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 150px 140px 170px;
    gap: 14px;
    align-items: center;
    padding: 15px 18px;
    border-top: 1px solid var(--line);
}

.doc-row:first-child,
.finance-row:first-child {
    border-top: 0;
}

.doc-row small,
.finance-row small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.finance-total {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: baseline;
    padding: 18px;
    background: var(--ink);
    color: var(--paper);
}

.finance-total strong {
    font-size: 34px;
    line-height: 1;
}

.empty {
    padding: 24px;
    color: var(--muted);
}

dialog {
    width: min(520px, calc(100vw - 28px));
    border: 1px solid var(--line);
    padding: 0;
    color: var(--ink);
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgba(31, 41, 51, .42);
}

.dialog-form {
    display: grid;
    gap: 14px;
    padding: 20px;
}

.dialog-form label {
    display: grid;
    gap: 8px;
}

.dialog-actions {
    justify-content: flex-end;
}

.dialog-actions button:not(.primary-button) {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    min-height: 42px;
    padding: 0 14px;
}

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

    .rail {
        position: relative;
        height: auto;
        padding: 14px;
    }

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

    .tab {
        text-align: center;
        padding: 0 8px;
    }

    .rail-graph,
    .rail-status {
        display: none;
    }

    .workspace {
        padding: 14px;
    }

    .summary-row,
    .flow-strip,
    .work-grid {
        grid-template-columns: 1fr;
    }

    .summary-row {
        position: relative;
    }

    .inspector {
        position: relative;
        top: auto;
    }

    .topbar {
        display: grid;
    }
}

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

    .metric {
        min-height: 90px;
    }

    .section-head,
    .toolbar,
    .filters {
        display: grid;
        width: 100%;
    }

    .filters input,
    .filters select {
        width: 100%;
    }

    .doc-row,
    .finance-row {
        grid-template-columns: 1fr;
    }

    dl {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}
