/* ===================================
   FABRICACIÓN - DISEÑO MODERNO
   Paleta: Índigo + Cyan + Slate
   =================================== */

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #6366f1;
    --accent: #06b6d4;
    --accent-dark: #0891b2;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-900: #0f172a;
}

/* Reset */
.fabricacion-modal * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Overlay del modal */
.fabricacion-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: stretch;
    justify-content: center;
    z-index: 10000;
    padding: 0;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Contenedor principal */
.fabricacion-modal .modal-content {
    background: white;
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* ===================================
   HEADER
   =================================== */
.fabricacion-modal .modal-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.15);
}

.fabricacion-modal .modal-header h2 {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fabricacion-modal .close-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 1.25rem;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.fabricacion-modal .close-button:active {
    background: rgba(255, 255, 255, 0.25);
}

/* ===================================
   BODY SCROLLABLE
   =================================== */
.fabricacion-modal .modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    background: var(--gray-50);
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.fabricacion-modal .modal-body::-webkit-scrollbar {
    width: 8px;
}

.fabricacion-modal .modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.fabricacion-modal .modal-body::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

/* ===================================
   BÚSQUEDA
   =================================== */
.search-container {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.search-box {
    display: flex;
    gap: 0.5rem;
}

.search-box input {
    flex: 1;
    min-width: 0;
    padding: 0.875rem 1rem;
    border: 2px solid var(--gray-200);
    border-radius: 10px;
    font-size: 0.9375rem;
    color: var(--gray-900);
    transition: all 0.2s;
    background: var(--gray-50);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.search-box input::placeholder {
    color: var(--gray-600);
}

.search-btn {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    color: white;
    font-size: 1.125rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
    flex-shrink: 0;
}

.search-btn:active {
    transform: scale(0.92);
}

/* Resultados */
.search-results {
    margin-top: 0.875rem;
    max-height: 180px;
    overflow-y: auto;
    border-radius: 10px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
    border-bottom: 1px solid var(--gray-200);
    transition: background 0.15s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:active {
    background: white;
}

.search-result-item span {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    color: var(--gray-700);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
}

.add-btn {
    padding: 0.5rem 0.875rem;
    border-radius: 8px;
    background: var(--success);
    border: none;
    color: white;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.add-btn:active {
    transform: scale(0.95);
}

/* ===================================
   ARTÍCULO SELECCIONADO
   =================================== */
.selected-articles h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.selected-article-item {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    margin-bottom: 1rem;
}

.article-main h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.4;
    margin-bottom: 1rem;
}

/* Stock Cards */
.current-stock-info,
.final-stock-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem;
    border-radius: 10px;
    margin-bottom: 0.875rem;
}

.current-stock-info {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    border-left: 3px solid var(--primary);
}

.final-stock-info {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border-left: 3px solid var(--success);
}

.stock-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stock-value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.current-stock-info .stock-value {
    color: var(--primary-dark);
}

.final-stock-info .stock-value {
    color: #059669;
}

/* Input cantidad */
.quantity-control {
    margin-top: 0.875rem;
}

.quantity-control label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.quantity-input {
    width: 100%;
    padding: 1rem;
    border: 3px solid var(--gray-200);
    border-radius: 12px;
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    color: var(--gray-900);
    background: var(--gray-50);
    transition: all 0.2s;
    letter-spacing: -0.03em;
}

.quantity-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

/* ===================================
   COMPOSICIÓN
   =================================== */
.composicion-list {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 0.875rem;
    margin-top: 1rem;
}

.composicion-list h5 {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.composicion-item {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.625rem;
}

.composicion-item:last-child {
    margin-bottom: 0;
}

.composicion-item > span {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.625rem;
    line-height: 1.3;
}

.stock-details {
    display: grid;
    gap: 0.5rem;
}

.stock-details > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.625rem;
    background: var(--gray-50);
    border-radius: 6px;
}

.stock-details .stock-label {
    font-size: 0.75rem;
}

.stock-details .stock-value {
    font-size: 0.875rem;
    font-weight: 700;
}

/* ===================================
   FOOTER STICKY
   =================================== */
.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

@supports (padding: max(0px)) {
    .modal-actions {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

.cancel-btn,
.save-btn {
    height: 48px;
    border-radius: 10px;
    border: none;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.cancel-btn {
    background: var(--gray-100);
    color: var(--gray-700);
}

.cancel-btn:active {
    background: var(--gray-200);
    transform: scale(0.97);
}

.save-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.save-btn:active {
    transform: scale(0.97);
}

.save-btn:disabled {
    background: var(--gray-300);
    color: var(--gray-600);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.6;
}

/* ===================================
   ESTADOS
   =================================== */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
}

.loading-spinner i {
    font-size: 2.5rem;
    color: var(--primary);
    animation: spin 1s linear infinite;
}

.loading-spinner span {
    font-size: 0.9375rem;
    color: var(--gray-600);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    padding: 1rem;
    margin: 1rem;
    text-align: center;
}

.error-message h2 {
    color: var(--danger);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.error-message p {
    color: #991b1b;
    font-size: 0.875rem;
}

/* ===================================
   RESPONSIVE
   =================================== */
@media (min-width: 768px) {
    .fabricacion-modal {
        padding: 2rem;
        align-items: center;
    }

    .fabricacion-modal .modal-content {
        width: 90%;
        height: 90vh;
        max-width: 800px;
        border-radius: 16px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }

    .fabricacion-modal .modal-header {
        border-radius: 16px 16px 0 0;
        padding: 1.5rem;
    }

    .fabricacion-modal .modal-header h2 {
        font-size: 1.5rem;
    }

    .modal-body {
        padding: 1.5rem;
    }

    .modal-actions {
        padding: 1.5rem;
        gap: 1rem;
    }

    .cancel-btn,
    .save-btn {
        height: 52px;
        font-size: 1rem;
    }

    .stock-details {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .fabricacion-modal .modal-content {
        max-width: 900px;
    }

    .modal-actions {
        grid-template-columns: auto auto;
        justify-content: flex-end;
    }

    .cancel-btn,
    .save-btn {
        min-width: 140px;
    }
}