/* iPad Responsive Layout
 * Handles sidebar collapse, content area adjustments, and safe areas
 * for iPad portrait, landscape, and Split View modes.
 */

/* ========================================================================
   SIDEBAR — Collapse in narrow widths (portrait, Split View)
   ======================================================================== */

@media (max-width: 1023px) and (pointer: coarse) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -68px;
        bottom: 0;
        z-index: 1100;
        transition: left 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }

    .sidebar.sidebar-open {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 1099;
        opacity: 0;
        transition: opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }

    .sidebar-overlay.visible {
        display: block;
        opacity: 1;
    }

    /* Main content fills full width when sidebar is hidden */
    .main-content {
        margin-left: 0 !important;
    }
}

/* Sidebar stays visible on wide screens */
@media (min-width: 1024px) {
    .sidebar-hamburger {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* ========================================================================
   HAMBURGER BUTTON — visible only when sidebar is collapsed
   ======================================================================== */

.sidebar-hamburger {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1098;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: var(--bg-primary, #fff);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #666);
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-hamburger svg {
    width: 20px;
    height: 20px;
}

@media (max-width: 1023px) and (pointer: coarse) {
    .sidebar-hamburger {
        display: flex;
    }

    /* Shift header content right to avoid hamburger overlap */
    body.is-ipad .main-header {
        padding-left: 56px;
    }
}

/* ========================================================================
   CONTENT AREA — Tighter padding on narrow screens
   ======================================================================== */

@media (max-width: 1023px) and (pointer: coarse) {
    .main-content {
        padding: 16px;
    }

    /* Today view adjustments */
    .today-layout {
        gap: 12px;
    }
}

/* Split View 1/3 screen (~507px) */
@media (max-width: 550px) and (pointer: coarse) {
    .main-content {
        padding: 12px;
    }

    .today-layout {
        flex-direction: column;
    }
}

/* ========================================================================
   WEEK VIEW — Show fewer days on narrow widths
   ======================================================================== */

@media (max-width: 1023px) and (pointer: coarse) {
    .week-columns {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    .week-column {
        min-width: 140px;
        scroll-snap-align: start;
    }
}

/* Split View narrow — show 3 days */
@media (max-width: 768px) and (pointer: coarse) {
    .week-column {
        min-width: 180px;
    }
}

/* ========================================================================
   SAFE AREAS — iPads with rounded corners / Home Indicator
   ======================================================================== */

body.is-ipad {
    padding-top: env(safe-area-inset-top, 0);
}

body.is-ipad .sidebar {
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
}

body.is-ipad .main-content {
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-right: env(safe-area-inset-right, 0);
}

/* ========================================================================
   DISABLE DESKTOP WINDOW CHROME on iPad
   ======================================================================== */

body.is-ipad .sidebar {
    -webkit-app-region: initial;
}

body.is-ipad .main-header {
    -webkit-app-region: initial;
}

/* Disable title bar dragging */
body.is-ipad [data-tauri-drag-region] {
    -webkit-app-region: initial;
}

/* ========================================================================
   MODAL & OVERLAY ADJUSTMENTS
   ======================================================================== */

@media (max-width: 768px) and (pointer: coarse) {
    .modal-content {
        width: 95vw;
        max-width: none;
        margin: 16px;
    }

    .settings-content {
        flex-direction: column;
    }

    .settings-sidebar {
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-primary, #e5e5e5);
    }
}

/* ========================================================================
   TASK BOARD — Horizontal scroll on narrow widths
   ======================================================================== */

@media (max-width: 1023px) and (pointer: coarse) {
    .board-columns {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        flex-wrap: nowrap;
    }

    .board-column {
        min-width: 260px;
        scroll-snap-align: start;
        flex-shrink: 0;
    }
}

/* ========================================================================
   REDUCED MOTION — Respect system preference
   ======================================================================== */

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-overlay {
        transition: none;
    }
}
