/* css/edit-expense-modal.css - Edit expense modal specific styles */

/* Reuse existing modal styles from add-expense-income.css but with edit-specific overrides */
#editExpenseModal.modal,
#editIncomeModal.modal {
    display: none;
    position: fixed;
    z-index: 10001; /* Higher than mobile context menu */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

#editExpenseModal .modal-content,
#editIncomeModal .modal-content {
    background-color: white;
    padding: 24px;
    border-radius: 4px;
    border: 1px solid #e1e1e1;
    width: 90%;
    max-width: 600px;
    max-height: calc(100svh - 40px);
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden; /* prevent content showing behind header/footer */
    box-sizing: border-box;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Roboto', sans-serif;
}

#editExpenseModal .close-btn,
#editIncomeModal .close-btn {
    color: #666;
    font-size: 24px;
    font-weight: 400;
    position: absolute;
    top: 20px;
    right: 24px;
    cursor: pointer;
    transition: color 0.15s ease;
    z-index: 1001;
    pointer-events: auto;
    background: transparent;
    border: none;
    padding: 4px;
}

#editExpenseModal .close-btn:hover,
#editIncomeModal .close-btn:hover {
    background: #f5f5f5;
    color: #2d2d2d;
}

#editExpenseModal h2,
#editIncomeModal h2 {
    margin: 0 0 16px 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #2d2d2d;
    padding: 16px 20px 12px 20px; /* similar to tab header */
    padding-right: 48px; /* space for close */
    border-bottom: 1px solid #e1e1e1;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 2;
}

#editExpenseModal h2::after,
#editIncomeModal h2::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: #9f7aea; /* active indicator bar like tabs */
}

#editExpenseModal form,
#editIncomeModal form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: auto; /* dedicated scroll region on desktop */
}

#editExpenseModal label,
#editIncomeModal label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #2d2d2d;
    margin-bottom: 4px;
    margin-top: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#editExpenseModal input,
#editExpenseModal select,
#editExpenseModal textarea,
#editIncomeModal input,
#editIncomeModal select,
#editIncomeModal textarea {
    padding: 12px 16px;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    font-size: 0.9rem;
    background: white;
    color: #2d2d2d;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Roboto', sans-serif;
    transition: border-color 0.15s ease;
}

#editExpenseModal input:focus,
#editExpenseModal select:focus,
#editExpenseModal textarea:focus,
#editIncomeModal input:focus,
#editIncomeModal select:focus,
#editIncomeModal textarea:focus {
    outline: none;
    border-color: #9f7aea;
}

#editExpenseModal textarea,
#editIncomeModal textarea {
    resize: vertical;
    min-height: 80px;
}

/* Currency amount container */
#editExpenseModal .currency-amount,
#editIncomeModal .currency-amount {
    display: flex;
    gap: 8px;
}

#editExpenseModal .currency-amount select,
#editExpenseModal .currency-amount .choices,
#editIncomeModal .currency-amount select,
#editIncomeModal .currency-amount .choices { flex: 0 0 88px; width: 88px !important; }
#editExpenseModal .currency-amount input,
#editIncomeModal .currency-amount input { flex: 1 1 auto; width: auto; }

/* Submit button */
#editExpenseModal button[type="submit"],
#editIncomeModal button[type="submit"] {
    background: #9f7aea;
    color: white;
    border: 1px solid #9f7aea;
    border-radius: 4px;
    padding: 14px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-top: 8px;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Roboto', sans-serif;
}

#editExpenseModal button[type="submit"]:hover,
#editIncomeModal button[type="submit"]:hover {
    background: #8b5fb8;
}

#editExpenseModal button[type="submit"]:disabled,
#editIncomeModal button[type="submit"]:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

/* Error messages */
#editExpenseModal .hidden,
#editIncomeModal .hidden {
    display: none;
}

#editExpenseModal #edit-error-message,
#editExpenseModal #edit-category-error-message,
#editIncomeModal #edit-error-message,
#editIncomeModal #edit-category-error-message {
    background: rgba(211, 47, 47, 0.1);
    border: 1px solid rgba(211, 47, 47, 0.3);
    border-radius: 4px;
    padding: 12px;
    color: #d32f2f;
    font-size: 0.875rem;
    margin-top: -8px;
    margin-bottom: 8px;
}

/* Choices.js overrides for edit modal */
#editExpenseModal .choices,
#editIncomeModal .choices {
    margin-bottom: 0;
}

#editExpenseModal .choices__inner,
#editIncomeModal .choices__inner {
    background: white;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    min-height: auto;
    padding: 12px 16px;
    font-size: 0.9rem;
}

#editExpenseModal .choices__inner:focus,
#editIncomeModal .choices__inner:focus {
    border-color: #9f7aea;
}

#editExpenseModal .choices__list--single .choices__item,
#editIncomeModal .choices__list--single .choices__item {
    color: #2d2d2d;
    font-weight: 400;
}

#editExpenseModal .choices__list--dropdown,
#editIncomeModal .choices__list--dropdown {
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#editExpenseModal .choices__item--selectable.is-highlighted,
#editIncomeModal .choices__item--selectable.is-highlighted {
    background-color: rgba(159, 122, 234, 0.1);
    color: #9f7aea;
}


/* Mobile responsive */
@media (max-width: 768px) {
    #editExpenseModal .modal-content,
    #editIncomeModal .modal-content {
        width: 95%;
        padding: 24px 20px;
        margin: 20px;
        max-height: calc(100vh - 40px);
    }

    #editExpenseModal h2,
    #editIncomeModal h2 {
        font-size: 1.3rem;
        margin-bottom: 20px;
    }

    #editExpenseModal .currency-amount,
    #editIncomeModal .currency-amount {
        gap: 6px;
    }

    #editExpenseModal .currency-amount select,
    #editIncomeModal .currency-amount select {
        flex: 0 0 80px;
    }

    #editExpenseModal .currency-amount input,
    #editIncomeModal .currency-amount input {
        flex: 1;
    }
}

@media (max-width: 480px) {
    /* Lock body scroll when modal is open */
    body.modal-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    /* Fixed positioning for mobile - no more floating */
    #editExpenseModal.modal,
    #editIncomeModal.modal {
        position: fixed;
        inset: 0;
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
        overflow: hidden;
        /* Prevent iOS bounce scrolling */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: none;
    }

    #editExpenseModal .modal-content,
    #editIncomeModal .modal-content {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        /* Enable internal scrolling only */
        overflow: hidden;
        /* iOS safe area support */
        padding-top: env(safe-area-inset-top, 0);
        /* Reserve space for fixed footer */
        padding-bottom: calc(84px + env(safe-area-inset-bottom, 0));
        padding-left: env(safe-area-inset-left, 0);
        padding-right: env(safe-area-inset-right, 0);
    }

    /* Header with close button - fixed at top */
    #editExpenseModal h2,
    #editIncomeModal h2 {
        font-size: 1.2rem;
        margin: 0;
        padding: 16px 20px 12px 20px;
        border-bottom: 1px solid #e1e1e1;
        background: white;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 2;
    }

    #editExpenseModal .close-btn,
    #editIncomeModal .close-btn {
        top: 12px;
        right: 16px;
        padding: 8px;
        font-size: 20px;
        z-index: 3;
    }

    /* Scrollable form container */
    #editExpenseModal form,
    #editIncomeModal form {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Let child elements handle scrolling */
    }

    /* Scrollable form fields area */
    #editExpenseModal .form-fields,
    #editIncomeModal .form-fields {
        flex: 1;
        padding: 20px 20px 0 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* If no .form-fields wrapper exists, apply to form */
    #editExpenseModal form:not(:has(.form-fields)),
    #editIncomeModal form:not(:has(.form-fields)) {
        padding: 20px 20px 0 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        gap: 12px; /* Reduce gap between fields */
    }

    /* Form field styles */
    #editExpenseModal input,
    #editExpenseModal select,
    #editExpenseModal textarea,
    #editIncomeModal input,
    #editIncomeModal select,
    #editIncomeModal textarea {
        padding: 12px 16px; /* Reduce padding slightly */
        font-size: 16px; /* Prevent iOS zoom */
        border-radius: 4px;
        min-height: 44px;
        box-sizing: border-box;
        margin-bottom: 12px; /* Reduce margin */
        width: 100%;
    }

    #editExpenseModal textarea,
    #editIncomeModal textarea {
        min-height: 100px;
        resize: none; /* Prevent resize on mobile */
    }

    /* Footer pinned to viewport bottom */
    #editExpenseModal .modal-footer,
    #editIncomeModal .modal-footer {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: saturate(120%) blur(6px);
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #eaeaea;
        z-index: 10005;
        box-sizing: border-box;
    }

    /* Currency amount container adjustments */
    #editExpenseModal .currency-amount,
    #editIncomeModal .currency-amount { gap: 8px; }
    #editExpenseModal .currency-amount select,
    #editExpenseModal .currency-amount .choices,
    #editIncomeModal .currency-amount select,
    #editIncomeModal .currency-amount .choices { flex: 0 0 88px; }
    #editExpenseModal .currency-amount input,
    #editIncomeModal .currency-amount input { flex: 1; }

    /* Prevent text selection during touch interactions */
    #editExpenseModal *,
    #editIncomeModal * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Allow text selection in input fields */
    #editExpenseModal input,
    #editExpenseModal textarea,
    #editIncomeModal input,
    #editIncomeModal textarea {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* Desktop/tablet footer: sticky inside modal content */
#editExpenseModal .modal-footer,
#editIncomeModal .modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #eaeaea;
    padding: 12px 20px;
    z-index: 3;
    box-sizing: border-box;
}
