/*
 * Mobile and small-screen overrides for modals and pages.
 * Loaded last on every page so it wins over the desktop rules in
 * style.css, dashboard.css, steady.css and profile.css.
 */

/* ---------- Modal shell: fit the visible viewport on phones ---------- */

@media (max-width: 768px) {
    .modal {
        padding: 12px;
    }

    /* Fallback first, then dynamic viewport height (accounts for mobile address bars). */
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        min-height: 0;
        border-radius: 14px;
    }

    .modal-header {
        padding: 14px 16px;
        gap: 8px;
    }

    .modal-header h2 {
        font-size: 18px;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        padding: 16px;
        -webkit-overflow-scrolling: touch;
    }

    .modal-form,
    .modal-checklist {
        padding: 16px;
    }

    /* Touch-friendly close and action buttons */
    .modal-close,
    .close-btn {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }

    .add-todo-btn,
    .add-link-btn,
    .add-category-btn {
        width: 40px;
        height: 40px;
    }

    .form-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .form-actions button,
    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
        min-height: 44px;
    }

    /* Stop iOS Safari zooming in on focus (needs 16px or larger) */
    .form-group input,
    .form-group textarea,
    .form-group select,
    .modal-form input,
    .modal-form select,
    .modal-form textarea {
        font-size: 16px;
    }

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

    .modal-form .form-group {
        margin-bottom: 16px;
    }
}

/* ---------- To Do modal: card grid of items, add/edit form in its own modal ---------- */

@media (max-width: 768px) {
    .todo-modal-content {
        max-width: 100% !important;
        width: 100%;
        height: calc(100vh - 24px);
        height: calc(100dvh - 24px);
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
    }

    .todo-modal-body {
        padding: 12px;
    }

    .todos-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .todos-list .todo-item {
        padding: 10px;
    }

    .todo-form-modal-content {
        max-width: 100% !important;
    }

    .todo-checkbox,
    .step-checkbox {
        width: 20px;
        height: 20px;
    }

    .delete-todo-btn,
    .delete-link-btn,
    .delete-btn,
    .step-delete-btn {
        min-width: 36px;
        min-height: 36px;
        width: 36px;
        height: 36px;
        font-size: 22px;
    }
}

/* ---------- Month calendar modal ---------- */

@media (max-width: 768px) {
    .month-modal-content {
        max-width: 100% !important;
        width: 100%;
        max-height: calc(100vh - 24px) !important;
        max-height: calc(100dvh - 24px) !important;
    }

    .modal-header button.month-nav-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 0 8px;
        font-size: 22px;
    }

    .month-modal-body {
        padding: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .calendar-container {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 12px;
        height: auto;
    }

    .calendar-grid {
        gap: 4px;
    }

    .calendar-header {
        gap: 4px;
        margin-bottom: 6px;
    }

    .calendar-weekday {
        font-size: 11px;
        padding: 4px 0;
    }

    .calendar-day {
        padding: 4px;
        font-size: 13px;
        min-width: 0;
        overflow: hidden;
    }

    .day-number {
        margin-bottom: 2px;
    }

    .day-details {
        padding-top: 16px;
    }

    .day-details h3 {
        font-size: 16px;
        margin-bottom: 12px;
    }

    .day-list li {
        padding: 10px 12px;
        font-size: 14px;
        overflow-wrap: anywhere;
    }
}

/* ---------- My Items modal: scroll the table instead of squeezing it ---------- */

@media (max-width: 768px) {
    .items-modal-content {
        max-width: 100% !important;
        width: 100%;
        max-height: calc(100vh - 24px) !important;
        max-height: calc(100dvh - 24px) !important;
    }

    .items-modal-body {
        min-height: 0;
        padding: 0;
    }

    .items-controls {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .items-table-wrapper {
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }

    .items-table {
        min-width: 560px;
    }

    .items-table th,
    .items-table td {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* ---------- Small phones ---------- */

@media (max-width: 420px) {
    .modal {
        padding: 8px;
    }

    .modal-content {
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
    }

    .modal-header {
        padding: 12px 14px;
    }

    .modal-body {
        padding: 14px;
    }

    .calendar-day {
        font-size: 12px;
    }
}

/* ---------- Profile page layout on phones ---------- */

@media (max-width: 480px) {
    .profile-container {
        padding: 12px;
    }

    .profile-section {
        padding: 16px;
    }

    .profile-header h2 {
        font-size: 22px;
    }
}

/* ---------- Login page on phones ---------- */

@media (max-width: 480px) {
    .auth-page .auth-card {
        padding: 20px;
    }
}
