:root {
    --ink: #1a1a2e;
    --paper: #f2e9e4;
    --muted: #9a8c98;
    --clay: #c9ada7;
    --field: #526a4f;
    --amber: #b87936;
    --line: rgba(26, 26, 46, 0.18);
    --shadow: 0 18px 44px rgba(26, 26, 46, 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(26, 26, 46, 0.06) 1px, transparent 1px),
        linear-gradient(0deg, rgba(26, 26, 46, 0.045) 1px, transparent 1px),
        var(--paper);
    background-size: 34px 34px;
    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: 208px minmax(0, 1fr) 334px;
    min-height: 100vh;
}

.left-rail,
.inspection {
    background: rgba(242, 233, 228, 0.92);
    backdrop-filter: blur(12px);
}

.left-rail {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-right: 2px solid var(--ink);
    padding: 18px;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--ink);
    text-decoration: none;
    font-weight: 850;
    line-height: 0.95;
    letter-spacing: 0;
}

.brand img {
    width: 44px;
    height: 44px;
    box-shadow: 5px 5px 0 var(--clay);
}

.rail-nav {
    display: grid;
    gap: 8px;
    margin-top: 38px;
}

.nav-item,
.segment,
.drawer-actions button,
.primary-action {
    border: 2px solid var(--ink);
    background: transparent;
    color: var(--ink);
    min-height: 42px;
    padding: 9px 12px;
    text-align: left;
    transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.nav-item:hover,
.segment:hover,
.drawer-actions button:hover:not(:disabled),
.primary-action:hover {
    transform: translate(-2px, -2px);
    box-shadow: 4px 4px 0 var(--ink);
}

.nav-item.active,
.segment.active,
.primary-action {
    background: var(--ink);
    color: var(--paper);
}

.rail-footer {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 13px;
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: var(--field);
    border: 2px solid var(--ink);
    animation: pulse 1.8s ease-in-out infinite;
}

.workbench {
    min-width: 0;
    padding: 26px clamp(18px, 4vw, 44px) 48px;
}

.topbar,
.canvas-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

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

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

h2 {
    margin-bottom: 8px;
    font-size: clamp(22px, 2.6vw, 34px);
    line-height: 1.05;
    letter-spacing: 0;
}

.topbar-actions {
    display: flex;
    align-items: end;
    gap: 10px;
}

.search-box {
    display: grid;
    gap: 6px;
    min-width: min(300px, 42vw);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.search-box input {
    width: 100%;
    border: 2px solid var(--ink);
    background: #fffaf7;
    color: var(--ink);
    min-height: 42px;
    padding: 8px 11px;
    outline: none;
}

.search-box input:focus {
    box-shadow: 4px 4px 0 var(--clay);
}

.metric-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 2px solid var(--ink);
    margin: 26px 0;
    background: #fffaf7;
    box-shadow: var(--shadow);
}

.metric {
    min-width: 0;
    padding: 18px;
    border-right: 2px solid var(--ink);
}

.metric:last-child {
    border-right: 0;
}

.metric-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    font-size: clamp(28px, 4vw, 52px);
    line-height: 0.95;
}

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

.screen.active {
    display: block;
}

.canvas-head p {
    max-width: 720px;
    color: #554c57;
}

.segmented {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.segment {
    min-height: 38px;
    text-align: center;
    white-space: nowrap;
}

.queue-table {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.queue-row {
    display: grid;
    grid-template-columns: minmax(180px, 1.25fr) minmax(150px, 0.8fr) minmax(150px, 0.7fr) 112px;
    align-items: center;
    gap: 12px;
    width: 100%;
    border: 2px solid var(--ink);
    background: rgba(255, 250, 247, 0.9);
    color: var(--ink);
    padding: 14px;
    text-align: left;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.queue-row:hover,
.queue-row.selected {
    transform: translate(-3px, -3px);
    box-shadow: 6px 6px 0 var(--ink);
}

.queue-row.selected {
    background: #f7d7c9;
}

.row-main,
.crop-block,
.money-block {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.queue-row b,
.queue-row small {
    overflow-wrap: anywhere;
}

.queue-row small {
    color: #5d5360;
}

.risk {
    justify-self: end;
    min-width: 92px;
    border: 2px solid var(--ink);
    padding: 7px 8px;
    text-align: center;
    font-weight: 850;
}

.risk.high {
    background: #f0aa7a;
}

.risk.medium {
    background: #f0d27a;
}

.risk.low {
    background: #d7e2bb;
}

.inspection {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-left: 2px solid var(--ink);
}

.drawer-top {
    padding: 22px;
    border-bottom: 2px solid var(--ink);
}

.drawer-top h2 {
    margin-bottom: 0;
}

.drawer-body {
    display: grid;
    gap: 10px;
    padding: 18px 22px;
    overflow: auto;
}

.drawer-fact {
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}

.drawer-fact span,
.drawer-fact b {
    display: block;
}

.drawer-fact span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
}

.drawer-fact b {
    margin-top: 4px;
    overflow-wrap: anywhere;
}

.drawer-note {
    margin-top: 8px;
    border: 2px solid var(--ink);
    background: #fffaf7;
    padding: 13px;
    line-height: 1.45;
}

.drawer-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: auto;
    padding: 18px 22px 22px;
    border-top: 2px solid var(--ink);
}

.drawer-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.timeline {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.timeline-item {
    display: grid;
    grid-template-columns: 168px 150px minmax(0, 1fr);
    gap: 12px;
    border-top: 2px solid var(--ink);
    padding: 14px 0;
}

.timeline-item time {
    color: var(--muted);
    font-size: 13px;
}

.timeline-item span {
    overflow-wrap: anywhere;
}

.workflow-grid,
.team-board {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.rule-row,
.team-board div {
    display: grid;
    grid-template-columns: 180px 190px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    border-top: 2px solid var(--ink);
    padding: 16px 0;
}

.rule-row span,
.team-board b {
    font-weight: 850;
}

.rule-row strong {
    color: var(--amber);
}

.rule-row em,
.team-board span,
.muted {
    color: #5c5360;
    font-style: normal;
    line-height: 1.45;
}

.team-board div {
    grid-template-columns: 180px minmax(0, 1fr);
}

.empty-state {
    border: 2px dashed var(--ink);
    padding: 22px;
    color: #5c5360;
    background: rgba(255, 250, 247, 0.72);
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 20;
    max-width: min(420px, calc(100vw - 36px));
    border: 2px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    padding: 12px 14px;
    box-shadow: 6px 6px 0 var(--clay);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

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

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

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

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

    .inspection {
        position: static;
        grid-column: 1 / -1;
        height: auto;
        border-left: 0;
        border-top: 2px solid var(--ink);
    }

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

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .left-rail {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 2px solid var(--ink);
    }

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

    .rail-footer {
        margin-top: 18px;
    }

    .topbar,
    .canvas-head,
    .topbar-actions {
        display: grid;
        align-items: stretch;
    }

    .search-box {
        min-width: 0;
    }

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

    .metric:nth-child(2) {
        border-right: 0;
    }

    .metric:nth-child(1),
    .metric:nth-child(2) {
        border-bottom: 2px solid var(--ink);
    }

    .queue-row,
    .timeline-item,
    .rule-row,
    .team-board div {
        grid-template-columns: 1fr;
    }

    .risk {
        justify-self: start;
    }
}

@media (max-width: 520px) {
    .workbench {
        padding: 20px 14px 34px;
    }

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

    .metric {
        border-right: 0;
        border-bottom: 2px solid var(--ink);
    }

    .metric:last-child {
        border-bottom: 0;
    }

    .drawer-actions {
        grid-template-columns: 1fr;
    }
}
