/* Toolbar Layout & Offsets */
body.toolbar-active {
    padding-top: 140px; /* Extra offset so page header isn't hidden under toolbar */
}

body.toolbar-active:not(.admin-bar) {
    padding-top: 120px; /* Just toolbar */
}

body.toolbar-minimized {
    padding-top: 64px; /* 32px admin bar + condensed toolbar header */
}

body.toolbar-minimized:not(.admin-bar) {
    padding-top: 40px; /* Just minimized toolbar header */
}

/* Fixed Toolbar Shell */
.fixed-toolbar {
    position: fixed;
    top: 32px;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #000435 0%, #33A7B5 100%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999; /* Below WP admin bar (99999) but above page content */
    transition: box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

body:not(.admin-bar) .fixed-toolbar {
    top: 0;
}

.fixed-toolbar .toolbar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: rgba(0, 4, 53, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.25);
    gap: 10px;
    min-height: 44px; /* Ensure consistent height */
    position: relative;
}

.fixed-toolbar .toolbar-title {
    color: #FFFFFF;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: none; /* Don't block clicks */
}

.fixed-toolbar .toolbar-toggle {
    background: #FFFFFF;
    border: 2px solid #000435;
    color: #000435;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer !important;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto !important;
    position: relative;
    z-index: 100000; /* ABOVE EVERYTHING including WP admin bar */
    flex-shrink: 0;
    user-select: none;
}

.fixed-toolbar .toolbar-toggle:hover {
    background: #FFF5CB;
    border-color: #33A7B5;
    transform: scale(1.05);
}

.fixed-toolbar .toolbar-toggle:active {
    transform: scale(0.95);
}

/* Facility Selector */
.fixed-toolbar .facility-selector {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.fixed-toolbar .facility-dropdown {
    min-width: 170px;
    max-width: 240px;
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.95);
    color: #000435;
    font-size: 13px;
    cursor: pointer;
    height: 32px;
}

.fixed-toolbar .facility-selector .btn-toolbar {
    width: 32px;
    height: 32px;
    padding: 4px;
    min-width: 32px;
    min-height: 32px;
}

/* Toolbar Content */
.fixed-toolbar .toolbar-content {
    padding: 10px 16px;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    max-height: 1000px;
    overflow-x: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.fixed-toolbar .toolbar-section {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    position: relative;
}

.fixed-toolbar .toolbar-group {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
}

.fixed-toolbar .toolbar-group.facility-nav-group {
    flex-grow: 0;
    position: relative;
    left: auto;
    transform: none;
    order: 1;
    width: 100%;
    justify-content: center;
    margin-top: 4px;
}

.fixed-toolbar .toolbar-label {
    display: none;
}

.fixed-toolbar .btn-toolbar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0;
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 8px;
    border: 2px solid #33A7B5;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #FFFFFF;
    color: #000435;
    box-shadow: 0 2px 4px rgba(51, 167, 181, 0.2);
    flex-shrink: 0;
    white-space: nowrap;
    text-align: center;
    overflow: hidden;
}

.fixed-toolbar .btn-toolbar:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(51, 167, 181, 0.3);
    background: #FFF5CB;
}

.fixed-toolbar .btn-toolbar.btn-primary {
    background: #33A7B5;
    color: #FFFFFF;
    border-color: #33A7B5;
}

.fixed-toolbar .btn-toolbar.btn-primary:hover {
    background: #000080;
    color: #FFFFFF;
    box-shadow: 0 4px 10px rgba(51, 167, 181, 0.4);
}

.fixed-toolbar .btn-toolbar.btn-secondary {
    background: #F2EEDF;
    color: #000435;
    border-color: #33A7B5;
}

.fixed-toolbar .btn-toolbar.btn-secondary:hover {
    background: #E6DCC7;
    color: #000435;
    box-shadow: 0 4px 10px rgba(51, 167, 181, 0.4);
}

.fixed-toolbar .btn-toolbar.btn-success {
    background: #B2E102;
    color: #000435;
    border-color: #33A7B5;
}

.fixed-toolbar .btn-toolbar.btn-success:hover {
    background: #9AC000;
    color: #000435;
    box-shadow: 0 4px 10px rgba(178, 225, 2, 0.4);
}

.fixed-toolbar .btn-toolbar.btn-danger {
    background: #FE8088;
    color: #000435;
    border-color: #FE8088;
}

.fixed-toolbar .btn-toolbar.btn-danger:hover {
    background: #FA5F69;
    color: #000435;
    box-shadow: 0 4px 10px rgba(254, 128, 136, 0.4);
}

/* Minimized state */
.fixed-toolbar.minimized {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.fixed-toolbar.minimized .toolbar-header {
    border-bottom: none;
}

.fixed-toolbar.minimized .toolbar-toggle {
    background: #EF9034 !important;
    color: #FFFFFF !important;
    border-color: #B2E102 !important;
    pointer-events: auto !important; /* Force clickable */
    cursor: pointer !important;
}

.fixed-toolbar.minimized .toolbar-content {
    /* Don't use display:none - it breaks the toggle! */
    height: 0 !important;
    max-height: 0 !important;
    min-height: 0 !important;
    opacity: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
    line-height: 0 !important;
}

.fixed-toolbar.minimized .btn-toolbar {
    box-shadow: none;
}

/* Toolbar Navigation Buttons */
.toolbar-nav-btn {
    opacity: 1;
    transition: opacity 0.2s ease;
}

.toolbar-nav-btn:disabled {
    opacity: 0.5;
}

/* Toolbar Dropdown States */
.toolbar-dropdown-no-project {
    cursor: pointer;
    color: #33A7B5;
}

/* Toolbar Expandable Section */
.toolbar-expandable-collapsed {
    display: none;
}

.toolbar-expandable-expanded {
    display: block;
}

/* Facility Navigation Buttons - Multi-facility display control */
.facility-nav-btn-hidden {
    display: none;
}

.facility-nav-btn-visible {
    display: inline-block;
}

/* Embedded toolbar toggle inside the form controls */
.facility-toolbar-expandable {
    display: none;
}

.facility-toolbar-expandable > .d-flex,
.facility-toolbar-expandable > .controls {
    margin-top: 10px;
}

#facility-toolbar-toggle {
    min-width: auto;
    padding: 4px 8px;
    font-size: 16px;
}

/* Aggressive space-saving for mobile screens <= 768px */
@media (max-width: 768px) {
    .fixed-toolbar .toolbar-header {
        padding: 4px 8px;
        min-height: 32px;
    }

    .fixed-toolbar .toolbar-title {
        font-size: 11px;
    }

    .fixed-toolbar .toolbar-title #toolbar-project-name {
        display: none;
    }

    .fixed-toolbar .toolbar-toggle {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .fixed-toolbar .toolbar-content {
        padding: 6px 10px;
        overflow-x: auto;
    }

    .fixed-toolbar .toolbar-section {
        gap: 6px;
    }

    .fixed-toolbar .toolbar-group {
        gap: 4px;
    }

    .fixed-toolbar .toolbar-group.facility-nav-group {
        justify-content: center;
        order: 1;
        width: 100%;
    }

    .fixed-toolbar .toolbar-label {
        display: none;
    }

    .fixed-toolbar .facility-dropdown {
        min-width: 110px;
        max-width: 150px;
        font-size: 12px;
        padding: 4px 8px;
        height: 32px;
    }
}

/* Small-screen tweaks that keep the toolbar in one row */
@media (max-width: 640px) {
    body.toolbar-active {
        padding-top: 200px;
    }

    .fixed-toolbar .toolbar-header {
        padding: 10px 15px;
        flex-wrap: wrap;
    }

    .fixed-toolbar .toolbar-title {
        font-size: 14px;
        flex: 1;
    }

    .fixed-toolbar .toolbar-content {
        padding: 6px 10px;
    }

    .fixed-toolbar .toolbar-section {
        gap: 8px;
        flex-wrap: wrap;
    }

    .fixed-toolbar .toolbar-group {
        gap: 8px;
        flex-wrap: nowrap;
        flex: 0 0 auto;
    }

    .fixed-toolbar .toolbar-group.facility-nav-group {
        width: 100%;
        order: 1;
        justify-content: center;
    }

    .fixed-toolbar .toolbar-label {
        font-size: 13px;
    }

    .fixed-toolbar .facility-dropdown {
        min-width: 90px;
        max-width: 140px;
        font-size: 12px;
        padding: 4px 8px;
        height: 34px;
    }

    .fixed-toolbar .facility-selector .btn-toolbar {
        width: 32px;
        height: 32px;
        font-size: 12px;
        padding: 0;
        min-width: 32px;
        min-height: 32px;
    }

    .fixed-toolbar .btn-toolbar {
        flex: 1 1 0;
        aspect-ratio: 1;
        min-width: 28px;
        max-width: 48px;
        width: auto;
        height: auto;
        min-height: 28px;
        font-size: 14px;
        padding: 0;
    }
}
