:root {
    --bg: #f3f0e8;
    --panel: rgba(255, 255, 255, 0.82);
    --panel-border: rgba(66, 50, 35, 0.12);
    --text: #1b1712;
    --muted: #65594d;
    --accent: #8d4a24;
    --accent-strong: #5a2d15;
    --soft: #efe1d3;
    --success: #2d6a4f;
    --danger: #a12b2b;
    --shadow: 0 18px 45px rgba(63, 43, 26, 0.12);
    --radius: 20px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(223, 176, 117, 0.28), transparent 35%),
        radial-gradient(circle at top right, rgba(110, 146, 162, 0.22), transparent 26%),
        linear-gradient(160deg, #efe9de 0%, #f6f3ec 45%, #ece5d9 100%);
    min-height: 100vh;
}

.shell,
.viewer-shell {
    width: min(1240px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 48px;
}

.hero,
.viewer-header,
.grid,
.panel,
.study-card,
.patient-card,
.series-card {
    animation: rise 420ms ease both;
}

.hero,
.grid,
.bottom-grid {
    display: grid;
    gap: 18px;
}

.hero {
    grid-template-columns: 2fr 1fr;
    align-items: start;
    margin-bottom: 24px;
}

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

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

.eyebrow {
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    margin: 0 0 10px;
}

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

h1 {
    font-size: clamp(2rem, 4vw, 3.6rem);
    line-height: 0.95;
    max-width: 12ch;
}

h2 {
    font-size: 1.1rem;
}

.subtitle {
    margin-top: 16px;
    color: var(--muted);
    max-width: 62ch;
    line-height: 1.5;
}

.section-copy,
.helper-text {
    color: var(--muted);
    line-height: 1.5;
}

.section-copy {
    margin-top: 8px;
}

.helper-text {
    font-size: 0.92rem;
}

.hero-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.hero-link {
    display: inline-flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(141, 74, 36, 0.08);
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 600;
}

.status-card,
.panel,
.patient-card,
.study-card,
.series-card {
    border: 1px solid var(--panel-border);
    background: var(--panel);
    backdrop-filter: blur(18px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.status-card {
    padding: 20px;
}

.credentials {
    margin-top: 18px;
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.95rem;
}

.panel {
    padding: 20px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 16px;
}

.inline-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.action-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.stack {
    display: grid;
    gap: 14px;
}

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

.selection-banner {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(141, 74, 36, 0.07);
    border: 1px solid rgba(141, 74, 36, 0.12);
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.92rem;
}

input,
button,
textarea {
    font: inherit;
}

input {
    border: 1px solid rgba(96, 73, 53, 0.18);
    background: rgba(255, 255, 255, 0.84);
    border-radius: 14px;
    padding: 12px 14px;
    color: var(--text);
}

input:focus {
    outline: 2px solid rgba(141, 74, 36, 0.25);
    border-color: rgba(141, 74, 36, 0.55);
}

button {
    border: none;
    border-radius: 999px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff7ef;
    cursor: pointer;
    transition: transform 140ms ease, opacity 140ms ease;
}

button:hover {
    transform: translateY(-1px);
}

button.ghost {
    background: rgba(141, 74, 36, 0.08);
    color: var(--accent-strong);
}

pre.result {
    min-height: 64px;
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 16px;
    background: #f4f2ee;
    color: #513f31;
    overflow: auto;
    white-space: pre-wrap;
    font-size: 0.9rem;
}

.cards,
.series-list {
    display: grid;
    gap: 12px;
}

.patient-card,
.study-card,
.series-card {
    padding: 16px;
}

.patient-meta,
.study-meta,
.order-chip,
.metadata-grid {
    display: grid;
    gap: 8px;
}

.patient-actions,
.study-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.order-chip,
.tag {
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--soft);
    font-size: 0.9rem;
}

code {
    font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
    font-size: 0.92em;
}

.empty-state {
    color: var(--muted);
}

.back-link {
    display: inline-flex;
    margin-bottom: 18px;
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 600;
}

.metadata-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metadata-grid .tag strong {
    display: block;
    margin-bottom: 4px;
}

.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.thumb-card {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(96, 73, 53, 0.12);
    background: rgba(255, 255, 255, 0.76);
}

.thumb-card img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #d7d0c6;
}

.thumb-card footer {
    padding: 10px;
    font-size: 0.9rem;
    color: var(--muted);
}

.viewer-body {
    background:
        radial-gradient(circle at top, rgba(233, 182, 116, 0.22), transparent 36%),
        linear-gradient(180deg, #f7f4ee 0%, #ece4d8 100%);
}

.viewer-body.patient-mode {
    background:
        radial-gradient(circle at top left, rgba(149, 189, 218, 0.22), transparent 34%),
        linear-gradient(180deg, #f4f6f8 0%, #e8edf1 100%);
}

.viewer-layout {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 18px;
}

.viewer-layout.patient-unified-layout .patient-stage-card {
    max-width: none;
    margin: 0;
}

.patient-viewer-layout {
    display: grid;
    grid-template-columns: 1fr;
}

.viewer-stage-card,
.viewer-gallery-card {
    min-height: 100%;
}

.patient-stage-card {
    max-width: 980px;
    margin: 0 auto;
}

.viewer-toolbar,
.viewer-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.viewer-toolbar {
    justify-content: space-between;
    margin-bottom: 14px;
}

.viewer-mode-badge,
.viewer-counter {
    padding: 9px 12px;
    border-radius: 999px;
    background: var(--soft);
    color: var(--accent-strong);
    font-size: 0.9rem;
    font-weight: 700;
}

.viewer-stage {
    min-height: 420px;
    border-radius: 22px;
    overflow: hidden;
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 40%),
        linear-gradient(180deg, #101418 0%, #1f2731 100%);
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.viewer-stage img {
    display: block;
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
}

.patient-stage {
    min-height: 500px;
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.1), transparent 40%),
        linear-gradient(180deg, #dde6ee 0%, #cdd8e1 100%);
}

.viewer-caption {
    margin-top: 14px;
    color: var(--muted);
    line-height: 1.6;
}

.viewer-note {
    margin-top: 10px;
    color: var(--muted);
    line-height: 1.5;
}

.viewer-thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 10px;
    margin-top: 18px;
}

.viewer-thumb-button {
    padding: 0;
    overflow: hidden;
    border-radius: 16px;
    border: 1px solid rgba(96, 73, 53, 0.12);
    background: rgba(255, 255, 255, 0.82);
    color: var(--text);
    text-align: left;
}

.viewer-thumb-button.active {
    outline: 2px solid rgba(141, 74, 36, 0.35);
    transform: translateY(-1px);
}

.viewer-thumb-button img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #d7d0c6;
}

.viewer-thumb-label {
    display: block;
    padding: 9px 10px 10px;
    font-size: 0.82rem;
    color: var(--muted);
}

.series-summary-list {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

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

@media (max-width: 920px) {
    .hero,
    .grid,
    .bottom-grid {
        grid-template-columns: 1fr;
    }

    .panel-head {
        flex-direction: column;
        align-items: stretch;
    }

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

    .selection-banner {
        flex-direction: column;
        align-items: stretch;
    }

    .viewer-layout {
        grid-template-columns: 1fr;
    }
}
