@media (max-width: 900px) {
    .home-stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .board-view {
        grid-template-columns: repeat(2, 1fr);
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    html, body {
        min-height: 100%;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    #app {
        min-height: 100dvh;
        height: 100dvh;
        overflow: hidden;
    }

    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        height: 100dvh;
        z-index: 100;
        transition: left 0.3s ease;
        width: 260px;
        min-width: 260px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

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

    #sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0s 0.3s;
    }

        #sidebar-overlay.active {
            opacity: 1;
            visibility: visible;
            transition-delay: 0s;
        }

    .topbar {
        padding: 8px 12px;
        min-height: 52px;
        gap: 8px;
    }

    .topbar-presence {
        display: none;
    }

    /* Constrain breadcrumb so the New Task button is never pushed off */
    .breadcrumb {
        min-width: 0;
        overflow: hidden;
    }

    .breadcrumb span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 120px;
        display: inline-block;
    }

    /* Hide last-edited pill text, keep icon only to save space */
    #last-edited-label {
        display: none;
    }

    .last-edited-pill {
        padding: 4px 8px;
    }

    /* Ensure New Task button is always visible and not clipped */
    .topbar-actions {
        flex-shrink: 0;
    }

    #new-task-btn {
        white-space: nowrap;
        font-size: 12px;
        padding: 6px 10px;
    }

    .view {
        padding: 24px 20px 40px;
    }

    #main-view {
        padding: 0 20px 40px;
    }

    .home-hero {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .home-greeting {
        flex-direction: column;
        align-items: flex-start;
    }

    .greeting-title {
        font-size: 28px;
    }

    .greeting-emoji {
        font-size: 40px;
    }

    .date-time-module {
        justify-content: center;
    }

    .home-stats-row {
        grid-template-columns: 1fr;
    }

    .task-list-header {
        display: none;
    }

    .task-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .task-name-cell {
        grid-column: 1 / -1;
    }

    .board-view {
        grid-template-columns: 1fr;
    }

    .calendar-header h2 {
        font-size: 16px;
        min-width: auto;
    }

    .calendar-grid {
        overflow-x: hidden;
    }

    .cal-weekday {
        padding: 8px 2px;
        font-size: 10px;
    }

    .cal-day {
        min-height: 70px;
        padding: 5px 3px;
    }

    .cal-day-num {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .cal-entry-chip {
        font-size: 9px;
        padding: 3px 5px;
        margin-bottom: 2px;
        gap: 4px;
    }

    .cal-entry-chip .entry-time {
        display: none;
    }

    .cal-day-add-btn {
        width: 18px;
        height: 18px;
        font-size: 10px;
        top: 4px;
        right: 3px;
    }

    .entry-detail-value {
        font-size: 14px;
        padding-left: 0;
    }

    .entry-detail-label {
        font-size: 10px;
    }

    #modal-calendar-entry-detail .modal-body {
        padding: 20px 16px;
    }

    .modal-overlay {
        padding: 16px;
    }

    .modal-xl {
        max-width: 100%;
    }

    .settings-layout {
        grid-template-columns: 1fr;
        gap: 16px 0;
    }

    .modal-xl .modal-body {
        max-height: calc(100vh - 160px);
    }

    .status-selector {
        grid-template-columns: 1fr;
    }

    .invite-member-row {
        flex-direction: column;
        align-items: stretch;
    }

    .invite-input-wrap {
        width: 100%;
    }

    .page-view-header {
        flex-wrap: wrap;
    }

    .task-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .view-toggle,
    .task-filters {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .greeting-title {
        font-size: 24px;
    }

    .date-time-primary {
        font-size: 24px;
    }

    .date-time-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .stat-value {
        font-size: 28px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .entry-type-toggle {
        width: 100%;
    }

    .entry-type-btn {
        min-width: auto;
        flex: 1;
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Calendar - compact dot-indicator view */
    .calendar-grid {
        overflow-x: hidden;
    }

    .cal-weekday {
        padding: 5px 1px;
        font-size: 8px;
        letter-spacing: 0;
    }

    .cal-day {
        min-height: 44px;
        padding: 3px 2px;
        overflow: hidden;
    }

    .cal-day-num {
        font-size: 10px;
        font-weight: 700;
        text-align: center;
        margin-bottom: 3px;
    }

    .cal-day-add-btn {
        display: none;
    }

    .cal-entry-chip {
        width: 6px;
        height: 6px;
        min-width: 6px;
        padding: 0;
        border-radius: 50%;
        margin: 1px auto;
        display: block;
        box-shadow: none;
        border: none;
        cursor: pointer;
    }

    .cal-entry-chip.task-chip {
        background: var(--primary);
    }

    .cal-entry-chip.meeting-chip {
        background: #ec4899;
    }

    .cal-entry-chip i,
    .cal-entry-chip span,
    .cal-entry-chip .entry-time {
        display: none;
    }

    .cal-entry-chip:hover {
        transform: none;
        box-shadow: none;
    }
}

@media print {
    #sidebar,
    .topbar,
    .modal-overlay,
    .fn-toast {
        display: none !important;
    }

    .view {
        padding: 0;
    }

    .task-row,
    .board-card,
    .cal-day {
        page-break-inside: avoid;
    }
}

@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        html, body {
            min-height: -webkit-fill-available;
        }

        #app,
        #sidebar {
            min-height: -webkit-fill-available;
        }
    }
}

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

#sidebar .sidebar-section {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
