/* calendar-popup.css */
.calendar-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 32px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.15);
    width: 90%;
    max-width: 820px;
    z-index: 2000;
    display: none;
    padding: 1rem 1.5rem 1rem;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid #eaeaea;
}

.calendar-popup.show {
    display: block;
    animation: fadeScale 0.25s ease;
}

@keyframes fadeScale {
    from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #f0f0f0;
}

.popup-header h3 {
    font-size: 1.8rem;
    font-weight: 300;
    color: #333333;
    letter-spacing: 1px;
    margin: 0;
}

.close-popup {
    background: none;
    border: none;
    font-size: 2.2rem;
    cursor: pointer;
    color: #999999;
    transition: 0.2s;
    line-height: 1;
}

.close-popup:hover { 
    color: #097684;
}

.calendar-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.month-box {
    background: #ffffff;
    border-radius: 24px;
    padding: 1.2rem;
    min-height: 400px;
    border: 1px solid #eeeeee;
}

.month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.month-year {
    font-weight: 500;
    color: #097684;
    font-size: 1.2rem;
}

.month-nav-btn {
    background: white;
    border: 1px solid #dddddd;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
    color: #666666;
}

.month-nav-btn:hover:not(:disabled) {
    background: #097684;
    color: white;
    border-color: #097684;
}

.month-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.weekdays {
    display: grid;
    grid-template-columns: repeat(7,1fr);
    text-align: center;
    font-weight: 500;
    font-size: 0.8rem;
    color: #666666;
    margin: 0.5rem 0;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(7,1fr);
    gap: 0;
}

.day {
    aspect-ratio: 1/1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 0;
    cursor: pointer;
    font-size: 0.9rem;
    transition: 0.15s;
    border: 1px solid transparent;
    position: relative;
    font-weight: 400;
    color: #333333;
    box-sizing: border-box;
    margin: 0;
    width: 100%;
    height: 100%;
}

.day .label {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-top: -2px;
    color: #666666;
}

.day:hover:not(.empty):not(.disabled) {
    background: #097684;
    border-color: #cccccc;
    color: white;
    border-radius: 0;
}

.day.empty {
    background: transparent;
    cursor: default;
}

.day.disabled {
    background: #f5f5f5;
    color: #bbbbbb;
    cursor: not-allowed;
}

.day.check-in {
    background: #097684;
    color: white;
    font-weight: 500;
    border-radius: 30px 0 0 30px;
}

.day.check-out {
    background: #097684;
    color: white;
    font-weight: 500;
    border-radius: 0 30px 30px 0;
}

.day.check-in.check-out {
    border-radius: 30px;
}

.day.check-in .label, .day.check-out .label {
    color: rgba(255,255,255,0.9);
}

.day.in-range {
    background: #e8f4f7;
    border-radius: 0;
    margin: 0;
    width: 100%;
}

.day.in-range + .day.in-range {
    border-left: none;
}

.day.check-in.in-range {
    border-radius: 30px 0 0 30px;
}

.day.check-out.in-range {
    border-radius: 0 30px 30px 0;
}

.day.today {
    color: #097684;
    font-weight: 600;
}

.popup-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    border-top: 1px solid #f0f0f0;
    padding-top: 1rem;
}

.night-count {
    background: #f5f5f5;
    border-radius: 40px;
    padding: 0.8rem 1.5rem;
    font-weight: 400;
    color: #333333;
}

.night-count span {
    color: #097684;
    font-weight: 600;
}

.search-btn {
    background: #097684;
    border: none;
    color: white;
    padding: 1rem 2.8rem;
    border-radius: 40px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
}

.search-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.search-btn:hover:not(:disabled) {
    background: #065a66;
}

.popup-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 1999;
    display: none;
}

.popup-overlay.show {
    display: block;
}

/* Prevent body scroll when popup is open */
body.no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

@media (max-width: 1000px) {
    .calendar-container { 
        grid-template-columns: 1fr; 
    }
    
    .popup-footer {
        display: flex;
    }
    
    .days-grid {
        gap: 0;
    }
}

/* Tablet Portrait (600px - 768px) */
@media (min-width: 600px) and (max-width: 768px) {
    .calendar-popup {
        max-width: 520px;
        padding: 0.8rem 1rem;
        border-radius: 28px;
    }
    
    .popup-header h3 {
        font-size: 1.6rem;
    }
    
    .close-popup {
        font-size: 2rem;
    }
    
    .month-box {
        min-height: 320px;
        padding: 0.8rem;
        border-radius: 20px;
    }
    
    .month-year {
        font-size: 1rem;
    }
    
    .month-nav-btn {
        width: 30px;
        height: 30px;
        font-size: 0.85rem;
    }
    
    .weekdays {
        font-size: 0.75rem; /* Slightly larger */
        margin: 0.2rem 0;
    }
    
    .days-grid {
        gap: 0;
    }
    
    .day {
        font-size: 0.85rem; /* Larger */
        width: 100%;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
    }
    
    .day .label {
        font-size: 0.5rem; /* Larger */
        margin-top: -2px;
    }
    
    .popup-footer {
        display: flex;
        gap: 0.8rem;
        align-items: stretch;
    }
    
    .night-count {
        text-align: center;
        padding: 0.6rem 1rem;
        font-size: 1rem; /* Larger */
    }
    
    .search-btn {
        padding: 0.8rem 1.5rem;
        width: 100%;
        font-size: 1rem; /* Larger */
    }
}

/* Large Phones (480px - 600px) */
@media (min-width: 480px) and (max-width: 600px) {
    .calendar-popup {
        max-width: 450px;
        padding: 0.6rem 0.8rem;
        border-radius: 24px;
    }
    
    .popup-header {
        margin-bottom: 0.8rem;
        padding-bottom: 0.3rem;
    }
    
    .popup-header h3 {
        font-size: 1.4rem; /* Larger */
    }
    
    .close-popup {
        font-size: 1.8rem; /* Larger */
    }
    
    .calendar-container {
        gap: 1rem;
    }
    
    .month-box {
        min-height: 280px;
        padding: 0.6rem;
        border-radius: 16px;
    }
    
    .month-header {
        margin-bottom: 0.4rem;
    }
    
    .month-year {
        font-size: 0.95rem; /* Larger */
    }
    
    .month-nav-btn {
        width: 28px; /* Slightly larger */
        height: 28px; /* Slightly larger */
        font-size: 0.8rem; /* Larger */
    }
    
    .weekdays {
        font-size: 0.75rem; /* Larger */
        margin: 0.2rem 0;
    }
    
    .days-grid {
        gap: 0;
    }
    
    .day {
        font-size: 0.8rem; /* Larger */
        width: 100%;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
    }
    
    .day .label {
        font-size: 0.5rem; /* Larger */
        margin-top: -2px;
        font-weight: 600;
    }
    
    .popup-footer {
        display: flex;
        gap: 0.6rem;
        margin-top: 0.8rem;
        padding-top: 0.6rem;
    }
    
    .night-count {
        text-align: center;
        padding: 0.6rem 0.8rem; /* Slightly larger padding */
        font-size: 0.9rem; /* Larger */
    }
    
    .search-btn {
        padding: 0.8rem 1rem; /* Slightly larger padding */
        width: 100%;
        font-size: 0.9rem; /* Larger */
    }
}

/* Small Phones (320px - 480px) */
@media (max-width: 480px) {
    .calendar-popup {
        max-width: 95%;
        padding: 0.5rem 0.6rem; /* Slightly more padding */
        border-radius: 20px; /* Slightly larger */
        max-height: 95vh;
    }
    
    .popup-header {
        margin-bottom: 0.6rem;
        padding-bottom: 0.2rem;
    }
    
    .popup-header h3 {
        font-size: 1.3rem; /* Larger */
    }
    
    .close-popup {
        font-size: 1.6rem; /* Larger */
    }
    
    .calendar-container {
        gap: 0.8rem;
        margin-bottom: 0.8rem;
    }
    
    .month-box {
        min-height: 260px; /* Slightly taller */
        padding: 0.5rem; /* Slightly more padding */
        border-radius: 16px; /* Slightly larger */
    }
    
    .month-header {
        margin-bottom: 0.4rem;
    }
    
    .month-year {
        font-size: 0.9rem; /* Larger */
    }
    
    .month-nav-btn {
        width: 28px; /* Larger */
        height: 28px; /* Larger */
        font-size: 0.75rem; /* Larger */
    }
    
    .weekdays {
        font-size: 0.7rem; /* Larger */
        margin: 0.2rem 0;
    }
    
    .days-grid {
        gap: 0;
    }
    
    .day {
        font-size: 0.75rem; /* Larger */
        width: 100%;
        padding: 0;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
    }
    
    .day .label {
        font-size: 0.45rem; /* Larger */
        margin-top: -2px;
        font-weight: 600;
    }
    
    /* Adjust selection states for small screens */
    .day.check-in {
        border-radius: 24px 0 0 24px; /* Adjusted for larger size */
    }
    
    .day.check-out {
        border-radius: 0 24px 24px 0; /* Adjusted for larger size */
    }
    
    .day.check-in.check-out {
        border-radius: 24px;
    }
    
    .day.check-in.in-range {
        border-radius: 24px 0 0 24px;
    }
    
    .day.check-out.in-range {
        border-radius: 0 24px 24px 0;
    }
    
    .popup-footer {
        display: flex;
        gap: 0.5rem;
        margin-top: 0.6rem;
        padding-top: 0.5rem;
    }
    
    .night-count {
        text-align: center;
        padding: 0.5rem 0.7rem; /* Larger padding */
        font-size: 0.85rem; /* Larger */
        width: 100%;
        box-sizing: border-box;
    }
    
    .night-count span {
        display: inline-block;
        margin-left: 0.2rem;
    }
    
    .search-btn {
        padding: 0.7rem 0.9rem; /* Larger padding */
        width: 100%;
        font-size: 0.85rem; /* Larger */
    }
}

/* Very Small Phones (below 320px) */
@media (max-width: 320px) {
    .calendar-popup {
        padding: 0.4rem 0.4rem;
    }
    
    .popup-header h3 {
        font-size: 1.1rem; /* Larger */
    }
    
    .month-box {
        min-height: 220px;
        padding: 0.4rem;
    }
    
    .month-year {
        font-size: 0.8rem; /* Larger */
    }
    
    .month-nav-btn {
        width: 24px; /* Slightly larger */
        height: 24px; /* Slightly larger */
        font-size: 0.7rem; /* Larger */
    }
    
    .weekdays {
        font-size: 0.65rem; /* Larger */
    }
    
    .days-grid {
        gap: 0;
    }
    
    .day {
        font-size: 0.7rem; /* Larger */
        width: 100%;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
    }
    
    .day .label {
        font-size: 0.4rem; /* Larger */
        margin-top: -2px;
    }
    
    .popup-footer {
        display: flex;
        gap: 0.4rem;
    }
    
    .night-count {
        font-size: 0.75rem; /* Larger */
        padding: 0.4rem 0.5rem;
    }
    
    .search-btn {
        padding: 0.5rem 0.6rem;
        font-size: 0.75rem; /* Larger */
    }
}

/* Touch-friendly improvements for mobile devices */
@media (max-width: 768px) {
    .days-grid {
        gap: 0;
    }
    
    .day {
        width: 100%;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
        min-height: 36px; /* Ensure minimum touch target size */
        min-width: 36px; /* Ensure minimum touch target size */
    }
    
    .day:active:not(.empty):not(.disabled) {
        transform: scale(0.95);
        background: #065a66;
        border-radius: 0;
    }
    
    .month-nav-btn:active:not(:disabled) {
        transform: scale(0.9);
    }
    
    .close-popup:active {
        transform: scale(0.9);
        color: #065a66;
    }
    
    .search-btn:active:not(:disabled) {
        transform: scale(0.98);
    }
    
    .popup-footer {
        display: flex;
    }
}

/* Landscape orientation for phones */
@media (max-width: 900px) and (orientation: landscape) {
    .calendar-popup {
        max-width: 90%;
        max-height: 85vh;
    }
    
    .calendar-container {
        grid-template-columns: 1fr 1fr;
    }
    
    .month-box {
        min-height: 180px;
    }
    
    .days-grid {
        gap: 0;
    }
    
    .day {
        width: 100%;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
        font-size: 0.8rem; /* Ensure readable in landscape */
    }
    
    .popup-footer {
        display: flex;
        padding-bottom: 0.5rem;
    }
}

/* Handle devices with notches */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .calendar-popup {
            padding-left: max(0.6rem, env(safe-area-inset-left));
            padding-right: max(0.6rem, env(safe-area-inset-right));
            padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
        }
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .calendar-popup {
        border-width: 0.5px;
    }
    
    .day.today {
        border-width: 1.5px;
    }
}