.recipe-modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: rgba(3,6,12,0.95);
    backdrop-filter: blur(6px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 280ms cubic-bezier(0.4, 0, 0.2, 1),
                visibility 280ms cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10000;
    overflow-y: auto;
    padding: 2rem 1rem;
}

/* ========== МОБІЛЬНА АДАПТАЦІЯ modal (max-width: 768px) ========== */
@media (max-width: 768px) {
    .recipe-modal-overlay {
        padding: 0 !important;
        align-items: center !important;
    }
    
    .recipe-modal {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 12px 12px 0 0 !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
    }
    
    .modal-close {
        right: 1rem !important;
        top: 1rem !important;
        font-size: 1.5rem !important;
    }
    
    .modal-image-wrap {
        width: 100% !important;
        height: 220px !important;
    }
    
    .modal-image {
        height: 220px !important;
        width: 100% !important;
        object-fit: cover !important;
    }
    
    .modal-body {
        padding: 1rem !important;
        flex-direction: column !important;
    }
    
    .modal-title {
        font-size: 1.2rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    .modal-description {
        font-size: 0.9rem !important;
        line-height: 1.5 !important;
        margin-bottom: 1rem !important;
    }
    
    .modal-section {
        margin-bottom: 1rem !important;
    }
    
    .modal-section h3 {
        font-size: 0.95rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .modal-section ul,
    .modal-section ol {
        font-size: 0.9rem !important;
        margin: 0 !important;
        padding-left: 1.25rem !important;
    }
    
    .comments-section {
        margin-top: 1rem !important;
        padding-top: 1rem !important;
        border-top: 1px solid rgba(255,255,255,0.1) !important;
    }
}

.recipe-modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.recipe-modal {
    width: min(920px, 95%);
    margin: auto;
    background: var(--bg-1);
    border-radius: 12px;
    color: var(--text-primary);
    position: relative;
    transform: translateY(24px) scale(0.98);
    transition: transform 320ms cubic-bezier(.2,.9,.2,1);
    padding: 0;
    overflow: hidden;
}

.recipe-modal-overlay.open .recipe-modal {
    transform: translateY(0) scale(1);
}

.modal-close {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 10;
    transition: color 180ms ease;
}

.modal-close:hover {
    color: var(--accent);
}

.modal-image-wrap {
    width: 100%;
    height: 260px;
    overflow: hidden;
    position: relative;
}

.modal-image-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(0deg, var(--bg-2) 0%, transparent 100%);
    opacity: 0.8;
    pointer-events: none;
}

.modal-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 400ms ease;
}

.recipe-modal:hover .modal-image-wrap img {
    transform: scale(1.04);
}

.modal-body {
    padding: 2rem;
    position: relative;
    z-index: 1;
}

#modalTitle {
    color: #fff;
    font-size: 2rem;
    margin: 0 0 1.5rem 0;
    font-weight: 600;
}

.modal-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.modal-tags {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.tag {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

.tag.difficulty {
    background: var(--accent);
    color: #111;
}

.tag.time {
    color: var(--accent);
    background: rgba(255, 122, 0, 0.1);
    border: 1px solid rgba(255, 122, 0, 0.3);
}

.difficulty {
    background: var(--accent);
    color: #111;
    padding: 0.25rem 1rem;
    border-radius: 6px;
    font-weight: 600;
}

.cook-time {
    color: #ffffff;
}

.recipe-category {
    background: rgba(0,0,0,0.28) !important;
    color: #ff7a00 !important;
    padding: 0.34rem 0.9rem !important;
    border-radius: 20px !important;
    font-weight: 700 !important;
    font-size: 0.95rem !important;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18) !important;
}

.ingredients {
    margin-bottom: 2rem;
}

.ingredients h4,
.preparation h4 {
    color: var(--accent);
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.modal-body ul {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem 2rem;
    margin: 0;
}

.modal-body ul li {
    color: #fff;
    position: relative;
    padding-left: 1rem;
}

.modal-body ul li::before {
    content: "•";
    color: var(--accent);
    position: absolute;
    left: 0;
}

.modal-body ol {
    color: #fff;
    padding-left: 1.2rem;
    margin: 0;
}

.modal-body ol li {
    margin-bottom: 0.5rem;
}

.modal-body ol li:last-child {
    margin-bottom: 0;
}

.modal-section {
    margin-bottom: 2rem;
}

.modal-section h4 {
    color: var(--accent);
    font-size: 1.1rem;
    margin: 0 0 1rem 0;
    font-weight: 600;
}

.ingredients-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 0.5rem 1.2rem;
    padding: 0;
    margin: 0;
}

.ingredients-list li {
    position: relative;
    padding-left: 1.2rem;
    color: #cbd5e1;
}

.ingredients-list li::before {
    content: "•";
    color: var(--accent);
    position: absolute;
    left: 0;
}

@media (max-width: 680px) {
    .modal-image-wrap { 
        height: 180px; 
    }
    .modal-body ul { 
        grid-template-columns: 1fr; 
    }
    .recipe-modal { 
        width: 96%; 
    }
    .ingredients-list {
        grid-template-columns: 1fr;
    }
}

/* Generic centered modal used on profile page (edit modal) */
.modal {
    display: none;
    position: fixed;
    z-index: 1200;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.show {
    display: flex;
}
.modal-content {
    background: linear-gradient(180deg,#071026 0%, #0d1420 100%);
    color: #e6eef8;
    padding: 24px;
    border-radius: 12px;
    max-width: 920px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 30px 80px rgba(2,6,23,0.85);
}
.modal-content h3 { margin-bottom: 12px; }
.close-modal { cursor: pointer; }
.modal-content {
    /* hide native scrollbar but keep scrolling functionality */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 10+ */
}
.modal-content::-webkit-scrollbar { display: none; } /* Chrome, Safari */

/* Cancel button styling for edit modal */
.btn-cancel {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.08);
    color: #e6eef8;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 160ms ease, transform 120ms ease, border-color 160ms ease;
}
.btn-cancel:hover {
    background: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.12);
    transform: translateY(-2px);
}
.btn-cancel:active { transform: translateY(0); }

/* Make Save button proper size inside edit modal */
#edit-modal .submit-btn {
    flex: 1 1 0;
    width: auto !important;
    padding: 12px 18px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(255, 122, 0, 0.3);
}

/* Force proper dimensions for the button */
#edit-modal .buttons-row {
    display: flex;
    gap: 12px;
}
#edit-modal .submit-btn {
    box-sizing: border-box;
    height: 48px;
    padding: 0 20px;
    font-size: 1rem;
}

/* Ensure button is properly aligned: remove animations/transforms/margins */
#edit-modal .submit-btn {
    animation: none !important;
    transform: none !important;
    margin: 0 !important;
}

@media (max-width: 768px) {
    #edit-modal {
        padding: 0;
        align-items: stretch;
        justify-content: flex-start;
        overflow-y: auto;
    }

    #edit-modal .modal-content {
        width: 100%;
        max-width: 100%;
        min-height: 100vh;
        max-height: none;
        border-radius: 0;
        padding: 1rem;
        margin: 0;
        background: #12161D;
        box-shadow: none;
        padding-bottom: 80px; /* Prevent last fields and buttons from hiding behind smartphone bottom panel */
    }

    #edit-modal .close-modal {
        position: absolute;
        top: 18px;
        right: 18px;
        width: 46px;
        height: 46px;
        border-radius: 14px;
        background: rgba(0, 0, 0, 0.55);
        color: #ffffff;
        font-size: 1.3rem;
        z-index: 20;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    #edit-modal h3 {
        margin-top: 0;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    #edit-modal .recipe-form-content {
        padding: 0;
        gap: 1rem;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    #edit-modal .form-group-row {
        display: grid;
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    #edit-modal .form-group input,
    #edit-modal .form-group select,
    #edit-modal .form-group textarea,
    #edit-modal .file-input-wrapper .btn {
        min-height: 48px;
        padding: 0.95rem 1rem;
        font-size: 1rem;
    }

    #edit-modal .form-group textarea {
        min-height: 120px;
    }

    #edit-modal .file-input-wrapper {
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        background: rgba(255, 255, 255, 0.03);
        border: 1px dashed rgba(255, 122, 0, 0.35);
        border-radius: 18px;
    }

    #edit-modal .add-btn {
        width: 100%;
        padding: 1rem;
        border-radius: 14px;
        border: 1px solid rgba(255, 122, 0, 0.25);
        color: #ffb87a;
        background: rgba(255, 122, 0, 0.08);
        font-size: 1rem;
    }

    #edit-modal .ingredients-list,
    #edit-modal .steps-list {
        gap: 0.85rem;
    }

    #edit-modal .ingredient-item,
    #edit-modal .step-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 0.85rem;
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.03);
        position: relative;
    }

    #edit-modal .ingredient-item input,
    #edit-modal .step-item textarea {
        margin-right: 60px; /* Sufficient right margin to not overlap delete button */
        box-sizing: border-box;
    }

    #edit-modal .delete-btn {
        position: absolute;
        top: 0.85rem;
        right: 0.85rem;
        width: 44px;
        height: 44px;
        padding: 0;
        border-radius: 14px;
        background: rgba(255, 75, 75, 0.18);
        color: #ffb4b4;
        font-size: 1.15rem;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 5;
    }

    #edit-modal .buttons-row {
        position: static; /* Change from sticky to static so it flows in document and doesn't overlap floating menu button */
        bottom: auto;
        left: auto;
        width: 100%;
        padding: 0.75rem 0;
        margin: 1rem 0 0;
        background: none;
        flex-direction: row; /* Keep buttons in one row on wider mobiles */
        gap: 10px;
        z-index: auto;
        display: flex;
        flex-wrap: wrap; /* Allow wrapping on very narrow screens */
    }

    #edit-modal .submit-btn {
        flex: 1; /* Full width since only one button */
        border-radius: 14px;
        padding: 1rem;
        font-size: 1rem;
        background: linear-gradient(90deg, #ff7a30, #ffa550);
        color: #111;
        box-shadow: 0 14px 28px rgba(255, 122, 0, 0.24);
    }

    /* Image fixes: ensure images don't break layout */
    #edit-modal img,
    #edit-modal .current-image img,
    #edit-current-image img {
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    #edit-modal .current-image,
    #edit-current-image {
        box-sizing: border-box !important;
    }

    #edit-modal .modal-content::-webkit-scrollbar {
        width: 8px;
    }
    #edit-modal .modal-content::-webkit-scrollbar-track {
        background: transparent;
    }
    #edit-modal .modal-content::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.12);
        border-radius: 999px;
    }
}