.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    overflow: auto;
}

/* Modal apilado - para modales que se abren sobre otros modales */
.modal.stacked {
    z-index: 2100;
    background: rgba(0, 0, 0, 0.85);
}

.modal.stacked .modal-content {
    z-index: 2101;
}
.modal[style*="display: block"],
.modal[style*="display: flex"] {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}
.modal-content {
    background: var(--primary);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    padding: 2.5rem 2rem 2rem 2rem;
    position: relative;
    margin: 0 auto;
    top: 0;
    left: 0;
    transform: none;
    transition: all 0.4s ease;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(233, 69, 96, 0.3);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
}
.modal.active .modal-content {
    transform: translateY(0);
}
.close-modal {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 2.2rem;
    color: var(--highlight);
    background: none;
    border: none;
    z-index: 10;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
}
.close-modal:hover {
    color: #b92d47;
    transform: scale(1.15);
}
.modal h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--highlight);
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.modal h2 i {
    font-size: 1.8rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: #1a1a1a;
}

.form-group label i {
    color: var(--highlight);
    font-size: 1rem;
    width: 18px;
    text-align: center;
}

/* Asteriscos requeridos siempre en rojo */
.form-group label::after {
    content: attr(data-required);
    color: #ef4444;
    margin-left: 2px;
    font-weight: 700;
}
.form-group input {
    width: 100%;
    padding: 0.8rem 1.2rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--light);
    font-size: 1rem;
    transition: var(--transition);
}
.form-group select {
    width: 100%;
    padding: 0.8rem 1.2rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--light);
    font-size: 1rem;
    transition: var(--transition);
    cursor: pointer;
}
.form-group textarea {
    width: 100%;
    padding: 0.8rem 1.2rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--light);
    font-size: 1rem;
    transition: var(--transition);
    resize: vertical;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--highlight);
    background: rgba(255, 255, 255, 0.12);
}
.submit-btn {
    width: 100%;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--highlight) 0%, #c41e3a 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 1rem;
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(233, 69, 96, 0.4);
}

.submit-btn i {
    font-size: 1rem;
}
.form-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: rgba(255, 255, 255, 0.7);
}
.form-footer a {
    color: var(--highlight);
    text-decoration: none;
    font-weight: 500;
}
.cart-items {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
}
.cart-item {
    display: flex;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.cart-item-image {
    width: 80px;
    height: 80px;
    background: linear-gradient(45deg, var(--secondary), #e9ecef);
    border-radius: 10px;
    margin-right: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    color: rgba(0, 0, 0, 0.1);
}
.cart-item-details {
    flex: 1;
}
.cart-item-name {
    font-weight: 600;
    margin-bottom: 0.3rem;
}
.cart-item-price {
    color: var(--highlight);
    font-weight: 700;
}
.cart-item-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.quantity-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--light);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}
.quantity-btn:hover {
    background: var(--accent);
}
.cart-item-quantity {
    margin: 0 0.5rem;
}
.remove-item {
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.2rem;
}
.remove-item:hover {
    color: var(--highlight);
}
.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.3rem;
    font-weight: 700;
    padding: 1rem 0;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin-top: 1rem;
}

/* Product Image Upload System */
#images-modal .modal-content {
    max-width: 450px;
    max-height: 600px;
}

#image-upload-section {
    max-height: 350px;
    overflow-y: auto;
    padding-right: 0.5rem;
    margin-bottom: 1rem;
}

#image-upload-section::-webkit-scrollbar {
    width: 6px;
}

#image-upload-section::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#image-upload-section::-webkit-scrollbar-thumb {
    background: #1e3a5f;
    border-radius: 3px;
}

.image-preview-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin-bottom: 1rem;
    min-height: 100px;
}

.image-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid #dee2e6;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview-item.primary {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .remove-image {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.image-preview-item:hover .remove-image {
    opacity: 1;
}

.image-preview-item .primary-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: #10b981;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
}

.upload-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
}

#add-image-btn {
    background: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s;
}

#add-image-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}

#add-image-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.image-count-info {
    color: #6c757d;
    font-size: 0.85rem;
    font-weight: 500;
}

#open-images-modal-btn {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    padding: 0.8rem 1.2rem;
    font-size: 0.95rem;
}

#open-images-modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

#images-badge {
    font-weight: 700;
}

/* Brand Logo Upload Styles */
.brand-logo-upload-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.brand-logo-preview {
    display: none;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.logo-preview-wrapper {
    position: relative;
    display: inline-block;
}

.logo-preview-img {
    width: 180px;
    height: 180px;
    object-fit: contain;
    border: 2px solid #e5e7eb;
    padding: 12px;
    border-radius: 12px;
    background: #f9fafb;
    display: block;
}

.remove-logo-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.remove-logo-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
}

.logo-hint {
    color: #6b7280;
    font-size: 0.85rem;
    margin: 0;
    font-style: italic;
}

.secondary-btn {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    padding: 0.7rem 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    transition: all 0.2s;
    width: fit-content;
}

.secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.secondary-btn i {
    font-size: 1rem;
}

/* Modal Sizes */
.small-modal .modal-content {
    max-width: 450px;
}

.medium-modal .modal-content {
    max-width: 650px;
    max-height: 85vh;
}

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

.add-btn.small {
    padding: 0.7rem 1.2rem;
    font-size: 0.95rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.add-btn.small:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.add-btn.elegant {
    background: linear-gradient(135deg, var(--highlight) 0%, #c41e3a 100%);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.add-btn.elegant:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3);
}

.subcat-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.subcat-counter {
    font-size: 0.85rem;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}

.manage-subcat-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: rgb(0, 0, 0);
    padding: 0.6rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.manage-subcat-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.manage-subcat-btn i {
    font-size: 1.2em !important;
    color: rgb(0, 0, 0);
    display: block;
}

/* Login and Register modal specific styles */
#login-modal,
#register-modal {
    display: none;
}

#login-modal .modal-content,
#register-modal .modal-content {
    max-width: 400px;
    margin: 8vh auto;
}

#product-details-modal {
    display: none;
}

/* ===== LOADER OVERLAY ===== */
#auth-loader {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#auth-loader.show {
    display: flex;
    opacity: 1;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(233, 69, 96, 0.2);
    border-top: 4px solid var(--highlight);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-text {
    color: var(--light);
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: 0.5px;
}
