:root {
    --bg: #f5f7f6;
    --surface: #ffffff;
    --surface-muted: #eef4f2;
    --surface-strong: #e4eee9;
    --ink: #16211f;
    --muted: #5f6f69;
    --line: #d8e1dd;
    --accent: #0f766e;
    --accent-dark: #0a5c56;
    --blue: #295f9e;
    --danger: #b42318;
    --warning: #9a5b00;
    --shadow: 0 24px 70px rgba(20, 35, 32, 0.12);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        linear-gradient(180deg, rgba(15, 118, 110, 0.08) 0, rgba(15, 118, 110, 0) 320px),
        var(--bg);
}

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

button {
    border: 0;
}

.app-shell {
    min-height: 100vh;
    padding: 28px;
}

.workspace {
    width: min(1480px, 100%);
    margin: 0 auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 0 28px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
    font-size: 24px;
    font-weight: 780;
}

.brand img,
.empty-state img {
    flex: 0 0 auto;
}

.top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    min-width: 0;
}

.text-link {
    color: var(--accent-dark);
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
}

.text-link:hover {
    text-decoration: underline;
}

.status-strip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.76);
    color: var(--muted);
    font-size: 14px;
    white-space: nowrap;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.13);
}

.intro {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.55fr);
    gap: 32px;
    align-items: end;
    margin-bottom: 30px;
    padding-bottom: 26px;
    border-bottom: 1px solid var(--line);
}

.compact-intro h1 {
    font-size: 46px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

h1 {
    max-width: 880px;
    margin-bottom: 0;
    font-size: 64px;
    line-height: 1;
    letter-spacing: 0;
}

.intro > p {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.65;
}

.layout,
.doctor-layout {
    display: grid;
    align-items: start;
    gap: 24px;
}

.layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.72fr);
}

.chat-layout {
    grid-template-columns: minmax(360px, 0.8fr) minmax(480px, 1.2fr);
}

.doctor-layout {
    grid-template-columns: 360px minmax(0, 1fr);
}

.intake-panel,
.report-panel,
.queue-panel,
.case-panel {
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.chat-panel {
    position: sticky;
    top: 24px;
    display: flex;
    min-height: 680px;
    flex-direction: column;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
    animation: enter 280ms ease both;
}

.intake-panel,
.report-panel,
.queue-panel,
.case-panel {
    animation: enter 280ms ease both;
}

.intake-panel {
    display: grid;
    gap: 22px;
    padding: 24px;
}

.report-panel,
.queue-panel {
    position: sticky;
    top: 24px;
}

.report-panel {
    min-height: 680px;
    padding: 24px;
}

.queue-panel {
    max-height: calc(100vh - 48px);
    overflow: auto;
    padding: 18px;
}

.case-panel {
    min-height: 680px;
    padding: 24px;
}

.section-heading,
.report-header,
.queue-header,
.case-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.section-heading {
    justify-content: flex-start;
    padding-top: 4px;
}

.section-divider {
    margin-top: 6px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

.section-heading span,
.queue-header span {
    display: grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--accent-dark);
    font-weight: 800;
}

.section-heading h2,
.report-header h2,
.queue-header h2,
.case-header h2 {
    margin: 0;
    font-size: 22px;
}

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

label,
fieldset {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    padding: 13px 14px;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.13);
}

.checks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 18px;
    margin: 0;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-muted);
}

.checks legend {
    padding: 0 8px;
    color: var(--ink);
}

.checks label,
.consent-line {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: var(--ink);
    font-weight: 650;
    line-height: 1.45;
}

.checks input,
.consent-line input {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    accent-color: var(--accent);
}

.urgent-note,
.disclaimer {
    margin: 0;
    border-radius: 8px;
    line-height: 1.55;
}

.urgent-note {
    padding: 14px 16px;
    border: 1px solid rgba(180, 35, 24, 0.26);
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
    font-weight: 760;
}

.disclaimer {
    margin-top: 18px;
    padding: 14px 16px;
    border: 1px solid rgba(154, 91, 0, 0.26);
    background: rgba(154, 91, 0, 0.08);
    color: #6f4300;
    font-size: 14px;
    font-weight: 720;
}

.primary-action,
.ghost-button {
    min-height: 48px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.primary-action {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 800;
}

.primary-action:hover,
.ghost-button:hover:not(:disabled),
.queue-item:hover {
    transform: translateY(-1px);
}

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

.primary-action:disabled {
    cursor: wait;
    opacity: 0.7;
}

.form-note {
    margin: -6px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.ghost-button {
    width: auto;
    padding: 0 16px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-weight: 760;
}

.ghost-button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.ghost-button.is-selected {
    border-color: var(--accent);
    background: var(--surface-strong);
    color: var(--accent-dark);
}

.empty-state,
.loading-state,
.error-state {
    display: grid;
    place-items: center;
    min-height: 470px;
    color: var(--muted);
    text-align: center;
}

.chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.chat-header h2 {
    margin: 0;
    font-size: 22px;
}

.chat-status {
    flex: 0 0 auto;
    padding: 7px 10px;
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 800;
}

.chat-empty {
    flex: 1;
    min-height: 440px;
}

.chat-thread {
    display: grid;
    flex: 1;
    gap: 14px;
    max-height: 450px;
    margin: 20px 0;
    padding-right: 4px;
    overflow-y: auto;
}

.chat-message {
    display: grid;
    gap: 7px;
    max-width: 88%;
    padding: 13px 15px;
    border-radius: 12px;
    line-height: 1.55;
}

.chat-message--assistant {
    justify-self: start;
    border: 1px solid var(--line);
    background: var(--surface-muted);
}

.chat-message--user {
    justify-self: end;
    background: var(--accent);
    color: #fff;
}

.chat-message__label {
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-message--assistant .chat-message__label {
    color: var(--accent-dark);
}

.chat-message p {
    margin: 0;
}

.chat-composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.chat-composer textarea {
    min-height: 54px;
}

.chat-composer .primary-action {
    min-width: 92px;
}

.chat-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.chat-loading span {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(15, 118, 110, 0.18);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 900ms linear infinite;
}

.chat-loading p,
.chat-complete {
    margin: 0;
}

.chat-complete {
    margin-top: 18px;
    padding: 14px 16px;
    border: 1px solid rgba(15, 118, 110, 0.28);
    border-radius: 8px;
    background: rgba(15, 118, 110, 0.08);
    color: var(--accent-dark);
    line-height: 1.55;
}

.required-note {
    color: var(--danger);
    font-size: 11px;
}

.field-grid > label {
    display: block;
}

.field-grid > label > input,
.field-grid > label > select {
    display: block;
    margin-top: 8px;
}

.consent-line .required-note {
    order: 1;
}

.chat-answer-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 0 1.25rem 1rem;
}

.chat-answer-options__list {
    display: flex;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.chat-answer-option.is-selected {
    border-color: var(--accent);
    background: var(--surface-strong);
    color: var(--accent-dark);
}

.chat-complete h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.chat-complete pre {
    margin: 0;
    font: inherit;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

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

.empty-state p,
.loading-state p {
    max-width: 340px;
    line-height: 1.6;
}

.loading-state span {
    width: 46px;
    height: 46px;
    border: 4px solid rgba(15, 118, 110, 0.16);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 900ms linear infinite;
}

.error-state {
    min-height: 220px;
    padding: 20px;
    border: 1px solid rgba(180, 35, 24, 0.28);
    border-radius: 8px;
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
    font-weight: 750;
}

.compact-error {
    min-height: 0;
    margin-bottom: 14px;
}

.report-meta {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.urgency-badge,
.urgency-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    border-radius: 999px;
    font-weight: 820;
    text-transform: uppercase;
}

.urgency-badge {
    min-height: 36px;
    margin-top: 14px;
    padding: 0 14px;
    background: rgba(41, 95, 158, 0.12);
    color: var(--blue);
    font-size: 12px;
}

.urgency-pill {
    min-height: 24px;
    padding: 0 9px;
    background: rgba(41, 95, 158, 0.1);
    color: var(--blue);
    font-size: 10px;
}

.urgency-badge[data-urgency="pilna"],
.urgency-pill[data-urgency="pilna"] {
    background: rgba(154, 91, 0, 0.12);
    color: var(--warning);
}

.urgency-badge[data-urgency="natychmiastowa"],
.urgency-pill[data-urgency="natychmiastowa"] {
    background: rgba(180, 35, 24, 0.12);
    color: var(--danger);
}

.report-output,
.case-detail {
    display: grid;
    gap: 18px;
    margin-top: 22px;
}

.report-section {
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.report-section h3,
.detail-block h3 {
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--accent-dark);
    text-transform: uppercase;
    letter-spacing: 0;
}

.report-section p,
.report-section li,
.detail-block p {
    color: var(--ink);
    line-height: 1.6;
}

.report-section ul {
    margin: 0;
    padding-left: 20px;
}

.queue-list {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.queue-filter,
.queue-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 720;
}

.queue-filter {
    margin-top: 18px;
}

.queue-filter select,
.queue-status select {
    width: auto;
    min-height: 34px;
    padding: 0 30px 0 10px;
    font: inherit;
}

.queue-item {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.queue-item-main {
    display: grid;
    gap: 7px;
    width: 100%;
    min-height: 92px;
    padding: 14px 14px 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.queue-status {
    padding: 0 14px 12px;
}

.queue-item.is-active {
    border-color: var(--accent);
    background: var(--surface-muted);
}

.queue-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.queue-item small,
.queue-meta,
.muted {
    color: var(--muted);
}

.queue-item small {
    display: -webkit-box;
    overflow: hidden;
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.case-header {
    align-items: flex-start;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.case-actions,
.status-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.status-controls {
    margin-bottom: 6px;
}

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

.detail-block {
    min-width: 0;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}

.detail-block p {
    margin-bottom: 0;
    overflow-wrap: anywhere;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

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

@media (max-width: 1100px) {
    .intro,
    .layout,
    .doctor-layout {
        grid-template-columns: 1fr;
    }

    .report-panel,
    .queue-panel,
    .chat-panel {
        position: static;
        min-height: 520px;
    }

    .chat-panel {
        scroll-margin-top: 24px;
    }

    .queue-panel {
        max-height: none;
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding: 16px;
    }

    .topbar,
    .top-actions,
    .report-header,
    .case-header {
        align-items: stretch;
        flex-direction: column;
    }

    .status-strip {
        justify-content: center;
        width: 100%;
        white-space: normal;
        text-align: center;
    }

    h1,
    .compact-intro h1 {
        font-size: 38px;
    }

    .field-grid,
    .checks,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .intake-panel,
    .report-panel,
    .case-panel,
    .chat-panel {
        padding: 18px;
    }

    .chat-panel {
        min-height: calc(100vh - 32px);
        min-height: calc(100dvh - 32px);
        scroll-margin-top: 16px;
    }

    .chat-header,
    .chat-composer {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .chat-header {
        display: grid;
    }

    .chat-message {
        max-width: 95%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
