:root {
    --bg: #eef2f4;
    --surface: #ffffff;
    --surface-muted: #f8fafb;
    --ink: #17212b;
    --muted: #60717f;
    --line: #dce5ea;
    --line-strong: #c7d4dc;
    --clinical: #1d6f75;
    --clinical-soft: #e7f3f4;
    --good: #2d7d59;
    --amber: #b87918;
    --risk: #b04c44;
    --shadow: 0 14px 38px rgba(25, 43, 54, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

.app-shell {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 14px clamp(14px, 2.4vw, 34px) 28px;
}

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

.eyebrow {
    margin: 0 0 5px;
    color: var(--clinical);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.095em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.55rem, 2.5vw, 2.25rem);
    font-weight: 780;
    letter-spacing: -0.04em;
}

h2 {
    margin: 0;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.subtle { color: var(--muted); }

.patient-card {
    min-width: 250px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(25, 43, 54, 0.05);
}

.patient-card span,
.patient-card small {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
}
.patient-card strong { display: block; font-size: 1rem; }

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

.stage-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: rgba(255,255,255,.72);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px;
}

.stage-jump,
.reset-button,
.primary-action,
.secondary-action {
    border: 1px solid transparent;
    border-radius: 999px;
    font-weight: 720;
    transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.stage-jump {
    padding: 7px 12px;
    background: transparent;
    color: var(--muted);
    font-size: .82rem;
}
.stage-controls .stage-jump.active { background: var(--clinical-soft); color: var(--clinical); box-shadow: inset 0 0 0 1px rgba(29,111,117,.22); }
.stage-jump.available:not(.active):hover { background: var(--clinical-soft); color: var(--clinical); }

.reset-button,
.secondary-action {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--muted);
    padding: 8px 13px;
}
.reset-button:hover,
.secondary-action:hover { border-color: var(--clinical); color: var(--clinical); }

.matrix-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.matrix-scroll { overflow-x: auto; }

.wellness-matrix {
    width: 100%;
    min-width: 1180px;
    border-collapse: separate;
    border-spacing: 0;
}

.wellness-matrix th,
.wellness-matrix td {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    padding: 9px 10px;
    vertical-align: middle;
    background: var(--surface);
}

.wellness-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f9fbfc;
    color: var(--ink);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.wellness-matrix thead th span,
.wellness-matrix thead th small { display: block; }
.wellness-matrix thead th small {
    margin-top: 3px;
    color: var(--muted);
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 4;
    width: 225px;
    min-width: 225px;
    box-shadow: 8px 0 14px rgba(20, 35, 45, 0.035);
}

tbody .sticky-col { background: #fbfcfd; }

.pillar-name { font-size: .98rem; font-weight: 800; }
.pillar-hint {
    margin-top: 4px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 500;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mobile-opportunity { display: none; }

.progressive-col {
    opacity: 1;
    transform: translateX(0);
    transition: opacity .22s ease, transform .22s ease, max-width .22s ease, padding .22s ease;
}

.app-shell[data-stage="1"] [data-stage-col="2"],
.app-shell[data-stage="1"] [data-stage-col="3"],
.app-shell[data-stage="1"] [data-stage-col="4"],
.app-shell[data-stage="1"] [data-stage-col="5"],
.app-shell[data-stage="2"] [data-stage-col="3"],
.app-shell[data-stage="2"] [data-stage-col="4"],
.app-shell[data-stage="2"] [data-stage-col="5"],
.app-shell[data-stage="3"] [data-stage-col="4"],
.app-shell[data-stage="3"] [data-stage-col="5"],
.app-shell[data-stage="4"] [data-stage-col="5"] {
    display: none;
}

.level-control {
    display: grid;
    grid-template-columns: repeat(3, minmax(76px, 1fr));
    gap: 6px;
}

.level-option {
    margin: 0;
    cursor: pointer;
}
.level-option input { position: absolute; opacity: 0; pointer-events: none; }
.level-option span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface-muted);
    color: var(--muted);
    font-weight: 760;
}
.level-option.selected span { color: #fff; box-shadow: inset 0 0 0 2px rgba(255,255,255,.38); }
.level-control.wellbeing .level-low.selected span { background: var(--risk); border-color: var(--risk); }
.level-control.wellbeing .level-medium.selected span { background: var(--amber); border-color: var(--amber); }
.level-control.wellbeing .level-high.selected span { background: var(--good); border-color: var(--good); }
.level-control.burden .level-low.selected span { background: var(--good); border-color: var(--good); }
.level-control.burden .level-medium.selected span { background: var(--amber); border-color: var(--amber); }
.level-control.burden .level-high.selected span { background: var(--risk); border-color: var(--risk); }

.reference-level {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-weight: 780;
    font-size: .78rem;
    margin-bottom: 6px;
}
.reference-level.level-low { color: #7d342e; background: #f7e7e5; }
.reference-level.level-medium { color: #7a4d0f; background: #f8edd9; }
.reference-level.level-high { color: #215d43; background: #e2f2ea; }
.reference-level.inverse.level-low { color: #215d43; background: #e2f2ea; }
.reference-level.inverse.level-high { color: #7d342e; background: #f7e7e5; }

details summary { cursor: pointer; color: var(--ink); font-weight: 700; }
details ul { margin: 8px 0 0; padding-left: 17px; color: var(--muted); font-size: .8rem; }

action-cell, .action-cell { min-width: 265px; }
textarea {
    width: 100%;
    min-height: 48px;
    max-height: 160px;
    resize: vertical;
    border: 1px solid var(--line-strong);
    border-radius: 11px;
    padding: 9px 10px;
    color: var(--ink);
    background: var(--surface-muted);
    line-height: 1.35;
}
textarea:focus,
.level-option:focus-within span {
    outline: 3px solid rgba(29,111,117,.18);
    border-color: var(--clinical);
}

tr.opportunity-strong td,
tr.opportunity-strong .sticky-col { background: #f3faf8; }
tr.opportunity-moderate td,
tr.opportunity-moderate .sticky-col { background: #fffdf7; }

.workflow-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 2px 16px;
}
.save-state { color: var(--muted); font-size: .83rem; }
.workflow-actions { display: flex; gap: 8px; }
.primary-action {
    background: var(--clinical);
    color: #fff;
    padding: 10px 18px;
}
.primary-action:hover { background: #155b60; transform: translateY(-1px); }

.overview-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
    margin-top: 4px;
}
.overview-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 12px;
}
.overview-heading p { color: var(--muted); margin: 0; max-width: 520px; }
.overview-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.overview-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 13px;
    background: #fbfcfd;
}
.overview-card.opportunity-strong { border-color: #9fcfbd; background: #f1faf6; }
.overview-card.opportunity-moderate { border-color: #ead29c; background: #fffaf0; }
.overview-card-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: start;
}
.overview-card-top span {
    border-radius: 999px;
    padding: 4px 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: .72rem;
    font-weight: 760;
    white-space: nowrap;
}
dl {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin: 10px 0;
}
dt { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; }
dd { margin: 0; font-weight: 780; }
.overview-card p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.4; }

@media (max-width: 980px) {
    .clinical-header, .control-strip, .workflow-footer, .overview-heading { align-items: stretch; flex-direction: column; }
    .patient-card { min-width: 0; }
    .overview-grid { grid-template-columns: 1fr; }
    .wellness-matrix { min-width: 0; }
    .wellness-matrix thead { display: none; }
    .wellness-matrix, .wellness-matrix tbody, .wellness-matrix tr, .wellness-matrix th, .wellness-matrix td { display: block; width: 100%; }
    .wellness-matrix tr { border-bottom: 1px solid var(--line-strong); }
    .wellness-matrix td { border-right: 0; padding-left: 148px; position: relative; }
    .wellness-matrix td::before { content: attr(data-label); position: absolute; left: 12px; top: 16px; color: var(--muted); font-size: .74rem; font-weight: 800; text-transform: uppercase; }
    .sticky-col { position: static; min-width: 0; box-shadow: none; }
    .pillar-hint { display: none; }
    .mobile-opportunity { display: inline-flex; margin-top: 6px; color: var(--clinical); font-size: .76rem; font-weight: 800; }
}
