:root {
    --ink: #0d1b2a;
    --paper: #f5ebe0;
    --steel: #778da9;
    --brass: #e0a458;
    --line: rgba(13, 27, 42, 0.18);
    --muted: rgba(13, 27, 42, 0.62);
    --danger: #b4473f;
    --ready: #327568;
    --white: #fffaf4;
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background:
        linear-gradient(90deg, rgba(13, 27, 42, 0.05) 1px, transparent 1px),
        linear-gradient(rgba(13, 27, 42, 0.04) 1px, transparent 1px),
        var(--paper);
    background-size: 22px 22px;
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.metrics-spine {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 20px;
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 9px),
        var(--ink);
    color: var(--paper);
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: inset -1px 0 rgba(255, 255, 255, 0.12);
}

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

.brand strong,
h1,
h2,
h3 {
    letter-spacing: 0;
}

.brand strong {
    display: block;
    font-size: 20px;
    line-height: 1;
    text-transform: uppercase;
}

.brand small {
    color: rgba(245, 235, 224, 0.68);
}

.mono,
.eyebrow {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    text-transform: uppercase;
    letter-spacing: 0;
    font-size: 11px;
}

.spine-gauge {
    border-top: 1px solid rgba(245, 235, 224, 0.2);
    border-bottom: 1px solid rgba(245, 235, 224, 0.2);
    padding: 22px 0;
}

.spine-gauge strong {
    display: block;
    font-size: clamp(48px, 8vw, 76px);
    line-height: 0.95;
    margin: 8px 0 16px;
    color: var(--brass);
}

.gauge-track,
.meter {
    display: block;
    height: 8px;
    border: 1px solid currentColor;
    background: rgba(255, 255, 255, 0.1);
}

.gauge-track i,
.meter i {
    display: block;
    height: 100%;
    width: 40%;
    background: var(--brass);
    transition: width 260ms ease;
}

.spine-metrics {
    display: grid;
    gap: 12px;
    margin: 0;
}

.spine-metrics div {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(245, 235, 224, 0.14);
}

.spine-metrics dt {
    color: rgba(245, 235, 224, 0.68);
}

.spine-metrics dd {
    margin: 0;
    font-weight: 800;
    font-size: 22px;
}

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

.screen-tab,
.icon-button,
.primary-button {
    border: 1px solid currentColor;
    min-height: 40px;
    border-radius: 4px;
    transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.screen-tab {
    background: transparent;
    color: var(--paper);
    text-align: left;
    padding: 10px 12px;
}

.screen-tab.is-active,
.screen-tab:hover {
    background: var(--brass);
    color: var(--ink);
    transform: translateX(3px);
}

.source-box {
    margin-top: auto;
    border: 1px solid rgba(245, 235, 224, 0.22);
    padding: 12px;
}

.source-box strong {
    display: block;
    margin-top: 5px;
    color: var(--brass);
}

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

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding-bottom: 18px;
    border-bottom: 2px solid var(--ink);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--muted);
}

h1 {
    margin: 0;
    font-size: clamp(30px, 4vw, 52px);
    line-height: 0.96;
    text-transform: uppercase;
}

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

.toolbar,
.quick-create {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-wrap input,
.quick-create input,
.quick-create select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--ink);
    border-radius: 4px;
    padding: 8px 10px;
    background: var(--white);
    color: var(--ink);
}

.search-wrap input {
    min-width: min(360px, 42vw);
}

.icon-button {
    width: 42px;
    background: var(--ink);
    color: var(--paper);
    font-size: 20px;
}

.primary-button {
    background: var(--brass);
    color: var(--ink);
    padding: 0 16px;
    font-weight: 800;
}

.icon-button:hover,
.primary-button:hover {
    transform: translateY(-1px);
}

.quick-create {
    margin: 18px 0;
    padding: 12px;
    border: 2px solid var(--ink);
    background:
        linear-gradient(90deg, rgba(224, 164, 88, 0.18), transparent 54%),
        var(--white);
    display: grid;
    grid-template-columns: 190px 220px minmax(220px, 1fr) auto;
}

.quick-create h2 {
    margin: 2px 0 0;
    font-size: 18px;
}

.quick-create label {
    display: grid;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}

.screen {
    display: none;
    animation: panelIn 220ms ease both;
}

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

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

.board-header,
.section-line {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    margin-bottom: 12px;
}

.board-header h2,
.section-line h2,
.report-grid h3 {
    margin: 0;
    text-transform: uppercase;
    font-size: 18px;
}

.board-header p {
    margin: 5px 0 0;
    color: var(--muted);
}

.kanban-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.lane {
    min-width: 180px;
    border: 1px solid var(--line);
    background: rgba(255, 250, 244, 0.68);
}

.lane-head {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid var(--line);
    background: rgba(119, 141, 169, 0.16);
}

.lane-head h3 {
    margin: 0;
}

.lane-head span {
    font-weight: 800;
}

.lane-items {
    display: grid;
    gap: 8px;
    padding: 8px;
}

.case-card {
    width: 100%;
    min-height: 150px;
    text-align: left;
    border: 1px solid var(--ink);
    border-left-width: 6px;
    border-radius: 4px;
    background: var(--white);
    color: var(--ink);
    padding: 12px;
    display: grid;
    gap: 8px;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.case-card:hover,
.case-card.is-active {
    transform: translateY(-2px);
    box-shadow: 0 10px 0 rgba(13, 27, 42, 0.12);
}

.case-card.is-active {
    background: #fff3d8;
}

.case-card strong {
    font-size: 16px;
    line-height: 1.12;
}

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

.risk-clear {
    border-left-color: var(--ready);
}

.risk-watch {
    border-left-color: var(--brass);
}

.risk-late {
    border-left-color: var(--danger);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    margin-top: auto;
}

.card-footer b {
    font-size: 12px;
}

.case-bottom,
.details-layout,
.report-grid {
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(420px, 1.1fr);
    gap: 14px;
    margin-top: 14px;
}

.active-panel,
.activity-panel,
.maintenance-panel,
.report-grid > section {
    border: 2px solid var(--ink);
    background: var(--white);
    padding: 16px;
}

.active-panel h2 {
    font-size: clamp(22px, 3vw, 34px);
    line-height: 1;
    margin: 8px 0;
}

.active-panel p {
    color: var(--muted);
}

dl {
    margin: 0;
}

#selectedFacts,
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

#selectedFacts div,
.detail-grid article {
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

dt,
.detail-grid span {
    color: var(--muted);
    font-size: 12px;
}

dd {
    margin: 2px 0 0;
    font-weight: 800;
}

.timeline {
    display: grid;
    gap: 10px;
    max-height: 360px;
    overflow: auto;
}

.timeline-row {
    display: grid;
    grid-template-columns: 18px 1fr;
    gap: 10px;
    align-items: start;
}

.timeline-dot {
    width: 10px;
    height: 10px;
    margin-top: 5px;
    border: 2px solid var(--ink);
    background: var(--brass);
}

.timeline-row strong {
    display: block;
    line-height: 1.25;
}

.timeline-row small,
.workflow-row small,
.meter-row small,
.calendar-slot small {
    display: block;
    color: var(--muted);
}

.detail-panel {
    min-height: 300px;
}

.detail-grid {
    margin-top: 16px;
}

.detail-grid article strong {
    display: block;
    margin-top: 4px;
}

.toggle-list {
    display: grid;
    gap: 12px;
}

.toggle-list label {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    padding: 10px;
    font-weight: 800;
}

.toggle-list input {
    width: 22px;
    height: 22px;
    accent-color: var(--brass);
}

.calendar-grid {
    display: grid;
    gap: 10px;
}

.calendar-slot {
    display: grid;
    grid-template-columns: 86px 1fr 94px;
    gap: 12px;
    align-items: center;
    min-height: 74px;
    border: 1px solid var(--ink);
    background: var(--white);
    padding: 12px;
}

.calendar-slot time {
    font-size: 28px;
    font-weight: 900;
}

.calendar-slot > span {
    justify-self: end;
    border: 1px solid currentColor;
    padding: 5px 8px;
    font-size: 12px;
}

.status-late {
    box-shadow: inset 5px 0 var(--danger);
}

.status-ready {
    box-shadow: inset 5px 0 var(--ready);
}

.status-due,
.status-queued {
    box-shadow: inset 5px 0 var(--brass);
}

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

.report-grid h3 {
    margin-bottom: 12px;
}

.meter-row,
.workflow-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px 42px;
    gap: 10px;
    align-items: center;
    border-top: 1px solid var(--line);
    padding: 10px 0;
}

.workflow-row {
    grid-template-columns: minmax(0, 1fr) 42px;
}

.workflow-row small {
    grid-column: 1 / -1;
}

.meter {
    color: var(--ink);
}

.error-state {
    border: 2px solid var(--danger);
    background: var(--white);
    padding: 14px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

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

    .metrics-spine {
        position: static;
        height: auto;
        display: grid;
        grid-template-columns: 1fr;
    }

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

    .topbar,
    .toolbar,
    .quick-create,
    .case-bottom,
    .details-layout,
    .report-grid {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .search-wrap input {
        min-width: 0;
    }
}

@media (max-width: 620px) {
    .workspace,
    .metrics-spine {
        padding: 16px;
    }

    .quick-create,
    .active-panel,
    .activity-panel,
    .maintenance-panel,
    .report-grid > section {
        padding: 12px;
    }

    .kanban-board {
        grid-template-columns: repeat(4, 78vw);
    }

    #selectedFacts,
    .detail-grid,
    .calendar-slot,
    .meter-row {
        grid-template-columns: 1fr;
    }

    .calendar-slot > span {
        justify-self: start;
    }
}
