/* ===== MOBILE/TABLET RESPONSIVENESS ===== */

/* --- Slide-out Sidebar --- */
#mobileSidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    background: #f0f4ff;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
}
#mobileSidebar.open {
    transform: translateX(0);
}
#mobileSidebarOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#mobileSidebarOverlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* --- Background Contrast Improvement --- */
@media (max-width: 1023px) {
    .bg-surface, #page-dashboard main {
        background-color: #e8edf8 !important;
    }
    .bg-geometric {
        background-color: #e8edf8 !important;
        background-image: radial-gradient(circle at 2px 2px, #cdd8f0 1px, transparent 0) !important;
    }
}

/* --- Info Boxes (Stats) Responsive --- */
@media (max-width: 640px) {
    /* Compact stat cards on mobile */
    #section-kalendar .grid.grid-cols-2 > div {
        padding: 0.75rem !important;
    }
    #section-kalendar .grid.grid-cols-2 > div .w-10 {
        width: 2rem !important;
        height: 2rem !important;
        margin-bottom: 0.375rem !important;
    }
    #section-kalendar .grid.grid-cols-2 > div .w-10 .material-symbols-outlined {
        font-size: 18px !important;
    }
    #section-kalendar .grid.grid-cols-2 > div .text-2xl {
        font-size: 1.25rem !important;
    }
    #section-kalendar .grid.grid-cols-2 > div .text-sm {
        font-size: 0.65rem !important;
    }
    /* Reduce gap */
    #section-kalendar > div:first-child .grid.grid-cols-2 {
        gap: 0.5rem !important;
    }
}

/* --- Calendar Mobile Responsiveness --- */
@media (max-width: 768px) {
    /* Calendar container */
    #calendarGrid {
        font-size: 0.7rem;
    }
    /* Day cells */
    #calendarGrid > div {
        min-height: 60px !important;
        padding: 2px !important;
    }
    /* Day numbers */
    #calendarGrid > div > span.text-lg {
        font-size: 0.75rem !important;
    }
    /* Event chips in calendar */
    #calendarGrid .text-\[10px\] {
        font-size: 7px !important;
        padding: 1px 2px !important;
        line-height: 1.2 !important;
    }
    /* Day header names */
    #calendarGrid > div.text-center.text-\[10px\] {
        font-size: 8px !important;
        padding: 4px 0 !important;
    }
    /* Today badge */
    .text-primary.bg-primary\/10 {
        font-size: 7px !important;
        padding: 1px 3px !important;
    }
    /* Calendar title bar */
    #calendarMonth {
        font-size: 1rem !important;
    }
    /* Calendar card padding */
    .lg\:col-span-10.bg-white {
        padding: 0.75rem !important;
    }
    /* View toggle buttons */
    #viewToggle button {
        padding: 0.375rem 0.75rem !important;
        font-size: 0.75rem !important;
    }
    /* New event button */
    #newEventBtn {
        padding: 0.375rem 0.75rem !important;
        font-size: 0.75rem !important;
    }
    #newEventBtn .material-symbols-outlined {
        font-size: 14px !important;
    }
}

@media (max-width: 480px) {
    #calendarGrid > div {
        min-height: 46px !important;
    }
    #calendarGrid > div > span.text-lg {
        font-size: 0.65rem !important;
    }
    #calendarGrid .text-\[10px\] {
        font-size: 6px !important;
    }
}

/* ===== MOBILE WEEKLY CALENDAR - Single Day View ===== */
.mobile-week-view {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.mobile-week-strip {
    display: flex;
    gap: 2px;
    padding: 8px 4px;
    background: #f8f9fc;
    border-radius: 12px;
    margin-bottom: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-week-day-btn {
    flex: 1;
    min-width: 42px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 2px;
    border-radius: 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.mobile-week-day-btn:active {
    transform: scale(0.95);
}
.mobile-week-day-btn.active {
    background: #0d59f2;
    color: white;
    box-shadow: 0 2px 8px rgba(13, 89, 242, 0.3);
}
.mobile-week-day-btn.is-today:not(.active) {
    background: rgba(13, 89, 242, 0.08);
}

.mobile-week-day-name {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}
.mobile-week-day-btn.active .mobile-week-day-name {
    opacity: 1;
    color: white;
}

.mobile-week-day-num {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}

.mobile-week-day-dot {
    font-size: 8px;
    font-weight: 700;
    background: #0d59f2;
    color: white;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}
.mobile-week-day-btn.active .mobile-week-day-dot {
    background: white;
    color: #0d59f2;
}

.mobile-week-body {
    border-radius: 12px;
    background: white;
    border: 1px solid rgba(0,0,0,0.06);
}

.mobile-week-timegrid {
    position: relative;
}

.mobile-week-hours {
    position: relative;
}

.mobile-week-hour-row {
    display: flex;
    align-items: flex-start;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}

.mobile-week-hour-label {
    width: 46px;
    flex-shrink: 0;
    font-size: 10px;
    color: #8898aa;
    font-weight: 500;
    text-align: right;
    padding-right: 8px;
    padding-top: 0;
    margin-top: -6px;
}

.mobile-week-hour-line {
    flex: 1;
    height: 1px;
    background: rgba(0,0,0,0.04);
}

.mobile-week-ghost {
    position: absolute;
    left: 0;
    right: 0;
    border-radius: 8px;
    border: 1px dashed rgba(13, 89, 242, 0.25);
    background: rgba(13, 89, 242, 0.04);
    cursor: pointer;
    padding: 4px 8px;
    z-index: 0;
}
.mobile-week-ghost:active {
    background: rgba(13, 89, 242, 0.1);
}

.mobile-week-ghost-label {
    font-size: 11px;
    font-weight: 500;
    color: rgba(13, 89, 242, 0.5);
}

.mobile-week-event {
    position: absolute;
    border-radius: 10px;
    cursor: pointer;
    overflow: hidden;
    padding: 6px 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.mobile-week-event:active {
    opacity: 0.85;
    transform: scale(0.98);
}
.mobile-week-event.pre-res {
    border: 2px dashed;
}

.mobile-week-event-name {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-week-event-time {
    font-size: 11px;
    opacity: 0.85;
    font-weight: 500;
}

.mobile-week-event-room {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 1px;
}

/* Event list below timegrid */
.mobile-week-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mobile-week-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.06);
    transition: background 0.15s;
}
.mobile-week-list-item:active {
    background: #f0f4ff;
}

.mobile-week-list-color {
    width: 4px;
    height: 32px;
    border-radius: 4px;
    flex-shrink: 0;
}

.mobile-week-list-info {
    flex: 1;
    min-width: 0;
}

.mobile-week-list-name {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-week-list-meta {
    font-size: 11px;
    color: #8898aa;
    margin-top: 1px;
}

.mobile-week-empty {
    padding: 24px;
    text-align: center;
    color: #8898aa;
    font-size: 13px;
}

/* Hide old weekly calendar horizontal scroll on mobile */
@media (max-width: 768px) {
    #weeklyCalendar {
        overflow-x: visible;
    }
    #weeklyCalendar > div {
        min-width: unset;
    }
}

/* ===== EVENT DRAWER - Complete Mobile Fix ===== */
/* Always fix: remove min-width on mobile */
@media (max-width: 768px) {
    #eventDrawer {
        min-width: unset !important;
        width: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    /* Sticky header with close button */
    #eventDrawer > div:first-child {
        position: sticky;
        top: 0;
        z-index: 20;
        background: white !important;
        flex-shrink: 0;
        padding: 0.75rem 1rem !important;
        border-bottom: 1px solid rgba(0,0,0,0.08);
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }
    /* Close button: larger touch target */
    #eventDrawer #closeDrawer {
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        background: #f0f4ff !important;
        flex-shrink: 0;
    }
    #eventDrawer #closeDrawer .material-symbols-outlined {
        font-size: 22px !important;
    }
    /* Scrollable content area */
    #eventDrawer > .flex-1,
    #eventDrawer > div.flex-1 {
        flex: 1 1 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        min-height: 0 !important;
        padding: 1rem !important;
    }
    /* Sticky footer with action buttons */
    #eventDrawer > div:last-child {
        position: sticky;
        bottom: 0;
        z-index: 20;
        background: white !important;
        flex-shrink: 0;
        padding: 0.75rem 1rem !important;
        border-top: 1px solid rgba(0,0,0,0.08);
        box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
    }
    /* Reduce inner padding */
    #eventDrawer .p-6 {
        padding: 0.75rem !important;
    }
    /* Ensure grid layouts don't break on small screens */
    #eventDrawer .grid.grid-cols-2,
    #eventDrawer .grid.grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
    /* Drawer title smaller */
    #eventDrawer #drawerTitle {
        font-size: 1rem !important;
    }
}

/* ===== ALL MODALS - Overflow Fix ===== */
@media (max-width: 640px) {
    /* Generic modal container fix */
    #employeeModal > div,
    #packageModal > div,
    #roomModal > div,
    #pinResetModal > div,
    .fixed.inset-0 > div[class*="bg-white"],
    .fixed.inset-0 > div[class*="rounded"] {
        max-height: 90vh !important;
        max-width: calc(100vw - 1rem) !important;
        overflow-y: auto !important;
        margin: auto !important;
        position: relative !important;
    }
    /* Ensure overlay modals don't go off screen */
    .fixed.inset-0.z-50 {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.5rem !important;
    }
}

/* --- Top Header Responsive --- */
@media (max-width: 640px) {
    header.h-16 {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    /* Show search on mobile too, just smaller */
    .relative.w-full.max-w-md.hidden.sm\:block {
        display: block !important;
        max-width: none !important;
    }
    .relative.w-full.max-w-md.hidden.sm\:block input {
        font-size: 0.8rem !important;
        padding: 0.375rem 0.375rem 0.375rem 2rem !important;
    }
}

/* --- Section Headers Responsive --- */
@media (max-width: 640px) {
    .text-3xl {
        font-size: 1.5rem !important;
    }
    /* Content area padding */
    .flex-1.overflow-y-auto.p-6 {
        padding: 0.75rem !important;
    }
}

/* --- Settings Tabs Responsive --- */
@media (max-width: 768px) {
    #settingsTabs {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        scrollbar-width: none;
    }
    #settingsTabs::-webkit-scrollbar {
        display: none;
    }
    #settingsTabs button {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.75rem !important;
    }
}

/* --- Gallery Filters Responsive --- */
@media (max-width: 640px) {
    #galleryFilters {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    #galleryFilters button {
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 0.75rem !important;
        padding: 0.375rem 0.75rem !important;
    }
}

/* --- Gallery Grid Responsive --- */
@media (max-width: 480px) {
    #galleriesGrid {
        grid-template-columns: 1fr !important;
    }
}

/* --- Employees Grid Responsive --- */
@media (max-width: 640px) {
    #employeesGrid {
        grid-template-columns: 1fr !important;
    }
}

/* --- Analytics Responsive --- */
@media (max-width: 640px) {
    .analytics-period-bar {
        flex-wrap: wrap;
    }
    .analytics-period-bar button {
        font-size: 0.75rem !important;
        padding: 0.375rem 0.5rem !important;
    }
    .analytics-filters {
        flex-direction: column;
        width: 100%;
    }
    .analytics-filter-select {
        width: 100% !important;
    }
}

/* --- Touch-friendly buttons --- */
@media (max-width: 768px) {
    button, a[role="button"], .nav-item {
        min-height: 40px;
    }
    /* Bottom nav larger touch targets */
    nav.lg\:hidden button {
        min-height: 52px;
        padding: 0.5rem 0 !important;
    }
}

/* --- Today Events Sidebar on Mobile --- */
@media (max-width: 1023px) {
    .lg\:col-span-2.min-w-0 {
        order: -1;
    }
    #todayEvents {
        max-height: 200px !important;
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }
    #todayEvents > * {
        flex-shrink: 0;
        width: 200px;
    }
}

/* --- Notification Dropdown Mobile --- */
@media (max-width: 480px) {
    #notificationDropdown {
        width: calc(100vw - 1rem) !important;
        right: -0.5rem !important;
    }
}

/* --- Search Results Mobile --- */
@media (max-width: 640px) {
    #searchResults {
        position: fixed !important;
        left: 0.5rem !important;
        right: 0.5rem !important;
        top: 4rem !important;
        max-height: 70vh !important;
    }
}

/* --- Room Legend Mobile --- */
@media (max-width: 640px) {
    #roomLegend {
        flex-wrap: wrap;
        gap: 0.25rem !important;
    }
    #roomLegend > * {
        font-size: 0.65rem !important;
    }
}

/* --- Permissions Section Mobile --- */
@media (max-width: 768px) {
    .roles-sidebar {
        width: 100% !important;
        max-width: none !important;
    }
    .permissions-layout {
        flex-direction: column !important;
    }
}

/* --- Tablet Tweaks (768-1024px) --- */
@media (min-width: 768px) and (max-width: 1023px) {
    .flex-1.overflow-y-auto.p-6 {
        padding: 1rem !important;
    }
    #calendarGrid > div {
        min-height: 80px !important;
    }
}
