/**
 * Global Organization → Medical Group selector bar.
 *
 * Compact sticky header on every plugin frontend page. Native-styled dropdowns
 * (no UIkit) on a single row. z-index sits below UIkit modals (1010+) and the
 * workflow-tracking sticky chrome (~1000).
 */

.ht-global-org-selector {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #ffffff;
    border-bottom: 1px solid #e5e5e5;
    padding: 4px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    font-size: 13px;
    line-height: 1.4;
}

.ht-global-org-selector__inner {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
    min-height: 28px;
}

.ht-global-org-selector__label {
    color: #6b7280;
    font-weight: 500;
    white-space: nowrap;
    margin-right: 0;
    margin-left: 8px;
    font-size: 12px;
}

.ht-global-org-selector__label:first-child,
.ht-global-org-selector__inner > .ht-global-org-selector__label:first-of-type {
    margin-left: 0;
}

.ht-global-org-selector__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.ht-global-org-selector__select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: #ffffff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='10' height='10'%3E%3Cpath fill='%236b7280' d='M6 8.5L1.5 4h9L6 8.5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 2px 22px 2px 8px;
    font-size: 13px;
    line-height: 1.4;
    color: #1f2937;
    cursor: pointer;
    min-width: 140px;
    max-width: 240px;
    height: 26px;
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ht-global-org-selector__select:hover {
    border-color: #9ca3af;
}

.ht-global-org-selector__select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.ht-global-org-selector__select:disabled {
    background-color: #f3f4f6;
    cursor: progress;
    opacity: 0.7;
}

.ht-global-org-selector__spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #d1d5db;
    border-top-color: #6b7280;
    border-radius: 50%;
    animation: ht-global-org-selector-spin 0.6s linear infinite;
}

.ht-global-org-selector__spinner[hidden] {
    display: none;
}

@keyframes ht-global-org-selector-spin {
    to { transform: rotate(360deg); }
}

/* Stack on narrow screens — keep the label visible but allow wrap */
@media (max-width: 640px) {
    .ht-global-org-selector {
        padding: 6px 12px;
    }
    .ht-global-org-selector__inner {
        flex-wrap: wrap;
        gap: 6px;
    }
    .ht-global-org-selector__select {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
    }
}

/* Sit just below the WordPress admin bar when it's showing */
.admin-bar .ht-global-org-selector {
    top: 32px;
}
@media (max-width: 782px) {
    .admin-bar .ht-global-org-selector {
        top: 46px;
    }
}

/* ------------------------------------------------------------------------
 * Scheduler-page override.
 *
 * The /scheduler/ page (and any page rendering [ht_schedule_management]) sets
 * `body { overflow: hidden; height: calc(100vh - 32px) }` and uses position:
 * fixed children at top: 0 that would cover this sticky bar.
 *
 * Strategy:
 *   1. Switch the bar to position:fixed with z-index above scheduler chrome
 *      (the scheduler uses z-index 100 for the left column, 1000 for the
 *      toggle button — we sit at 1100).
 *   2. Add `padding-top` equal to the bar's height to the body so all the
 *      page's flow content (theme nav, scheduler wrapper) starts BELOW the
 *      bar instead of behind it. `box-sizing: border-box` keeps body within
 *      `calc(100vh - 32px)` so the scheduler's locked-viewport math stays
 *      correct.
 *   3. The scheduler's own JS (`calculateAndSetHeaderPosition`) measures the
 *      theme header via `offset().top`, so it automatically positions
 *      `.hts-fixed-left-column` / `.hts-grid-scroll-area` below the new
 *      theme-nav offset — no extra adjustment needed for those elements.
 * ------------------------------------------------------------------------ */
body:has(.hts-frontend-scheduler-wrapper) .ht-global-org-selector {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1100;
}
.admin-bar:has(.hts-frontend-scheduler-wrapper) .ht-global-org-selector {
    top: 32px;
}
@media (max-width: 782px) {
    .admin-bar:has(.hts-frontend-scheduler-wrapper) .ht-global-org-selector {
        top: 46px;
    }
}

/* Push flow content (theme nav, scheduler wrapper) below the bar. */
body:has(.hts-frontend-scheduler-wrapper):has(.ht-global-org-selector) {
    padding-top: 38px !important;
    box-sizing: border-box !important;
}
