@layer reset, tokens, base, layout, components;

@layer reset {
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    body {
        margin: 0;
    }

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

@layer tokens {
    :root {
        color-scheme: light dark;

        /* Palette rule: layout/background neutrals use zero chroma. */
        --bg: oklch(98.5% 0 0);
        --bg-raised: oklch(96% 0 0);
        --bg-subtle: oklch(93% 0 0);
        --line: oklch(82% 0 0);
        --line-strong: oklch(70% 0 0);

        /* Text is near-neutral warm: OKLCH C is kept around 0.01, roughly a 5% saturation intent. */
        --text: oklch(30% 0.012 75);
        --text-strong: oklch(22% 0.012 75);
        --text-muted: oklch(50% 0.01 75);
        --text-faint: oklch(62% 0.008 75);
        --code: oklch(34% 0.012 75);

        --accent: oklch(54% 0.13 230);
        --accent-muted: oklch(54% 0.08 230);
        --success: oklch(48% 0.11 145);
        --warning: oklch(62% 0.12 85);
        --danger: oklch(54% 0.14 25);

        --space-1: 4px;
        --space-2: 8px;
        --space-3: 12px;
        --space-4: 16px;
        --space-5: 24px;
        --space-6: 32px;

        --radius-soft: 8px;
        --radius-panel: 12px;
        --font-sans:
            Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
            "Segoe UI", sans-serif;
        --font-mono:
            ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
            "Liberation Mono", monospace;
    }

    @media (prefers-color-scheme: dark) {
        :root {
            --bg: oklch(16% 0 0);
            --bg-raised: oklch(21% 0 0);
            --bg-subtle: oklch(26% 0 0);
            --line: oklch(36% 0 0);
            --line-strong: oklch(48% 0 0);

            --text: oklch(87% 0.012 75);
            --text-strong: oklch(95% 0.01 75);
            --text-muted: oklch(70% 0.01 75);
            --text-faint: oklch(58% 0.008 75);
            --code: oklch(84% 0.012 75);

            --accent: oklch(76% 0.12 230);
            --accent-muted: oklch(71% 0.08 230);
            --success: oklch(77% 0.12 145);
            --warning: oklch(82% 0.13 85);
            --danger: oklch(76% 0.14 25);
        }
    }
}

@layer base {
    body {
        background: var(--bg);
        color: var(--text);
        font-family: var(--font-sans);
    }

    a {
        color: var(--accent);
    }

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

    h1,
    h2,
    h3 {
        color: var(--text-strong);
        margin-top: 0;
    }

    p {
        line-height: 1.55;
    }

    code,
    pre {
        font-family: var(--font-mono);
    }

    code {
        color: var(--code);
    }

    small {
        color: var(--text-muted);
        display: block;
        margin-top: var(--space-1);
    }
}

@layer layout {
    .workspace-layout {
        display: grid;
        grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
        width: 100vw;
        height: 100dvh;
        margin: 0;
        padding: 0;
        overflow: hidden;
        min-width: 0;
    }

    .shell {
        display: grid;
        gap: var(--space-6);
        min-width: 0;
        min-height: 0;
        overflow-y: auto;
        padding: var(--space-6);
    }

    .grid {
        display: grid;
        gap: var(--space-5);
        grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
        min-width: 0;
    }

    .runtime {
        grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
    }

    .stack {
        display: grid;
        gap: var(--space-4);
    }

    @media (max-width: 760px) {
        .workspace-layout {
            grid-template-columns: 1fr;
            width: 100vw;
            height: auto;
            min-height: 100dvh;
            overflow: visible;
        }

        .shell {
            overflow: visible;
            padding: var(--space-5) var(--space-4);
        }
    }
}

@layer components {
    .workspace-sidebar {
        align-self: stretch;
        min-width: 0;
        min-height: 0;
        overflow-y: auto;
        padding: var(--space-6) var(--space-5);
    }

    .sidebar-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: var(--space-4);
        margin-bottom: var(--space-6);
        min-width: 0;
    }

    .workspace-label {
        display: grid;
        gap: var(--space-1);
        min-width: 0;
    }

    .workspace-sidebar h1 {
        margin: 0;
        font-size: 1.05rem;
        line-height: 1.25;
    }

    .workspace-status {
        margin: 0;
        color: var(--text-muted);
        font-size: 0.78rem;
        line-height: 1.35;
    }

    .workspace-status.error,
    .section-state.error,
    .error {
        color: var(--danger);
    }

    .settings-button {
        flex: 0 0 auto;
        display: grid;
        place-items: center;
        width: 32px;
        height: 32px;
        border: 0;
        border-radius: var(--radius-soft);
        background: var(--bg-subtle);
        color: var(--text-muted);
        cursor: not-allowed;
    }

    .sidebar-sections {
        display: grid;
        gap: var(--space-5);
        min-width: 0;
    }

    .nav-section {
        display: grid;
        gap: var(--space-2);
    }

    .section-heading-row,
    .section-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
    }

    .section-heading-row h2,
    .section-header,
    .eyebrow {
        color: var(--text-faint);
        font-size: 0.72rem;
        font-weight: 750;
        letter-spacing: 0.11em;
        text-transform: uppercase;
    }

    .section-heading-row h2 {
        margin: 0;
    }

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

    .section-count {
        color: var(--text-muted);
        font-size: 0.72rem;
        line-height: 1;
    }

    .nav-list {
        display: grid;
        gap: var(--space-1);
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .nav-item,
    .objective-link {
        display: grid;
        gap: 3px;
        min-width: 0;
        padding: var(--space-2) 0 var(--space-2) var(--space-3);
        border-left: 2px solid transparent;
        color: inherit;
        text-align: left;
        text-decoration: none;
    }

    .nav-item.active,
    .objective-link.active,
    .nav-item:hover,
    .objective-link:hover {
        border-left-color: var(--accent);
    }

    .item-title,
    .item-meta {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .item-title {
        color: var(--text-strong);
        font-weight: 650;
    }

    .item-meta,
    .section-note,
    .section-state,
    .muted {
        color: var(--text-muted);
        font-size: 0.82rem;
    }

    .section-note,
    .section-state {
        margin: 0;
        line-height: 1.45;
    }

    .card {
        min-width: 0;
        padding: var(--space-5) 0 0;
        border-top: 1px solid var(--line);
    }

    .card:first-child {
        padding-top: 0;
        border-top: 0;
    }

    .runtime-card {
        padding: var(--space-4) 0 0;
        border-top: 1px solid var(--line);
    }

    .selected-card.selected {
        border-top-color: var(--accent);
    }

    .runtime-heading,
    .detail-heading {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: var(--space-3);
        margin-bottom: var(--space-3);
    }

    .runtime-heading span {
        color: var(--success);
    }

    .runtime-heading span.warn {
        color: var(--warning);
    }

    .detail-heading h3 {
        margin: 0;
    }

    .detail-heading span {
        color: var(--text-muted);
        font-size: 0.8rem;
    }

    dl {
        display: grid;
        gap: var(--space-3);
    }

    dt {
        color: var(--text-faint);
        font-size: 0.78rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    dd {
        margin: 0;
    }

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

    table {
        width: 100%;
        border-collapse: collapse;
    }

    th,
    td {
        border-bottom: 1px solid var(--line);
        padding: 10px 8px;
        text-align: left;
        vertical-align: top;
    }

    th {
        color: var(--text-faint);
        font-size: 0.78rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .diagnostics {
        margin-top: var(--space-4);
    }

    .diagnostics li {
        display: grid;
        gap: var(--space-1);
        margin-bottom: var(--space-3);
    }

    .record-body {
        overflow-x: auto;
        padding: var(--space-4) 0 0;
        border-top: 1px solid var(--line);
        color: var(--text);
        white-space: pre-wrap;
    }
}
