:root {
    color-scheme: light;
    --bg: #f6f7f4;
    --surface: #ffffff;
    --surface-soft: #edf7f4;
    --ink: #172026;
    --muted: #64707a;
    --line: #d8dfdf;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --accent: #b7791f;
    --danger: #b42318;
    --warning: #a15c07;
    --success: #237347;
    --shadow: 0 12px 40px rgba(23, 32, 38, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 72px;
    padding: 0 32px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--muted);
    font-weight: 700;
}

.nav-actions form {
    margin: 0;
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 700;
}

.page-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 64px;
}

.workspace-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.split-header {
    align-items: center;
}

.workspace-header h1,
.auth-copy h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1.1;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.upload-panel,
.summary-band,
.progress-panel,
.chat-section,
.question-section,
.finding-section,
.position-section,
.job-section,
.auth-form {
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.upload-panel,
.summary-band,
.progress-panel,
.chat-section,
.question-section,
.finding-section,
.position-section {
    margin-bottom: 24px;
}

.upload-form {
    display: grid;
    gap: 18px;
}

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

label,
.form-grid label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-weight: 700;
}

.full-field {
    grid-column: 1 / -1;
}

.field {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}

.field:focus {
    outline: 3px solid rgba(15, 118, 110, 0.18);
    border-color: var(--primary);
}

.file-field {
    padding: 8px;
}

.compact-field {
    min-width: 0;
}

small {
    color: var(--muted);
    font-weight: 500;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
    white-space: nowrap;
}

.primary-button {
    background: var(--primary);
    color: white;
}

.primary-button:hover {
    background: var(--primary-dark);
}

.secondary-button,
.small-button {
    background: white;
    color: var(--ink);
    border-color: var(--line);
}

.danger-button {
    background: white;
    color: var(--danger);
    border-color: #fac5bd;
}

.danger-button:hover {
    background: #fff0ed;
}

.small-button {
    min-height: 36px;
    padding: 8px 12px;
}

.document-list {
    display: grid;
    gap: 14px;
}

.document-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.document-card h2 {
    margin: 0 0 4px;
    font-size: 19px;
}

.document-card p {
    margin: 0;
    color: var(--muted);
}

.document-meta,
.header-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 999px;
    background: #e7edf0;
    color: #334155;
    font-size: 13px;
    font-weight: 800;
}

.status-completed,
.status-succeeded {
    background: #dff3e7;
    color: var(--success);
}

.status-failed,
.status-cancelled,
.severity-critical {
    background: #fde8e6;
    color: var(--danger);
}

.status-stopped {
    background: #f1f5f9;
    color: #475569;
}

.status-needs_input,
.status-review,
.status-warning,
.severity-warning {
    background: #fff4da;
    color: var(--warning);
}

.status-analyzing,
.status-running,
.status-queued,
.status-pending,
.status-uploaded,
.status-extracting {
    background: var(--surface-soft);
    color: var(--primary-dark);
}

.empty-state {
    padding: 28px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.68);
    text-align: center;
}

.empty-state h2,
.summary-band h2,
.progress-panel h2,
.chat-section h2,
.question-section h2,
.finding-section h2,
.position-section h2,
.job-section h2 {
    margin: 0 0 12px;
    font-size: 21px;
}

.empty-state p,
.summary-band p,
.finding-item p,
.question-item p {
    margin: 0;
    color: var(--muted);
}

.question-section,
.finding-section {
    display: grid;
    gap: 14px;
}

.question-item,
.finding-item {
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.recommendation {
    padding: 10px 12px;
    background: var(--surface-soft);
    border-radius: 8px;
}

.hidden {
    display: none;
}

.header-subline {
    margin: 10px 0 0;
    color: var(--muted);
    font-weight: 700;
}

.progress-panel {
    display: grid;
    gap: 12px;
}

.progress-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.progress-heading h2,
.progress-panel p {
    margin: 0;
}

.progress-track {
    width: 100%;
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #e7edf0;
}

.progress-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transition: width 0.3s ease;
}

.chat-section {
    display: grid;
    gap: 16px;
    margin-bottom: 24px;
}

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

.chat-message {
    max-width: min(760px, 100%);
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
}

.chat-message p {
    margin: 6px 0 0;
    color: var(--ink);
}

.chat-user {
    justify-self: end;
    background: var(--surface-soft);
}

.chat-assistant,
.chat-system {
    justify-self: start;
}

.chat-form {
    display: grid;
    gap: 10px;
}

.chat-input {
    resize: vertical;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-heading span {
    color: var(--muted);
    font-weight: 800;
}

.position-table {
    display: grid;
    gap: 1px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.position-row {
    display: grid;
    grid-template-columns: minmax(110px, 0.9fr) minmax(260px, 2fr) minmax(160px, 1.1fr) minmax(110px, 0.8fr) minmax(110px, 0.8fr) minmax(180px, 1.2fr);
    gap: 12px;
    align-items: start;
    min-width: 980px;
    padding: 12px;
    background: white;
}

.position-head {
    background: #eef2f0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

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

.inline-fields {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) minmax(60px, 0.6fr);
    gap: 8px;
}

.row-actions {
    display: grid;
    gap: 8px;
}

.check-label {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 8px;
    color: var(--ink);
}

.note-field {
    min-height: 66px;
    resize: vertical;
}

.job-list {
    display: grid;
    gap: 8px;
}

.job-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

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

.auth-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 44px;
    align-items: center;
    min-height: calc(100vh - 180px);
}

.auth-copy p:last-child {
    max-width: 560px;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 16px;
}

.auth-form input {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.form-errors,
.errorlist {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fde8e6;
    color: var(--danger);
}

.message-stack {
    width: min(1180px, calc(100% - 32px));
    margin: 18px auto 0;
    display: grid;
    gap: 10px;
}

.message {
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: white;
    font-weight: 700;
}

.message.success {
    border-color: #b9e4c8;
    background: #eaf8ef;
}

.message.error {
    border-color: #fac5bd;
    background: #fff0ed;
}

@media (max-width: 780px) {
    .topbar,
    .workspace-header,
    .document-card,
    .auth-layout {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar {
        padding: 16px;
    }

    .nav-actions,
    .document-meta,
    .header-actions {
        justify-content: flex-start;
    }

    .workspace-header,
    .auth-layout {
        display: grid;
        gap: 18px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .workspace-header h1,
    .auth-copy h1 {
        font-size: 30px;
    }

    .upload-panel,
    .summary-band,
    .progress-panel,
    .chat-section,
    .question-section,
    .finding-section,
    .position-section,
    .job-section,
    .auth-form {
        padding: 18px;
    }

    .job-item {
        grid-template-columns: 1fr;
    }
}
