/* Cohort extension: inherit the Explorer palette, typography and control shapes.
   Layers: ordinary content 0, anchored non-modal filter panels 60 (above Atlas status notifications). */
.cohort-filters { margin: 24px 0 12px; padding: 22px 22px 14px; border: 1px solid var(--line-strong); border-radius: 16px; background: var(--panel); color: var(--text); }
.cohort-filters [hidden] { display: none !important; }
.cohort-optional { color: var(--muted); font-size: .8rem; font-weight: 400; }
.cohort-primary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto auto; gap: 12px; align-items: end; }
.cohort-field { min-width: 0; }
.cohort-field > span, .cohort-panel label:not(.cohort-check) { display: block; margin-bottom: 7px; font-size: .83rem; font-weight: 600; }
.cohort-filters button, .cohort-filters input { font: inherit; }
.cohort-trigger, .cohort-more, .cohort-apply { min-height: 46px; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: .9rem !important; white-space: nowrap; }
.cohort-trigger { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; text-align: left; border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); }
.cohort-trigger > [id$="Value"] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cohort-chevron { width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); flex: none; margin: -4px 3px 0; }
.cohort-trigger[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); }
.cohort-trigger[aria-expanded="true"] .cohort-chevron { transform: rotate(225deg); margin-top: 4px; }
.cohort-more { color: var(--accent-strong); border: 1px solid transparent; background: transparent; }
.cohort-more[aria-expanded="true"] { background: var(--accent-soft); }
.cohort-more span { margin-left: 7px; font-variant-numeric: tabular-nums; }
.cohort-apply { color: #fbfdfe; background: var(--accent-strong); border: 1px solid var(--accent-strong); font-weight: 600 !important; }
.cohort-filters button:disabled { opacity: .58; cursor: not-allowed; }
.cohort-filters button:not(:disabled):hover { filter: brightness(.96); }
.cohort-filters button:not(:disabled):active { transform: translateY(1px); }
.cohort-filters :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.cohort-filters input { accent-color: var(--accent); caret-color: var(--accent); }
.cohort-filters ::selection { background: var(--accent-soft); color: var(--accent-strong); }
.cohort-panel { position: fixed; z-index: 60; width: min(440px, calc(100vw - 32px)); padding: 20px; background: var(--panel); border-radius: 12px; box-shadow: 0 12px 40px rgba(28,52,66,.23); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.cohort-panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.cohort-panel h3, .cohort-sample-panel h3 { font-size: .95rem; font-weight: 650; margin: 0; }
.cohort-text-button { padding: 6px 2px; border: 0; background: transparent; color: var(--accent-strong); font-size: .82rem !important; font-weight: 600 !important; cursor: pointer; text-underline-offset: 3px; min-height: 32px; }
.cohort-text-button:hover { text-decoration: underline; }
.cohort-presets { display: flex; flex-wrap: wrap; gap: 7px; }
.cohort-presets button { padding: 8px 11px; min-height: 36px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); border-radius: 8px; cursor: pointer; font-size: .8rem; }
.cohort-presets button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.cohort-age-range { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0; border: 0; margin: 20px 0 12px; }
.cohort-age-range legend { font-size: .82rem; margin-bottom: 12px; font-weight: 600; }
.cohort-age-range input, #cohortConditionSearch { width: 100%; min-height: 42px; padding: 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); font-size: .85rem; }
.cohort-filters input::placeholder { color: #61717d; opacity: 1; }
.cohort-filters input[aria-invalid="true"] { border-color: var(--danger); }
.cohort-help { color: #526572; font-size: .8rem; line-height: 1.5; margin: 9px 0 12px; max-width: 65ch; }
.cohort-check { display: flex; align-items: flex-start; gap: 9px; min-height: 36px; padding: 8px 0; font-size: .82rem; line-height: 1.4; cursor: pointer; }
.cohort-check input { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.cohort-condition-tree { margin: 12px -5px; max-height: 310px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.cohort-tree-branch { padding-left: 15px; }
.cohort-tree-row { display: flex; align-items: flex-start; gap: 5px; padding: 2px 5px; border-radius: 6px; }
.cohort-tree-row:hover { background: var(--panel-strong); }
.cohort-tree-expander { width: 24px; min-height: 36px; border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 7px; }
.cohort-tree-expander:disabled { visibility: hidden; }
.cohort-tree-expander .cohort-chevron { display: block; width: 5px; height: 5px; transform: rotate(-45deg); margin: 0; }
.cohort-tree-expander[aria-expanded="true"] .cohort-chevron { transform: rotate(45deg); }
.cohort-tree-row .cohort-check { flex: 1; min-width: 0; }
.cohort-tree-row .cohort-check > span:not(.cohort-count) { min-width: 0; overflow-wrap: anywhere; }
.cohort-tree-row .cohort-count { margin-left: auto; padding-left: 8px; font-variant-numeric: tabular-nums; color: #526572; font-size: .75rem; }
.cohort-sample-panel { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; border-top: 1px solid var(--line); margin-top: 18px; padding-top: 18px; }
.cohort-optional { margin-left: 6px; }
.cohort-sample-options { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.cohort-feedback { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; min-height: 32px; }
.cohort-feedback p { font-size: .82rem; color: #526572; line-height: 1.5; font-variant-numeric: tabular-nums; }
.cohort-filters[data-pending="true"] .cohort-feedback p { color: var(--accent-strong); }
.cohort-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cohort-chip { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; padding: 0 0 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-strong); color: var(--text); font-size: .78rem !important; text-align: left; }
.cohort-chip-label { min-width: 0; padding: 6px 0; overflow-wrap: anywhere; }
.cohort-filters .cohort-chip-remove { align-self: stretch; flex: none; min-width: 58px; min-height: 36px; margin-left: 6px; padding: 6px 10px; border: 0; border-left: 1px solid var(--line); border-radius: 0 7px 7px 0; background: transparent; color: var(--accent-strong); font-size: .72rem; cursor: pointer; }
.cohort-filters .cohort-chip-remove:hover { background: var(--accent-soft); text-decoration: underline; text-underline-offset: 3px; }
.cohort-error, .cohort-empty { padding: 12px 0 4px; font-size: .83rem; line-height: 1.5; }
.cohort-error { color: var(--danger); }
.cohort-empty { color: var(--text); border-top: 1px solid var(--line); margin-top: 12px; }
.cohort-filters[aria-busy="true"] .cohort-primary { opacity: .7; }
.cohort-filters + .controls { margin-top: 12px; background: transparent; border-color: var(--line); padding-top: 16px; padding-bottom: 16px; }
@media (max-width: 900px) {
    .cohort-primary { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .cohort-more { justify-self: start; }
    .cohort-apply { justify-self: end; min-width: 140px; }
}
@media (max-width: 600px) {
    body { padding: 12px; }
    .container { padding: 16px; border-radius: 18px; }
    .cohort-filters { padding: 16px 14px 12px; }
    .cohort-primary { gap: 12px 8px; }
    .cohort-field { grid-column: 1 / -1; }
    .cohort-sample-panel { grid-template-columns: 1fr; gap: 4px; }
    .cohort-panel { width: calc(100vw - 24px); padding: 16px; max-height: calc(100dvh - 24px); }
    .cohort-tree-branch { padding-left: 10px; }
    .cohort-condition-tree { max-height: min(310px, 42dvh); }
}
@media (prefers-reduced-motion: no-preference) {
    .cohort-trigger, .cohort-apply, .cohort-presets button { transition: background-color 150ms ease, border-color 150ms ease; }
}
/* Atlas-local controls inherit its dark scientific viewer palette. */
#atlasSection .cohort-filters {
    --accent-soft: #153c3b;
    --danger: #ffb4ab;
    margin: 0;
    padding: 16px 18px 12px;
    border: 0;
    border-bottom: 1px solid var(--line-strong);
    border-radius: 0;
}
#atlasSection .cohort-help,
#atlasSection .cohort-feedback p,
#atlasSection .cohort-count { color: #a8bec8; }
#atlasSection .cohort-apply { background: var(--accent); border-color: var(--accent); color: #071019; }
#atlasSection .cohort-panel { border: 1px solid var(--line-strong); }
#atlasSection .cohort-filters input::placeholder { color: #8da4ae; }


/* Compact toolbar keeps the brain viewer as the dominant surface. */
#atlasSection .cohort-filters { padding: 8px 18px; }
.cohort-controls { border: 0; padding: 0; margin: 0; min-width: 0; }
#atlasSection .cohort-primary { grid-template-columns: minmax(160px, 240px) minmax(220px, 320px) auto auto; justify-content: start; gap: 8px; align-items: center; }
#atlasSection .cohort-trigger, #atlasSection .cohort-more, #atlasSection .cohort-apply { min-height: 34px; padding: 6px 10px; border-radius: 7px; font-size: .8rem !important; }
#atlasSection .cohort-trigger { gap: 8px; justify-content: start; }
.cohort-inline-label { color: var(--muted); font-size: .75rem; flex: none; }
.cohort-trigger .cohort-chevron { margin-left: auto; }
#atlasSection .cohort-apply { min-width: 64px; }
#atlasSection .cohort-feedback { margin-top: 4px; min-height: 20px; justify-content: start; gap: 6px 16px; }
#atlasSection .cohort-feedback p { font-size: .75rem; margin: 0; }
#atlasSection .cohort-feedback .cohort-text-button { min-height: 24px; padding: 2px; font-size: .75rem !important; }
.cohort-chips:not(:empty) { margin-top: 4px; }
.cohort-unsupported { color: var(--muted); font-size: .75rem; line-height: 1.5; margin: 5px 0 0; }
.cohort-filters[data-supported="false"] .cohort-feedback,
.cohort-filters[data-supported="false"] .cohort-chips,
.cohort-filters[data-supported="false"] .cohort-empty,
.cohort-filters[data-supported="false"] #cohortError { display: none; }
@media (max-width: 900px) {
    #atlasSection .cohort-primary { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto auto; }
}
@media (max-width: 600px) {
    #atlasSection .cohort-filters { padding: 8px 12px; }
    #atlasSection .cohort-primary { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 4px 8px; }
    #atlasSection .cohort-field { grid-column: auto; }
    #atlasSection .cohort-trigger { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 6px; min-height: 48px; }
    .cohort-inline-label { grid-column: 1; text-align: left; }
    .cohort-trigger > [id$="Value"] { grid-column: 1; grid-row: 2; }
    .cohort-trigger .cohort-chevron { grid-column: 2; grid-row: 1 / 3; }
    #atlasSection .cohort-more, #atlasSection .cohort-apply { min-height: 40px; }
}
#atlasSection .cohort-controls:disabled .cohort-apply {
    background: var(--panel-strong);
    border-color: var(--line-strong);
    color: var(--muted);
}

/* Match the Atlas control family; the Filter trigger shares its header actions. */
#atlasFilterToggle[aria-expanded="true"] { border-color: var(--accent); background: rgba(85,214,176,.12); color: var(--accent-strong); }
#atlasSection .cohort-trigger { font-family: inherit; font-size: 12px !important; font-weight: 500; color: var(--muted); background: rgba(255,255,255,.025); }
#atlasSection .cohort-inline-label { font-size: 11px; font-weight: 600; color: #b9ccd0; }

#atlasSection #atlasFilterDone { font-size: 11px; font-weight: 600; }
#atlasSection.show-filters .toast { visibility: hidden; }

.cohort-settings-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.cohort-settings-hint .cohort-text-button { font-size: 12px !important; padding: 2px; min-height: 28px; text-decoration: underline; }

/* Quiet Atlas form controls: category, value and disclosure each have one role. */
#atlasSection .cohort-primary { gap: 10px; }
#atlasSection .cohort-trigger {
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
    border-color: rgba(150,185,201,.2);
    background: #101f2b;
    color: #cfe3e2;
    gap: 10px;
    line-height: 1.25;
}
#atlasSection .cohort-inline-label {
    padding-right: 10px;
    border-right: 1px solid var(--line-strong);
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
}
.cohort-select-arrow { width: 14px; height: 14px; flex: none; margin-left: auto; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#atlasSection .cohort-trigger:not(:disabled):hover { filter: none; background: #142733; border-color: rgba(150,185,201,.42); }
#atlasSection .cohort-trigger[aria-expanded="true"] { border-color: var(--accent); background: #102d2e; }
.cohort-trigger[aria-expanded="true"] .cohort-select-arrow { transform: rotate(180deg); stroke: var(--accent); }
#atlasSection .cohort-more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 8px 10px;
    color: #a8bec8;
    font-size: 12px !important;
    font-weight: 500;
    line-height: 1.25;
    border-radius: 8px;
}
.cohort-more-icon { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.25; stroke-linecap: round; flex: none; }
#atlasSection .cohort-more:not(:disabled):hover { filter: none; color: var(--text); background: var(--panel-strong); }
#atlasSection .cohort-more[aria-expanded="true"] { color: var(--accent-strong); background: var(--accent-soft); }
.cohort-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
#atlasSection .cohort-settings-hint { margin: 0; font-size: 11px; line-height: 1.4; }
#atlasSection .cohort-settings-hint .cohort-text-button { font-size: 11px !important; font-weight: 500 !important; }
#atlasSection #atlasFilterDone { margin-left: auto; padding: 6px 12px; min-height: 28px; }
@media (max-width: 600px) {
    #atlasSection .cohort-primary { gap: 4px 8px; }
    #atlasSection .cohort-trigger { min-height: 48px; gap: 3px 8px; padding: 7px 10px; }
    #atlasSection .cohort-inline-label { padding: 0; border: 0; }
    .cohort-select-arrow { grid-column: 2; grid-row: 1 / 3; }
    #atlasSection .cohort-more { min-height: 40px; }
    #atlasSection .cohort-footer { gap: 6px; }
    #atlasSection #atlasFilterDone { flex: none; }
}

/* The disclosure opens space for filtering; data updates never dismiss it.
   Grid rows keep the surrounding Atlas layout continuous without fixed heights. */
.cohort-disclosure { display: grid; grid-template-rows: 0fr; opacity: 0; overflow-anchor: none; transition: grid-template-rows 180ms cubic-bezier(.16,1,.3,1), opacity 140ms ease-out; }
.cohort-disclosure[hidden] { display: none; }
.cohort-disclosure[data-open="true"] { grid-template-rows: 1fr; opacity: 1; transition-duration: 240ms, 180ms; }
.cohort-disclosure-clip { min-height: 0; overflow: hidden; }
.cohort-disclosure[data-state="open"] > .cohort-disclosure-clip { overflow: visible; }
.cohort-panel:not([hidden]) { animation: cohort-options-in 130ms ease-out; }
@keyframes cohort-options-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: no-preference) {
    .cohort-select-arrow { transition: transform 160ms ease-out; }
    .cohort-chip-remove { transition: background-color 120ms ease-out; }
}
@media (prefers-reduced-motion: reduce) {
    .cohort-disclosure, .cohort-disclosure[data-open="true"] { transition-duration: 0s, 70ms; }
    .cohort-panel:not([hidden]) { animation-duration: 70ms; }
}
