:root {
    --ink: #1f2937;
    --muted: #64748b;
    --line: #d8e0ea;
    --panel: #ffffff;
    --soft: #f5f8fb;
    --brand: #173b70;
    --teal: #0f766e;
    --warn: #9a3412;
    --danger: #991b1b;
    --good: #166534;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: #eef3f8;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

a { color: var(--brand); }

button,
input,
select { font: inherit; }

button:focus,
a:focus,
input:focus,
select:focus {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

.app-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: 100vh;
}

.app-sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    min-height: 100vh;
    height: 100vh;
    overflow-y: auto;
    background: #1ABBB9;
    color: #fff;
    padding: 22px 16px;
}

.app-main {
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    color: #fff;
    text-decoration: none;
    margin-bottom: 22px;
    padding: 2px 0;
}

.brand-logo {
    display: block;
    max-width: 100%;
    width: auto;
    height: auto;
    max-height: 42px;
    object-fit: contain;
}

.app-sidebar nav {
    display: grid;
    gap: 6px;
}

.app-sidebar a,
.disabled-nav {
    color: #ffffff;
    border-radius: 6px;
    padding: 10px 12px;
    text-decoration: none;
    font-weight: 700;
}

.app-sidebar a.active,
.app-sidebar a:hover {
    background: #ffffff;
    color: #0f766e;
}

.disabled-nav {
    color: rgba(255, 255, 255, 0.65);
    cursor: not-allowed;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
}

.global-search {
    flex: 1;
    max-width: 720px;
}

.global-search label,
.search-form label,
.sort-form label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
}

input[type="search"],
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    padding: 10px 12px;
}

.topbar-actions,
.button-row,
.context-actions,
.status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.alert-pill,
.profile-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--soft);
    color: var(--ink);
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.page-shell {
    max-width: 1320px;
    margin: 0 auto;
    padding: 24px 28px 48px;
}

.page-title,
.patient-context,
.content-band,
.info-panel,
.table-panel,
.document-toolbar,
.clinical-alert,
.assessment-banner {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
}

.page-title,
.patient-context,
.document-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    padding: 18px 20px;
    margin-bottom: 16px;
}

h1,
h2 {
    margin: 0;
    color: var(--brand);
}

h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { margin: 10px 0; font-size: 16px; }

p { line-height: 1.45; }

.page-title p,
.patient-context p,
.document-toolbar p,
.section-header p,
.muted,
.muted-inline {
    color: var(--muted);
}

.muted {
    display: block;
    margin-top: 4px;
    font-size: 12px;
}

.search-form {
    display: flex;
    gap: 8px;
    align-items: end;
}

.search-form input { width: 320px; }

button,
.primary-button,
.secondary-button,
.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.3;
    transition: all 0.15s ease;
    box-sizing: border-box;
}

.primary-button:hover,
button:hover:not(:disabled) {
    background: #1e3a8a;
    color: #fff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
}

.secondary-button,
.link-button {
    background: var(--teal);
}

.secondary-button:hover,
.link-button:hover {
    background: #0f766e;
    color: #fff;
    box-shadow: 0 2px 6px rgba(13, 148, 136, 0.2);
}

.link-button {
    margin-right: 8px;
}

.compact {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 5px;
}

.disabled,
button:disabled {
    background: #94a3b8;
    color: #fff;
    cursor: not-allowed;
    box-shadow: none;
}

.inline-form { margin: 0; }

.breadcrumb {
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 14px;
}

.breadcrumb a {
    color: var(--brand);
    font-weight: 700;
    text-decoration: none;
}

.patient-context-main {
    min-width: 0;
}

.patient-tabs {
    position: sticky;
    top: 84px;
    z-index: 9;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    background: #eef3f8;
    padding: 8px 0;
    margin-bottom: 16px;
}

.patient-tabs a {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
    font-weight: 700;
    text-decoration: none;
}

.patient-tabs a.active {
    background: var(--brand);
    color: #fff;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.2;
    box-sizing: border-box;
}

.ready,
.status-ready-for-review,
.status-confirmed,
.status-approved { 
    background: #dcfce7; 
    color: #15803d; 
    border: 1px solid #bbf7d0; 
}

.missing,
.status-missing,
.status-not-generated,
.status-unknown,
.status-stale,
.status-conditional { 
    background: #fef3c7; 
    color: #b45309; 
    border: 1px solid #fde68a; 
}

.status-blocked,
.status-blocking,
.status-conflicting,
.status-gap,
.status-rejected { 
    background: #fee2e2; 
    color: #b91c1c; 
    border: 1px solid #fecaca; 
}

.clinical-alert {
    margin-bottom: 16px;
    padding: 16px 18px;
}

.blocking-alert {
    border-color: #ef4444;
    background: #fff1f2;
}

.blocking-alert strong {
    color: var(--danger);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.metric-grid article {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.metric-grid strong {
    display: block;
    color: var(--brand);
    font-size: 22px;
}

.metric-grid span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
}

.filter-bar a,
.filter-bar button {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.filter-bar .active,
.filter-bar a.active {
    background: var(--brand);
    color: #fff;
}

.sort-form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.sort-form select { width: 180px; }

.worklist {
    display: grid;
    gap: 12px;
}

.worklist-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.patient-link {
    display: inline-block;
    color: var(--brand);
    font-size: 18px;
    font-weight: 700;
    text-decoration: none;
}

.worklist-facts,
.detail-list,
.mini-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0 0;
}

.detail-list.four {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.worklist-facts div,
.detail-list div,
.mini-grid div {
    border-left: 3px solid var(--teal);
    padding-left: 10px;
}

dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

dd {
    margin: 4px 0 0;
    font-weight: 700;
}

.compact-list,
.summary-list {
    margin: 10px 0;
    padding-left: 20px;
}

.compact-list li,
.summary-list li {
    margin: 6px 0;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.info-panel,
.content-band {
    padding: 18px;
    margin-bottom: 16px;
}

.assessment-state {
    margin: 12px 0;
    color: var(--danger);
    font-size: 24px;
    font-weight: 700;
}

.caution-text,
.empty-inline {
    border-left: 4px solid #f59e0b;
    background: #fff7e6;
    color: #7c2d12;
    padding: 10px 12px;
}

.notice,
.success-notice {
    margin-bottom: 16px;
    border-radius: 8px;
    padding: 14px 16px;
    font-weight: 700;
}

.notice {
    border: 1px solid #f4c36b;
    background: #fff7e6;
    color: #7c2d12;
}

.success-notice {
    border: 1px solid #86d3a6;
    background: #ecfdf3;
    color: var(--good);
}

.flex-notice {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: #0f2d4a;
    color: #ffffff;
    text-align: left;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 12px 16px;
    white-space: nowrap;
}

th,
td {
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
    font-size: 13px;
    line-height: 1.4;
}

tbody tr {
    transition: background-color 0.12s ease;
}

tbody tr:nth-child(even) { 
    background: #f8fafc; 
}

tbody tr:hover {
    background: #f1f5f9;
}

.data-table th:last-child,
.data-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

.wide-table-wrap {
    width: 100%;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

.data-table,
.payload-table,
.timeline-table { min-width: 980px; }

.source-badge {
    border: 1px solid #b6c6d8;
    background: #eef6ff;
    color: var(--brand);
    border-radius: 999px;
    padding: 5px 8px;
    font-size: 11px;
    font-weight: 700;
}

.confidence-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.brief-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.brief-card {
    min-height: 170px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
    color: inherit;
    padding: 14px;
    text-decoration: none;
}

.brief-card:hover { border-color: var(--teal); }
.warning-card { border-color: #f4c36b; }

.brief-headline {
    margin: 10px 0;
    color: var(--ink);
    font-weight: 700;
}

.brief-metrics,
.brief-facts { padding-left: 18px; }
.brief-facts,
.source-note { color: var(--muted); font-size: 12px; }

.document-workspace {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.document-rail {
    position: sticky;
    top: 82px;
    background: #e8eef5;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.document-rail h2 {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.document-rail nav {
    display: grid;
    gap: 6px;
    margin-top: 10px;
}

.document-rail a {
    color: var(--ink);
    border-left: 3px solid transparent;
    padding: 7px 8px;
    text-decoration: none;
    font-size: 13px;
}

.document-rail a:hover {
    border-color: var(--teal);
    background: var(--panel);
}

.source-accordion {
    display: block;
    padding: 0;
    overflow: hidden;
}

.source-accordion summary {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 14px 16px;
    cursor: pointer;
}

.source-accordion .wide-table-wrap,
.source-accordion .muted { margin: 14px 16px 16px; }

.assessment-markdown {
    margin: 0 16px 18px;
    color: var(--muted);
    white-space: normal;
}

.assessment-hero {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 16px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
}

.assessment-hero.status-blocked {
    border-color: #ef4444;
    background: #fff7f7;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.hero-subtitle {
    margin: 8px 0 12px;
    color: var(--muted);
    font-size: 18px;
}

.compact-table {
    width: 100%;
    min-width: 100%;
}

.compact-table th,
.compact-table td {
    padding: 8px 10px;
    font-size: 13.5px;
    word-break: break-word;
}

.action-grid,
.treatment-course {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.action-card,
.treatment-node {
    border: 1px solid #d9e2ee;
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.treatment-node {
    border-left: 4px solid var(--teal);
}

.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 20;
    display: inline-flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
    font-size: 22px;
    font-weight: 700;
    text-decoration: none;
}

.recommendation-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.recommendation-card {
    border: 1px solid #d9e2ee;
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.assessment-banner {
    padding: 18px;
    margin-bottom: 16px;
}

.assessment-banner.status-blocked {
    border-color: #ef4444;
    background: #fff1f2;
}

.evidence-drawer {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15, 23, 42, 0.35);
}

.drawer-panel {
    margin-left: auto;
    width: min(460px, 100%);
    height: 100%;
    overflow-y: auto;
    background: #fff;
    padding: 22px;
    box-shadow: -10px 0 28px rgba(15, 23, 42, 0.2);
}

.drawer-close {
    float: right;
    background: #475569;
}

.drawer-facts {
    display: grid;
    gap: 12px;
    clear: both;
}

.drawer-facts div {
    border-top: 1px solid #e8eef5;
    padding-top: 10px;
}

.empty-state {
    padding: 28px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 980px) {
    .app-layout { grid-template-columns: 1fr; min-height: auto; }
    .app-sidebar {
        position: static !important;
        min-height: 0 !important;
        height: auto !important;
        padding: 14px 16px;
    }
    .app-sidebar nav {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }
    .brand { margin-bottom: 10px; }
    .brand-logo { max-height: 36px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .worklist-card,
    .overview-grid,
    .brief-grid,
    .action-grid,
    .treatment-course,
    .document-workspace,
    .recommendation-list,
    .detail-list,
    .detail-list.four,
    .worklist-facts {
        grid-template-columns: 1fr;
    }
    .page-title,
    .patient-context,
    .document-toolbar,
    .app-header {
        display: block;
    }
    .context-actions,
    .topbar-actions,
    .search-form { margin-top: 12px; }
    .search-form input { width: 100%; }
    .document-rail { position: static; }
}

@media (max-width: 560px) {
    .page-shell { padding: 14px 12px; }
    .app-sidebar {
        position: static !important;
        min-height: 0 !important;
        height: auto !important;
        padding: 12px 12px 10px;
    }
    .app-sidebar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }
    .app-sidebar a,
    .disabled-nav {
        text-align: center;
        padding: 8px 8px;
        font-size: 13.5px;
    }
    .brand { margin-bottom: 8px; justify-content: center; }
    .brand-logo { max-height: 30px; }
    .metric-grid { grid-template-columns: 1fr; }
    .sort-form { margin-left: 0; }
}
