/* Avoid painting legacy controls before the synchronous sidebar setup finishes. */
.op-sidebar-ui:not(.op-sidebar-ready) .sidebar { visibility: hidden; }
/* The current site starts with a default cohort; only explicit actions open this drawer. */
.op-sidebar-ui #cohort-modal-overlay { display: none; }
/* Shared sidebar controls and drawer chrome. One family for every sidebar menu;
 * compact segmented choices remain distinct from buttons that open a panel. */
.op-sidebar-ui .sidebar { overflow: visible; }
.op-sidebar-ui .op-sidebar-control {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    height: 44px;
    min-height: 44px;
    margin: 0 !important;
    padding: 0 12px;
    border: 1px solid var(--border-color-strong);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: .875rem;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    cursor: pointer;
    transition: var(--transition-fast);
}
.op-sidebar-ui .op-sidebar-control:hover { background: var(--straw-tint); border-color: var(--primary); }
.op-sidebar-ui .op-sidebar-control:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.op-sidebar-ui .op-sidebar-control[aria-expanded="true"], details[open] > .op-sidebar-control {
    border-color: var(--primary); background: var(--straw-tint);
}
.op-sidebar-ui .op-sidebar-control:disabled { opacity: .5; cursor: default; }
.op-sidebar-ui .op-sidebar-control > :is(svg, i) { display: none; }
.op-sidebar-disclosure::after, .op-sidebar-select::after {
    content: '';
    flex: 0 0 16px;
    width: 16px;
    height: 16px;
    margin-left: auto;
    background: var(--text-secondary);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m9 6 6 6-6 6' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m9 6 6 6-6 6' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
    transition: transform .15s ease;
}
.op-sidebar-disclosure[aria-expanded="true"]::after, details[open] > .op-sidebar-disclosure::after { transform: rotate(90deg); }
.op-sidebar-ui summary.op-sidebar-control { list-style: none; }
.op-sidebar-ui summary.op-sidebar-control::-webkit-details-marker { display: none; }
.op-sidebar-select { position: relative; width: 100%; }
.op-sidebar-select select.op-sidebar-control { display: block; appearance: none; padding-right: 40px; }
.op-sidebar-select::after { position: absolute; top: 14px; right: 12px; margin: 0; pointer-events: none; transform: rotate(90deg); }
.op-sidebar-select:has(select:open)::after { transform: rotate(270deg); }
.op-sidebar-ui .sidebar .filter-section { gap: 8px !important; }
.op-sidebar-ui .sidebar .discovery-advanced { margin: 0; width: 100%; }

/* Loss/Gain and grouping use the same restrained segmented choice. */
.op-sidebar-ui :is(.sidebar, .op-sidebar-drawer) .mode-toggle {
    display: flex; align-items: stretch; width: 100%; gap: 0; padding: 0;
    border: 1px solid var(--border-color-strong); border-radius: 8px;
    background: var(--bg-card); overflow: hidden; box-shadow: none;
}
.op-sidebar-ui :is(.sidebar, .op-sidebar-drawer) :is(.mode-toggle-btn, .ptm-toggle-btn) {
    flex: 1 1 0; min-width: 0; min-height: 36px; margin: 0; padding: 8px 10px;
    border: 0; border-right: 1px solid var(--border-color); border-radius: 0;
    color: var(--text-secondary); background: var(--bg-card); box-shadow: none;
    font-family: var(--font-family); font-size: .875rem; font-weight: 500;
    line-height: 1.4; text-align: center; cursor: pointer;
}
.op-sidebar-ui :is(.sidebar, .op-sidebar-drawer) :is(.mode-toggle-btn, .ptm-toggle-btn):last-child { border-right: 0; }
.op-sidebar-ui :is(.sidebar, .op-sidebar-drawer) :is(.mode-toggle-btn, .ptm-toggle-btn):hover { background: var(--straw-tint); }
.op-sidebar-ui :is(.sidebar, .op-sidebar-drawer) :is(.mode-toggle-btn, .ptm-toggle-btn).active { background: var(--primary); color: #fff; font-weight: 500; }
.op-sidebar-ui :is(.sidebar, .op-sidebar-drawer) :is(.mode-toggle-btn, .ptm-toggle-btn):focus-visible { outline: 2px solid var(--primary); outline-offset: -3px; }

/* All popouts share the study selector's frame and typography. Only their contents differ. */
.op-sidebar-overlay {
    position: fixed; top: var(--op-menubar-h, 62px); left: var(--op-sidebar-w, 281px);
    right: 0; bottom: 0; z-index: 55;
    display: flex; align-items: stretch; justify-content: flex-start;
    background: none; backdrop-filter: none; animation: none;
}
.op-sidebar-ui .op-sidebar-drawer {
    box-sizing: border-box; position: relative; display: flex; flex-direction: column;
    width: 100%; min-width: 0; max-width: none; height: 100%; min-height: 0; max-height: none;
    margin: 0; padding: 0; gap: 0; overflow: hidden;
    border: 0; border-radius: 0; background: var(--bg-card); color: var(--text-primary);
    box-shadow: -14px 0 44px rgb(39 70 89 / 14%);
    font-family: var(--font-family); font-size: .875rem; text-align: left;
    animation: opSidebarDrawerIn .18s ease;
}
.op-sidebar-overlay[hidden], .op-sidebar-drawer[hidden] { display: none !important; }
.op-sidebar-drawer-header {
    display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; flex-wrap: wrap;
    gap: 12px; min-height: 80px; margin: 0; padding: 20px 24px;
    background: var(--bg-card); border: 0; border-bottom: 1px solid var(--border-color);
}
.op-sidebar-drawer-header h2 { margin: 0; color: var(--text-primary); font-family: var(--font-family); font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.op-sidebar-drawer-header > div:first-child { flex: 1; min-width: 0; }
.op-sidebar-drawer-header :is(.cohort-modal-subtitle, .column-picker-count) { margin: 4px 0 0; font-size: .8125rem; font-weight: 400; line-height: 1.5; color: var(--text-secondary); }
.op-sidebar-drawer-close {
    display: inline-flex; flex: 0 0 32px; align-items: center; justify-content: center;
    width: 32px; height: 32px; margin: 0; padding: 6px; border: 0; border-radius: 6px;
    color: var(--text-secondary); background: transparent; cursor: pointer;
}
.op-sidebar-drawer-close svg { width: 20px; height: 20px; stroke-width: 2; }
.op-sidebar-drawer-close:hover { background: var(--straw-tint); color: var(--text-primary); }
.op-sidebar-drawer-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.op-sidebar-drawer-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0; padding: 20px 24px; }
.op-sidebar-drawer-body > :is(p, .ex-row) { max-width: 760px; }
.op-sidebar-drawer-footer {
    display: flex; flex: 0 0 auto; align-items: center; justify-content: flex-end; flex-wrap: wrap;
    gap: 12px; margin: 0; padding: 16px 24px; border: 0;
    border-top: 1px solid var(--border-color); background: var(--bg-header);
}
.op-sidebar-drawer-footer .btn, .op-sidebar-drawer-footer button {
    min-height: 40px; padding: 9px 16px; border: 1px solid var(--border-color-strong);
    border-radius: 8px; font-family: var(--font-family); font-size: .875rem;
    font-weight: 500; line-height: 1.4; cursor: pointer;
    background: var(--bg-card); color: var(--text-primary);
}
.op-sidebar-drawer-footer .btn-secondary, .op-sidebar-drawer-footer .op-sidebar-drawer-done { background: var(--bg-card); color: var(--text-primary); }
.op-sidebar-drawer-footer .btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.op-sidebar-drawer-footer button:hover { filter: brightness(.98); }
.op-sidebar-drawer-footer button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.op-sidebar-drawer-body .control-group { padding: 0 0 20px; gap: 8px; }
.op-sidebar-drawer-body .control-group > label:not(.checkbox-label) { font-size: .6875rem; font-weight: 600; letter-spacing: .07em; color: var(--text-secondary); }
.op-sidebar-drawer-body .checkbox-label { font-size: .875rem; font-weight: 400; text-transform: none; letter-spacing: normal; line-height: 1.5; }
.op-sidebar-drawer-body .checkbox-group { gap: 12px; }
#discovery-advanced-controls { display: grid; grid-template-columns: minmax(0, 520px); gap: 0; padding: 0; }
#discovery-advanced-controls #loss-type-control-group:not([style*="display: none"]) { display: flex !important; }
#sidebar-advanced-panel .op-sidebar-drawer-body > p { max-width: 65ch; color: var(--text-secondary); line-height: 1.6; }
.op-sidebar-drawer-body .ex-row { margin-bottom: 20px; }
.op-sidebar-drawer-body .ex-status { margin: 12px 0; }
.column-picker-options fieldset { max-width: 760px; }
@keyframes opSidebarDrawerIn { from { transform: translateX(-14px); opacity: .4; } to { transform: translateX(0); opacity: 1; } }
@media (max-width: 760px) {
    .op-sidebar-overlay { left: 0; z-index: 110; }
    .op-sidebar-drawer-header, .op-sidebar-drawer-body { padding: 16px; }
    .op-sidebar-drawer-footer { padding: 12px 16px; }
    .op-sidebar-drawer-header { min-height: 72px; }
}
@media (prefers-reduced-motion: reduce) { .op-sidebar-ui .op-sidebar-drawer { animation: none; } }

/* Utility actions sit below the filters and share their typography. */
.op-sidebar-actions { display: grid; gap: 6px; margin-top: auto; padding: 12px 0 4px; border-top: 1px solid var(--border-color); }
.op-sidebar-ui .op-sidebar-actions #btn-reset-filters { justify-content: center; height: 36px; min-height: 36px; border-color: transparent; background: transparent; color: var(--text-secondary); }
.op-sidebar-ui .op-sidebar-actions #btn-reset-filters:hover { color: var(--text-primary); background: var(--straw-tint); }
.op-sidebar-ui .op-sidebar-actions #btn-hotspots-export { background: var(--straw-tint); border-color: var(--border-color); color: var(--primary); }
.op-sidebar-ui .op-sidebar-actions #btn-hotspots-export:hover { border-color: var(--primary); }
@media (max-width: 760px) { .op-sidebar-actions { grid-template-columns: 1fr 1fr; margin-top: 12px; } }
/* Keep utility actions within reach, directly after the filter controls. */
.op-sidebar-ui .sidebar .filter-section { flex-grow: 0; }
.op-sidebar-actions { margin-top: 12px; padding-top: 12px; }
.op-sidebar-ui .op-sidebar-actions #btn-reset-filters { justify-content: flex-start; height: 40px; min-height: 40px; border-color: var(--border-color); background: var(--bg-card); color: var(--text-secondary); }
.op-sidebar-ui .op-sidebar-actions #btn-reset-filters::before { content: ''; width: 16px; height: 16px; flex: 0 0 16px; background: currentColor; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 10a9 9 0 1 1 2 8M3 4v6h6' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; }
.op-sidebar-ui .sidebar-footer { margin-top: auto; }
.cohort-modal-header > div:first-child { display: flex; align-items: center; gap: 10px; }
.cohort-heading-help { position: relative; flex: 0 0 auto; }
.cohort-heading-help summary { display: flex; align-items: center; justify-content: center; width: 20px; height: 20px; border: 1px solid var(--border-color-strong); border-radius: 50%; color: var(--text-secondary); font-size: .75rem; font-weight: 500; list-style: none; cursor: pointer; }
.cohort-heading-help summary::-webkit-details-marker { display: none; }
.cohort-heading-help summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.cohort-heading-help > p { display: none; position: absolute; z-index: 5; top: 26px; right: 0; width: min(290px, 65vw); margin: 0; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-card); box-shadow: 0 6px 20px rgb(0 0 0 / 10%); color: var(--text-secondary); font-size: .8125rem; font-weight: 400; line-height: 1.5; }
.cohort-heading-help[open] > p { display: block; }
@media (hover: hover) { .cohort-heading-help:hover > p { display: block; } }

/* Export is a utility action rather than a highlighted analysis control. */
.op-sidebar-ui .op-sidebar-actions #btn-hotspots-export { min-height: 40px; height: 40px; background: var(--bg-card); border-color: var(--border-color); color: var(--text-secondary); }
.op-sidebar-ui .op-sidebar-actions #btn-hotspots-export:hover { background: var(--straw-tint); border-color: var(--primary); color: var(--text-primary); }
.op-sidebar-ui .op-sidebar-actions #btn-hotspots-export::before { content: ''; flex: 0 0 16px; width: 16px; height: 16px; background: currentColor; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3v12m-4-4 4 4 4-4M4 16v4h16v-4' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; }
