/* Mobile Responsive Styles */
@media (max-width: 768px) {

    /* Layout Adjustments */
    body {
        padding: 0.5rem;
        /* Mobile body padding */
    }

    .app-header {
        flex-direction: column;
        gap: 1rem;
    }

    .controls,
    .view-switcher,
    .actions {
        width: 100%;
        justify-content: space-between;
    }

    .view-switcher {
        background: rgba(0, 0, 0, 0.2);
        padding: 4px;
        border-radius: 10px;
    }

    .view-switcher button {
        flex: 1;
        text-align: center;
    }

    .main-content {
        flex-direction: column;
        /* overflow-x: hidden; -- Causes sticky issues */
        overflow-x: visible;
        position: static !important;
    }

    .calendar-view {
        min-height: 60vh;
        width: 100%;
        /* Ensure width */
    }

    .calendar-cell {
        padding: 2px !important;
        min-height: 60px !important;
    }

    .weekday-cell {
        padding: 0.5rem 0.1rem !important;
        font-size: 0.75rem !important;
    }

    /* --- Sidebar Mobile Drawer --- */
    .sidebar {
        /* Reset positioning for drawer */
        position: fixed;
        bottom: -100%;
        /* Hidden by default */
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        height: 70vh;
        /* Use 70% of screen height */
        max-height: 80vh;
        z-index: 1000;
        background: var(--bg-panel);
        border-top: 1px solid var(--border-highlight);
        border-radius: 20px 20px 0 0;
        padding: 1.5rem;
        box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.6);
        transition: bottom 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        overflow-y: auto;
        flex: none;
        gap: 1.5rem;
    }

    .sidebar.show {
        bottom: 0;
    }

    /* Mobile Overlay */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
        display: none;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.show {
        color: white;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        z-index: 900;
        border: none;
        cursor: pointer;
        transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
        /* Rich Effect Base */
        background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
        box-shadow: 0 4px 15px var(--accent-glow), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    }

    /* Mobile FAB Base */
    .mobile-fab {
        position: fixed;
        bottom: 1.5rem;
        width: 3rem;
        height: 3rem;
        border-radius: 50%;
        border: 1px solid rgba(255, 255, 255, 0.25);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        color: white;
        z-index: 1000;
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
        backdrop-filter: blur(4px);
        /* Base Rich Shadow */
        box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.5);
    }

    .mobile-fab.right-fab {
        right: 1.5rem;
        /* Deep Tech Gradient (Indigo to Violet) */
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        box-shadow: 0 8px 16px -4px rgba(99, 102, 241, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    .mobile-fab.left-fab {
        left: 1.5rem;
        /* Warm Gradient (Pink to Rose) */
        background: linear-gradient(135deg, #ec4899, #f43f5e);
        box-shadow: 0 8px 16px -4px rgba(236, 72, 153, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    .mobile-fab:hover {
        transform: translateY(-2px) scale(1.05);
        filter: brightness(1.15);
        box-shadow: 0 12px 24px -4px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }

    .mobile-fab:active {
        transform: scale(0.95);
        box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.4);
    }

    /* Ensure controls can slide if too tight */
    .controls {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 4px;
        /* Space for scrollbar if needed */
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        /* Align start to allow scroll */
        gap: 0.5rem;
    }

    /* Ensure visual space for fab */
    .mobile-fab {
        z-index: 2000 !important;
        /* Force on top */
        display: flex !important;
        /* Force display on mobile */
    }

    /* --- End Sidebar Mobile Drawer --- */

    /* Scrollable Calendar for Mobile */
    .vertical-view {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .vertical-header,
    .vertical-body,
    .all-day-row {
        min-width: 600px;
        /* Ensure columns don't shrink too much */
    }

    .close-sidebar-mobile {
        position: sticky;
        top: 0;
        margin-left: auto;
        /* Push to right */
        right: 0;
        /* Reset */
        z-index: 1001;
        background: var(--bg-panel);
        /* Needs background to hide content under it */
        color: var(--text-secondary);
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
        cursor: pointer;
        transition: color 0.2s, background 0.2s;
        margin-bottom: 0;
        /* Remove bottom margin to tighten spacing */
    }

    .close-sidebar-mobile:hover {
        color: var(--text-primary);
        background: rgba(255, 255, 255, 0.1);
    }

    /* Day View overrides moved to Unified Scrolling section */

    /* Remove scrollbar compensation on mobile (overlay scrollbars) */
    .vertical-header {
        padding-right: 0 !important;
    }


    /* Modal Adjustments */
    .modal-content {
        width: 95%;
        padding: 1rem;
        max-height: 85vh;
        /* Ensure modal fits in screen */
    }

    .task-modal-content {
        max-height: 80vh;
        overflow-y: auto;
        margin: 10% auto;
        /* Centers visually */
    }

    /* Form Adjustments */
    .form-group-row {
        flex-direction: column;
        gap: 0.8rem;
    }

    /* Button Adjustments */
    .form-actions {
        flex-direction: column-reverse;
        gap: 0.8rem;
    }

    .form-actions button {
        width: 100%;
        justify-content: center;
    }

    #btn-open-goodnotes {
        margin-right: 0 !important;
        /* Override inline style */
    }

    /* UNIFIED SCROLLING START: Fix Sticky Time Labels & Header for Mobile Week & Day View */
    .week-view,
    .day-view {
        /* Make the view the single scroll container for X and Y */
        display: block !important;
        height: calc(100vh - 220px) !important;
        height: calc(100dvh - 220px) !important;
        /* Fit inside viewport - Increased offset for taller mobile header */
        max-height: 100dvh !important;
        overflow: scroll !important;
        /* Force scrollbars */
        position: relative;
        overscroll-behavior: contain;
        touch-action: pan-y pinch-zoom;
        /* Allow vertical scroll but reserve horizontal for JS */
    }

    /* Reset intermediate container */
    .week-view .vertical-view,
    .day-view .vertical-view {
        height: auto !important;
        overflow: visible !important;
        display: block !important;
        background: transparent !important;
        border: none !important;
        backdrop-filter: none !important;
        /* Fix sticky issue */
        width: max-content;
        /* Allow content to define width */
        min-width: 100%;
        pointer-events: auto !important;
    }

    /* Remove internal scroll from body */
    .week-view .vertical-body,
    .day-view .vertical-body {
        overflow-y: visible !important;
        height: auto !important;
        flex: none !important;
        min-width: 600px;
        /* maintained from previous */
        padding-bottom: 80px !important;
        /* Ensure bottom is reachable */
    }

    /* Sticky Header (Vertical Scroll) */
    .week-view .vertical-header,
    .day-view .vertical-header {
        position: sticky !important;
        top: 0 !important;
        left: 0;
        z-index: 50 !important;
        background: var(--bg-app) !important;
        width: 100%;
        min-width: 600px;
        padding-right: 0 !important;
        display: flex;
        border-bottom: 1px solid var(--border-subtle);
    }

    /* Sticky All-Day Row (Vertical Scroll) */
    .week-view .all-day-row,
    .day-view .all-day-row {
        position: sticky !important;
        top: 48px !important;
        z-index: 49 !important;
        background: var(--bg-app) !important;
        min-width: 600px;
        overflow: visible;
        border-bottom: 1px solid var(--border-subtle);
    }

    /* Sticky Corner (Header Spacer) - Both Top and Left */
    .week-view .vertical-header>div:first-child,
    .day-view .vertical-header>div:first-child {
        position: sticky !important;
        left: 0;
        top: 0 !important;
        z-index: 55 !important;
        background: var(--bg-app) !important;
        border-right: 1px solid var(--border-subtle);
    }

    /* Sticky All-Day Label */
    .week-view .all-day-label,
    .day-view .all-day-label {
        position: sticky !important;
        left: 0;
        top: 48px !important;
        z-index: 55 !important;
        background: var(--bg-panel) !important;
        border-right: 1px solid var(--border-subtle);
    }

    /* Sticky Time Labels (Horizontal Scroll) */
    .week-view .time-labels,
    .day-view .time-labels {
        position: sticky !important;
        /* Force sticky */
        left: 0;
        z-index: 45 !important;
        background: var(--bg-app) !important;
        border-right: 1px solid var(--border-subtle);
        margin-top: 0 !important;
    }

    /* Day View Specific Overrides (Must come after unified settings to reset widths) */
    .day-view .vertical-view {
        width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }

    .day-view .vertical-header,
    .day-view .all-day-row,
    .day-view .vertical-body {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* Ensure All-Day Row maintains width - Redundant but safe to keep minimal */
    /* UNIFIED SCROLLING END */

    /* Force alignment for Week View columns */
    /* Header Cell Calculation (Parent includes 60px spacer) */
    .week-view .header-cell {
        flex: 0 0 calc((100% - 60px) / 7) !important;
        width: calc((100% - 60px) / 7) !important;
        min-width: 0 !important;
        max-width: calc((100% - 60px) / 7) !important;
        box-sizing: border-box;
    }

    /* Protect Spacer from shrinking */
    .vertical-header>div:first-child {
        flex-shrink: 0 !important;
        width: 60px !important;
    }

    /* All Day & Body Column Calculation (Parent excludes 60px label) */
    .week-view .all-day-cell,
    .week-view .day-column {
        flex: 0 0 calc(100% / 7) !important;
        /* Fixed width exactly 1/7 of grid */
        width: calc(100% / 7) !important;
        min-width: 0 !important;
        max-width: calc(100% / 7) !important;
        box-sizing: border-box;
        /* Ensure border integration */
    }

    /* Reset padding for headers/body in week view to align */
    .week-view .all-day-row,
    .week-view .vertical-body,
    .week-view .all-day-grid {
        padding-right: 0 !important;
    }
}

/* PC Style Overrides for FAB */
@media (min-width: 769px) {

    .mobile-fab,
    .sidebar-overlay,
    .close-sidebar-mobile,
    .mobile-only {
        display: none !important;
    }
}