@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@300;400;600;700;900&display=swap');

:root {
    --nhs-blue: #005EB8;
    --nhs-dark-blue: #003087;
    --nhs-light-blue: #41B6E6;
    --nhs-white: #FFFFFF;
    --nhs-pale-grey: #E8EDEE;
    --nhs-mid-grey: #768692;
    --nhs-dark-grey: #425563;
    --nhs-green: #009639;
    --nhs-yellow: #FFB81C;
    --nhs-red: #DA291C;
    --sidebar-w: 240px;
    --sub-header-h: 44px;
    --header-total-h: 100px;  /* 56px header + 44px sub-header */
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Source Sans 3', Arial, sans-serif;
    background: #F0F4F5;
    color: var(--nhs-dark-grey);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Top Header ── */
.top-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: 56px;
    background: var(--nhs-dark-blue);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px 0 0;
}
.top-header__brand {
    display: flex; align-items: center; gap: 16px;
    height: 100%; padding: 0 24px;
    background: var(--nhs-blue);
    clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 100%, 0 100%);
    padding-right: 40px;
}
.top-header__logo {
    width: 40px; height: 40px;
    background: var(--nhs-white);
    border-radius: 4px;
    display: grid; place-items: center;
    font-weight: 900; font-size: 11px; color: var(--nhs-blue);
    letter-spacing: 0.5px;
    line-height: 1;
}
.top-header__title {
    color: var(--nhs-white);
    font-size: 20px; font-weight: 700;
    letter-spacing: -0.01em;
}
.top-header__right {
    display: flex; align-items: center; gap: 20px; color: rgba(255,255,255,0.8); font-size: 14px;
}
.top-header__right .status-dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--nhs-green);
    display: inline-block; margin-right: 4px;
}

/* ── Header KPIs ── */
.top-header__kpis {
    display: flex;
    align-items: center;
    gap: 24px;
}
.header-kpi {
    display: flex;
    align-items: baseline;
    gap: 3px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    font-weight: 400;
    white-space: nowrap;
}
.header-kpi__num {
    color: var(--nhs-white);
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.header-kpi__sep {
    color: rgba(255, 255, 255, 0.35);
    font-weight: 300;
    font-size: 14px;
    margin: 0 1px;
}
.header-kpi__den {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}
.header-kpi__label {
    color: rgba(255, 255, 255, 0.4);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-left: 4px;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--nhs-white);
    border-right: 1px solid var(--nhs-pale-grey);
    overflow-y: auto; z-index: 100;
    display: flex; flex-direction: column;
}
.sidebar__section { padding: 16px 0; }
.sidebar__section + .sidebar__section { border-top: 1px solid var(--nhs-pale-grey); }
.sidebar__label {
    padding: 0 20px 8px;
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--nhs-mid-grey);
}
.sidebar__item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px;
    font-size: 15px; font-weight: 400;
    color: var(--nhs-dark-grey);
    text-decoration: none;
    border-left: 4px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    cursor: pointer;
}
.sidebar__item:hover { background: #F0F4F5; }
.sidebar__item--active {
    background: #E8F0FE;
    border-left-color: var(--nhs-blue);
    color: var(--nhs-blue);
    font-weight: 600;
}
.sidebar__item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__footer {
    margin-top: auto; padding: 16px 20px;
    border-top: 1px solid var(--nhs-pale-grey);
    font-size: 12px; color: var(--nhs-mid-grey);
}

/* ── Global Filter Sub-Header ── */
.sub-header {
    position: fixed;
    top: 56px;
    left: var(--sidebar-w);
    right: 0;
    z-index: 150;
    height: var(--sub-header-h);
    background: #E8F0FE;
    border-bottom: 1px solid #C5D4E8;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
}
.sub-header__group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.sub-header__label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--nhs-dark-blue);
    white-space: nowrap;
    opacity: 0.6;
}
.sub-header__divider {
    width: 1px;
    height: 24px;
    background: rgba(0, 48, 135, 0.15);
}

/* ── Main Content ── */
.main {
    margin-left: var(--sidebar-w);
    margin-top: var(--header-total-h);
    padding: 24px;
    min-height: calc(100vh - var(--header-total-h));
    display: flex; flex-direction: column; gap: 20px;
    overflow-y: auto;
}

/* View containers */
#view-container {
    flex: 1; display: flex; flex-direction: column; min-height: 0;
}
#patient-pathways-view {
    flex: 1; display: flex; flex-direction: column; min-height: 0; gap: 20px;
}

/* ── Patient Pathways Filter Strip ── */
.pathway-filters {
    background: var(--nhs-white);
    border: 1px solid var(--nhs-pale-grey);
    border-bottom: 2px solid var(--nhs-blue);
    padding: 8px 20px;
    display: flex; align-items: center;
}
.pathway-filters__buttons {
    display: flex; align-items: center; gap: 8px;
}
.pathway-filters__separator {
    width: 1px; height: 24px;
    background: var(--nhs-pale-grey);
    margin: 0 4px;
}

/* Toggle pills */
.toggle-pills {
    display: flex; border: 1px solid var(--nhs-pale-grey); overflow: hidden;
}
.toggle-pill {
    padding: 6px 16px;
    font-size: 14px; font-weight: 600;
    color: var(--nhs-dark-grey);
    background: var(--nhs-white);
    cursor: pointer;
    border: none; outline: none;
    transition: background 0.15s, color 0.15s;
}
.toggle-pill + .toggle-pill { border-left: 1px solid var(--nhs-pale-grey); }
.toggle-pill--active {
    background: var(--nhs-blue);
    color: var(--nhs-white);
}
.toggle-pill:hover:not(.toggle-pill--active) { background: #F0F4F5; }
.toggle-pill:focus-visible { box-shadow: 0 0 0 3px var(--nhs-yellow); z-index: 1; }

/* Dash dcc.Dropdown overrides for filter bar */
.filter-dropdown {
    min-width: 160px;
    font-size: 14px;
    font-family: inherit;
}
.filter-dropdown .Select-control {
    height: 34px;
    border-color: var(--nhs-pale-grey);
}
.filter-dropdown .Select-value-label {
    color: var(--nhs-dark-grey) !important;
    font-size: 14px;
}

/* ── Chart Area ── */
.chart-card {
    background: var(--nhs-white);
    border: 1px solid var(--nhs-pale-grey);
    flex: 1;
    display: flex; flex-direction: column;
    min-height: 0;
}
/* Flex chain through dcc.Loading wrapper → chart container → dcc.Graph */
#chart-container {
    flex: 1; display: flex; flex-direction: column; min-height: 0;
}
#pathway-chart {
    flex: 1; min-height: 0;
}
.chart-card > .dash-loading-callback,
.chart-card > .dash-loading-callback > div {
    flex: 1; display: flex; flex-direction: column; min-height: 0;
}
.chart-card__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--nhs-pale-grey);
    display: flex; justify-content: space-between; align-items: baseline;
}
.chart-card__title {
    font-size: 18px; font-weight: 700;
    color: var(--nhs-dark-blue);
}
.chart-card__subtitle {
    font-size: 13px; color: var(--nhs-mid-grey);
}
.chart-card__tabs {
    display: flex; gap: 0;
    border-bottom: 1px solid var(--nhs-pale-grey);
}
.chart-tab {
    padding: 10px 24px;
    font-size: 14px; font-weight: 600;
    color: var(--nhs-mid-grey);
    border: none; background: none; cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}
.chart-tab--active {
    color: var(--nhs-blue);
    border-bottom-color: var(--nhs-blue);
}
.chart-tab:hover:not(.chart-tab--active) { color: var(--nhs-dark-grey); }
.chart-tab:focus-visible { box-shadow: inset 0 0 0 3px var(--nhs-yellow); }

/* ── Filter Bar Buttons ── */
.filter-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px;
    font-size: 14px; font-weight: 600;
    font-family: inherit;
    color: var(--nhs-dark-grey);
    background: var(--nhs-white);
    border: 1px solid var(--nhs-pale-grey);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.filter-btn:hover { background: #F0F4F5; border-color: var(--nhs-blue); }
.filter-btn:focus-visible { box-shadow: 0 0 0 3px var(--nhs-yellow); z-index: 1; }
.filter-btn--clear {
    color: var(--nhs-mid-grey);
    border-color: transparent;
    background: transparent;
    font-weight: 400;
}
.filter-btn--clear:hover { color: var(--nhs-red); background: transparent; }
.filter-btn__badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px;
    padding: 0 6px;
    font-size: 11px; font-weight: 700;
    color: var(--nhs-white);
    background: var(--nhs-blue);
    border-radius: 10px;
    line-height: 1;
}
.filter-btn__badge--hidden { display: none; }

/* ── Filter Modals ── */
.modal-chips-scroll {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 8px;
}
.modal-chips-scroll .mantine-Chip-label {
    font-family: 'Source Sans 3', Arial, sans-serif;
    white-space: nowrap;
}
.mantine-Modal-title {
    width: 100%;
}
.modal-drug-badge {
    cursor: pointer;
    transition: background 0.15s;
}
.modal-drug-badge:hover {
    filter: brightness(0.9);
}
.modal-directorate-accordion {
    margin-top: 8px;
}

/* ── Footer ── */
.page-footer {
    background: var(--nhs-pale-grey);
    border-top: 1px solid #D0D5D6;
    padding: 16px 20px;
    font-size: 13px; color: var(--nhs-mid-grey);
    text-align: center;
}

/* ── Trust Comparison Landing ── */
.tc-landing {
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.tc-landing__header {
    padding: 0 0 8px;
}
.tc-landing__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--nhs-dark-blue);
    margin: 0 0 4px;
}
.tc-landing__desc {
    font-size: 14px;
    color: var(--nhs-mid-grey);
    font-weight: 400;
    margin: 0;
}
.tc-landing__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.tc-landing__grid--wide {
    grid-template-columns: repeat(4, 1fr);
}

/* Directorate selector cards */
.tc-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 20px;
    background: var(--nhs-white);
    border: 1px solid var(--nhs-pale-grey);
    border-left: 4px solid transparent;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.tc-card:hover {
    border-left-color: var(--nhs-blue);
    background: #FAFCFF;
    box-shadow: 0 1px 4px rgba(0, 48, 135, 0.08);
}
.tc-card:focus-visible {
    box-shadow: 0 0 0 3px var(--nhs-yellow);
    z-index: 1;
}
.tc-card__name {
    font-size: 14px;
    font-weight: 700;
    color: var(--nhs-dark-blue);
    line-height: 1.3;
}
.tc-card__stats {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--nhs-mid-grey);
}
.tc-card__stat {
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}
.tc-card__dot {
    color: var(--nhs-pale-grey);
}

/* ── Trust Comparison Dashboard ── */
.tc-dashboard {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.tc-dashboard__header {
    display: flex;
    align-items: center;
    gap: 16px;
}
.tc-dashboard__back {
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: var(--nhs-blue);
    background: var(--nhs-white);
    border: 1px solid var(--nhs-pale-grey);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.tc-dashboard__back:hover {
    background: #E8F0FE;
}
.tc-dashboard__back:focus-visible {
    box-shadow: 0 0 0 3px var(--nhs-yellow);
}
.tc-dashboard__title {
    font-size: 20px;
    font-weight: 700;
    color: var(--nhs-dark-blue);
    margin: 0;
}

/* 2×3 chart grid */
.tc-dashboard__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Individual chart cell */
.tc-chart-cell {
    background: var(--nhs-white);
    border: 1px solid var(--nhs-pale-grey);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.tc-chart-cell__title {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--nhs-dark-blue);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--nhs-pale-grey);
}

/* ── Responsive ── */
@media (max-width: 1200px) {
    .tc-landing__grid { grid-template-columns: repeat(2, 1fr); }
    .tc-landing__grid--wide { grid-template-columns: repeat(3, 1fr); }
    .top-header__kpis { gap: 16px; }
    .header-kpi__label { display: none; }
}
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; }
    .sub-header { left: 0; }
    .top-header__kpis { display: none; }
    .tc-landing__grid { grid-template-columns: 1fr; }
    .tc-dashboard__grid { grid-template-columns: 1fr; }
    .pathway-filters { flex-wrap: wrap; gap: 8px; }
}
