/* Z-Index Hierarchy System - Comprehensive Layer Management */

/*
 * Z-Index Layer System:
 * Layer 0-99: Content and static elements
 * Layer 100-199: Sticky/floating elements
 * Layer 200-299: Calendar and interactive components
 * Layer 300-399: Overlays and selections
 * Layer 400-499: Navigation and controls
 * Layer 500-999: Modals and popups
 * Layer 1000+: Critical system overlays
 */

:root {
    /* Base Content Layers (0-99) */
    --z-base: 0;
    --z-content: 1;
    --z-cards: 2;
    --z-elevated: 5;

    /* Sticky/Floating Elements (100-199) */
    --z-sticky-header: 100;
    --z-sticky-sidebar: 105;
    --z-floating-button: 110;
    --z-pricing-controls: 120;
    --z-sticky-cart: 115; /* Between floating button and pricing controls */
    --z-sticky-table-column: 400; /* Higher than calendar selections to prevent overlap */

    /* Calendar and Interactive (200-299) */
    --z-calendar-base: 200;
    --z-calendar-header: 210;
    --z-calendar-cell: 220;
    --z-calendar-selection: 230;
    --z-calendar-tooltip: 240;

    /* Overlays and Selections (300-399) */
    --z-selection-overlay: 300;
    --z-dropdown: 310;
    --z-popover: 320;
    --z-selection-range: 330;

    /* Navigation and Controls (400-499) */
    --z-navigation: 400;
    --z-mobile-nav: 410;
    --z-search-controls: 420;
    --z-sticky-cart-alternate: 450; /* Alternate position between nav and modals */

    /* Modals and Popups (500-999) */
    --z-modal-backdrop: 500;
    --z-modal: 510;
    --z-modal-header: 520;
    --z-toast: 800;
    --z-notification: 850;

    /* Critical System (1000+) */
    --z-debug: 1000;
    --z-system-modal: 1100;
    --z-emergency: 9999;
}

/* Apply hierarchy to specific components */

/* Base content */
#roomsList {
    z-index: var(--z-content);
}

.fluent-card {
    z-index: var(--z-cards);
    position: relative;
}

/* Sticky elements */
.pricing-controls {
    z-index: var(--z-pricing-controls) !important;
}

.calendar-header-row {
    z-index: var(--z-calendar-header) !important;
}

.room-header-cell {
    z-index: var(--z-sticky-header) !important;
}

/* Calendar system - CRITICAL FIX */
.availability-table-redesigned {
    z-index: var(--z-calendar-base);
    position: relative;
}

.availability-cell-redesigned {
    z-index: var(--z-calendar-cell);
    position: relative;
    /* REMOVE transform that causes overlapping */
    transform: none !important;
}

/* Enhanced selection states with proper z-index */
.availability-cell-redesigned.check-in {
    z-index: var(--z-calendar-selection) !important;
    /* Use border and background instead of transform for emphasis */
    border-width: 2px !important;
    box-shadow: none !important; /* Comment #19: Flat design - no shadows */
}

.availability-cell-redesigned.check-out {
    z-index: var(--z-calendar-selection) !important;
    border-width: 1px !important;
    box-shadow: none !important; /* Comment #19: Flat design - no shadows */
}

.availability-cell-redesigned.in-range {
    z-index: var(--z-selection-range) !important;
    border-width: 1px !important;
    box-shadow: none !important; /* Comment #19: Flat design - no shadows */
}

/* Mobile components */
.mobile-search-button {
    z-index: var(--z-floating-button) !important;
}

.mobile-search-modal {
    z-index: var(--z-modal) !important;
}

.mobile-search-modal .modal-backdrop {
    z-index: var(--z-modal-backdrop) !important;
}

/* Navigation */
.navbar {
    z-index: var(--z-navigation) !important;
}

/* Search controls and integrated search panel */
.integrated-search-panel {
    z-index: var(--z-search-controls) !important;
    position: relative;
}

.date-range-display {
    z-index: var(--z-search-controls) !important;
    position: relative;
    align-content: center;
}

/* Skeleton loading */
.skeleton-container {
    z-index: var(--z-content);
    position: relative;
}

/* Debug components */
.optimization-suggestions {
    z-index: var(--z-debug) !important;
}

/* Tooltips and popovers */
.tooltip {
    z-index: var(--z-calendar-tooltip) !important;
}

.popover {
    z-index: var(--z-popover) !important;
}

/* Prevent calendar cell overlapping during scroll */
.availability-cell-redesigned:hover {
    /* Use subtle visual feedback without transform */
    filter: brightness(1.1);
    transition: filter 0.2s ease;
    /* Keep in same layer to prevent overlap */
    z-index: var(--z-calendar-cell);
}

/* Override hover effects for unavailable cells */
.availability-cell-redesigned.unavailable:hover,
.availability-cell-redesigned.in-range.unavailable:hover {
    /* Remove all hover effects on unavailable cells */
    filter: none !important;
    transform: none !important;
    cursor: not-allowed !important;
}

/* Ensure sticky elements stay above calendar */
.sticky {
    z-index: var(--z-sticky-header) !important;
}

/* Scroll to Top Button */
.scroll-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3.5rem;
    height: 3.5rem;
    /* Comment #19: Flat design - solid olive green, no gradients */
    background-color: #6B8E23;
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow:
        0 4px 16px rgba(0, 120, 212, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    z-index: var(--z-floating-button);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    backdrop-filter: blur(10px);
}

/* Show button when scrolled */
.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Hover effects */
.scroll-to-top:hover {
    /* Comment #19: Flat design - solid olive green, no gradients */
    background-color: #6B8E23;
    box-shadow:
        0 6px 20px rgba(0, 120, 212, 0.4),
        0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px) scale(1.05);
}

.scroll-to-top:active {
    transform: translateY(0) scale(0.95);
    transition-duration: 0.1s;
}

/* Dark theme support */
[data-theme="dark"] .scroll-to-top {
    background: linear-gradient(135deg, #58a6ff 0%, #4d94ff 100%);
    box-shadow:
        0 4px 16px rgba(88, 166, 255, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .scroll-to-top:hover {
    /* Comment #19: Flat design - solid olive green, no gradients */
    background-color: #6B8E23;
    box-shadow:
        0 6px 20px rgba(88, 166, 255, 0.4),
        0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .scroll-to-top {
        width: 3rem;
        height: 3rem;
        bottom: 1.5rem;
        right: 1.5rem;
        font-size: 1rem;
    }
}

/* Ultra-compact mobile (avoid interference with pricing controls) */
@media (max-width: 480px) {
    .scroll-to-top {
        width: 2.5rem;
        height: 2.5rem;
        bottom: 1rem;
        right: 1rem;
        font-size: 0.9rem;
    }
}

/* Bootstrap modal fixes */
.modal {
    z-index: var(--z-modal) !important;
}

.modal-backdrop {
    z-index: var(--z-modal-backdrop) !important;
}

/* Critical fix for scrolling overlap issues */
.calendar-container,
#calendarView,
#availabilityTableContainer {
    isolation: isolate; /* Create new stacking context */
    position: relative;
}

.availability-table-redesigned {
    /* Prevent calendar from creating its own stacking context that interferes */
    isolation: auto;
    position: relative;
    contain: layout style; /* Optimize rendering performance */
}

/* Fix for any remaining transform issues */
.availability-cell-redesigned * {
    /* Ensure child elements don't inherit problematic transforms */
    transform: none;
}

/* Fix for mobile bottom navigation */
.mobile-bottom-nav {
    z-index: var(--z-mobile-nav) !important;
}

/* Ensure proper layering during scroll */
.scroll-container {
    /* Ensure scrolling doesn't affect z-index behavior */
    transform: translateZ(0);
    backface-visibility: hidden;
}