/* =========================================================
   IAProds Core Stylesheet — Reutilizable en todos los productos
   Logo, colores, tipografía, componentes base
   ========================================================= */

/* -- Variables de Marca (Corporate) -- */
:root {
    --iaprods-violet: #1e3a5f;
    --iaprods-violet-light: #3b6fa5;
    --iaprods-violet-dark: #0f2440;
    --iaprods-purple: #1e3a5f;
    --iaprods-gradient: linear-gradient(135deg, #1e3a5f 0%, #2c5a8c 100%);
    --iaprods-gradient-hover: linear-gradient(135deg, #2c5a8c 0%, #1e3a5f 100%);
    --iaprods-bg: #f4f6f9;
    --iaprods-border: #d1d9e6;
    --iaprods-text: #1f2937;
    --iaprods-text-muted: #6b7280;
    --iaprods-white: #ffffff;
    --iaprods-shadow: 0 4px 20px rgba(30, 58, 95, 0.10);
    --iaprods-shadow-lg: 0 10px 40px rgba(30, 58, 95, 0.15);
    --iaprods-radius: 8px;
    --iaprods-radius-lg: 14px;
    --iaprods-transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* -- Reset Base -- */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--iaprods-bg);
    color: var(--iaprods-text);
    line-height: 1.6;
}

/* -- Logo IAProds -- */
.logo-iaprods { height: 38px; width: auto; }
.logo-iaprods-sm { height: 28px; width: auto; }
.logo-iaprods-lg { height: 48px; width: auto; }

/* -- Botones Modernos (UI 2026) -- */
.btn-iaprods {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    background: var(--iaprods-gradient);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    letter-spacing: 0.2px;
}
.btn-iaprods:hover { opacity: 0.9; }
.btn-iaprods:active { transform: scale(0.97); }

.btn-iaprods-outline {
    background: transparent;
    color: var(--iaprods-violet);
    border: 1.5px solid var(--iaprods-violet);
    box-shadow: none;
}
.btn-iaprods-outline:hover {
    background: rgba(30, 58, 95, 0.06);
    opacity: 1;
}

.btn-iaprods-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
    gap: 6px;
}

.btn-iaprods-xs {
    padding: 4px 10px;
    font-size: 0.72rem;
    gap: 4px;
    border-radius: 6px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s ease;
    color: var(--iaprods-text-muted);
}
.btn-icon:hover { background: rgba(30, 58, 95, 0.06); color: var(--iaprods-violet); }
.btn-icon.danger:hover { background: #fef2f2; color: #dc2626; }

.btn-iaprods-danger {
    background: #dc2626;
}
.btn-iaprods-danger:hover { opacity: 0.9; }

.btn-iaprods-success {
    background: #059669;
}
.btn-iaprods-success:hover { opacity: 0.9; }

.btn-iaprods-warning {
    background: #d97706;
}

.btn-mejora {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-mejora:hover { background: linear-gradient(135deg, #fde68a, #fcd34d); }
.btn-mejora:active { transform: scale(0.96); }

/* -- Cards -- */
.card-iaprods {
    background: var(--iaprods-white);
    border-radius: var(--iaprods-radius-lg);
    padding: 1.5rem;
    box-shadow: var(--iaprods-shadow);
    border: 1px solid var(--iaprods-border);
    transition: var(--iaprods-transition);
}
.card-iaprods:hover {
    transform: translateY(-4px);
    box-shadow: var(--iaprods-shadow-lg);
}
.card-iaprods-static:hover { transform: none; }

.card-iaprods-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid #f0f0f0;
}

/* -- Layout -- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar-iaprods {
    width: 260px;
    background: white;
    border-right: 1px solid var(--iaprods-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-iaprods .sidebar-header {
    padding: 1.2rem 1.2rem 0.8rem;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-iaprods .sidebar-nav {
    padding: 0.8rem 0;
    flex: 1;
}

.sidebar-iaprods .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.7rem 1.2rem;
    color: var(--iaprods-text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: var(--iaprods-transition);
    border-left: 3px solid transparent;
}

.sidebar-iaprods .nav-item:hover {
    color: var(--iaprods-violet);
    background: rgba(30, 58, 95, 0.04);
}

.sidebar-iaprods .nav-item.active {
    color: var(--iaprods-violet);
    background: rgba(30, 58, 95, 0.06);
    border-left-color: var(--iaprods-violet);
    font-weight: 600;
}

.sidebar-iaprods .nav-item .nav-icon {
    width: 22px;
    text-align: center;
    font-size: 1.1rem;
}

.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
    min-height: 100vh;
}

/* -- Top Bar -- */
.topbar-iaprods {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #f0f0f0;
}

.topbar-iaprods h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--iaprods-text);
}

.topbar-iaprods .breadcrumb {
    font-size: 0.85rem;
    color: var(--iaprods-text-muted);
}
.topbar-iaprods .breadcrumb span { color: var(--iaprods-text); font-weight: 500; }

/* -- Stats Grid -- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: var(--iaprods-radius);
    padding: 1.2rem 1.5rem;
    border: 1px solid var(--iaprods-border);
    transition: var(--iaprods-transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--iaprods-shadow); }

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--iaprods-violet);
    margin-bottom: 0.2rem;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--iaprods-text-muted);
}

.stat-card .stat-icon {
    float: right;
    font-size: 2rem;
    opacity: 0.15;
}

/* -- Tablas Rediseñadas (compactas, especificación como columna principal) -- */
.table-iaprods {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.table-iaprods thead { position: sticky; top: 0; z-index: 2; }

.table-iaprods th {
    text-align: left;
    padding: 0.55rem 0.8rem;
    color: #6b7280;
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    white-space: nowrap;
}

.table-iaprods td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.table-iaprods tr:last-child td { border-bottom: none; }

.table-iaprods tbody tr {
    transition: background 0.1s ease;
}
.table-iaprods tbody tr:hover { background: #f8faff; }

/* Columna código+nombre compacta */
.td-entity {
    white-space: nowrap;
    min-width: 140px;
}
.td-entity .entity-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.72rem;
    background: #f3f4f6;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    color: #1e3a5f;
    font-weight: 500;
    margin-right: 6px;
}
.td-entity .entity-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: #1f2937;
}

/* Versión ultra compacta */
.td-version {
    white-space: nowrap;
    text-align: center;
    width: 50px;
}
.badge-version {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.62rem;
    font-weight: 600;
    background: #e5e7eb;
    color: #4b5563;
    letter-spacing: 0.2px;
}

/* Badges de estado compactos */
.table-iaprods .badge {
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.45rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fef2f2; color: #991b1b; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-core { background: #dbeafe; color: #1e40af; }
.badge-product { background: #d1e7f5; color: #0f4c81; }

/* Columna especificación — ocupa todo el espacio */
.td-especificacion {
    max-width: 0;
    width: 100%;
}
.td-especificacion .esp-preview {
    font-size: 0.78rem;
    color: #6b7280;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 2.8em;
    cursor: default;
}
.td-especificacion .esp-expandida {
    max-height: none;
    -webkit-line-clamp: unset;
}

/* Columnas de acciones */
.table-iaprods .actions {
    display: flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
    justify-content: flex-end;
}

/* -- Forms -- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--iaprods-text);
}
.form-control {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1.5px solid #e5e7eb;
    border-radius: var(--iaprods-radius);
    font-size: 0.9rem;
    transition: var(--iaprods-transition);
    background: var(--iaprods-white);
    color: var(--iaprods-text);
}
.form-control:focus {
    outline: none;
    border-color: var(--iaprods-violet);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.08);
}
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { appearance: auto; }

/* -- Tabs -- */
.tabs-iaprods {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #f0f0f0;
    margin-bottom: 1.5rem;
}
.tabs-iaprods .tab {
    padding: 0.7rem 1.5rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--iaprods-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--iaprods-transition);
    font-size: 0.92rem;
}
.tabs-iaprods .tab:hover { color: var(--iaprods-violet); }
.tabs-iaprods .tab.active {
    color: var(--iaprods-violet);
    border-bottom-color: var(--iaprods-violet);
}

/* -- Modal -- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.modal-iaprods {
    background: white;
    border-radius: var(--iaprods-radius-lg);
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
/* Modal grande para comparación de especificaciones */
.modal-iaprods.modal-wide {
    max-width: min(1100px, 95vw);
}

textarea.espec-comparison {
    min-height: 250px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.78rem !important;
    line-height: 1.5;
    tab-size: 2;
}
.modal-iaprods .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.modal-iaprods .modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--iaprods-text-muted);
    padding: 0.3rem;
    line-height: 1;
}
.modal-close:hover { color: var(--iaprods-text); }

/* -- Alert / Toast -- */
.toast-iaprods {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    padding: 1rem 1.5rem;
    border-radius: var(--iaprods-radius);
    background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInRight 0.3s ease;
    max-width: 400px;
}
.toast-iaprods.success { border-left: 4px solid #10b981; }
.toast-iaprods.error { border-left: 4px solid #ef4444; }
.toast-iaprods.info { border-left: 4px solid #3b82f6; }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* -- Empty State -- */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--iaprods-text-muted);
}
.empty-state .empty-icon { font-size: 4rem; margin-bottom: 1rem; opacity: 0.3; }
.empty-state h3 { font-size: 1.2rem; margin-bottom: 0.5rem; color: var(--iaprods-text); }
.empty-state p { font-size: 0.9rem; max-width: 400px; margin: 0 auto 1.5rem; }

/* -- Spinner -- */
.spinner {
    width: 24px; height: 24px;
    border: 3px solid #f0f0f0;
    border-top-color: var(--iaprods-violet);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -- Scrollbar -- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* -- Responsive -- */
@media (max-width: 768px) {
    .sidebar-iaprods {
        width: 100%;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--iaprods-border);
    }
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }
    .app-layout { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ===== RELACIONES TABS ===== */
.relations-tabs { display: flex; gap: 0; border-bottom: 2px solid #e5e7eb; margin-bottom: 1rem; }
.relations-tab { padding: 0.6rem 1.2rem; font-size: 0.82rem; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; color: #6b7280; transition: all 0.2s; }
.relations-tab.active { color: #1e3a5f; border-bottom-color: #1e3a5f; font-weight: 600; }
.relations-tab:hover { color: #1e3a5f; }
.rel-panel { display: none; }
.rel-panel.active { display: block; }
.rel-item { display: flex; align-items: center; justify-content: space-between; padding: 0.55rem 0.8rem; background: #f9fafb; border-radius: 6px; margin-bottom: 0.35rem; }

/* ===== FÁBRICA CARDS ===== */
.fabrica-card { background: white; border-radius: 12px; padding: 0; border: none; cursor: default; box-shadow: 0 1px 3px rgba(0,0,0,0.08); overflow: hidden; transition: all 0.25s ease; }
.fabrica-card:hover { box-shadow: 0 6px 20px rgba(30,58,95,0.12); transform: translateY(-3px); }
.fabrica-card-inner { padding: 1.2rem 1.4rem 1rem; }
.fabrica-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.fabrica-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.8rem; color: #1e3a5f; }
.fabrica-section { margin-bottom: 0.6rem; }
.fabrica-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; color: #6b7280; display: block; margin-bottom: 0.35rem; }
.fabrica-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip { background: #f3f4f6; color: #374151; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.72rem; font-weight: 500; border: 1px solid #e5e7eb; white-space: nowrap; }

/* ===== ESPEC COMPARISON ===== */
.espec-grid-wide { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.espec-panel-actual, .espec-panel-mejora { background: white; border-radius: 8px; overflow: hidden; }
.espec-panel-actual { border: 1px solid #e5e7eb; }
.espec-panel-mejora { border: 1px solid #fcd34d; background: #fffbeb; }
.espec-panel-header { padding: 0.5rem 0.8rem; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid inherit; }
.espec-panel-actual .espec-panel-header { background: #f3f4f6; color: #6b7280; }
.espec-panel-mejora .espec-panel-header { background: #fef3c7; color: #92400e; }
.espec-comparison { width: 100%; min-height: 220px; border: none; padding: 0.8rem; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.78rem !important; line-height: 1.5; resize: vertical; outline: none; background: transparent; tab-size: 2; }
.espec-grid-wide .espec-panel-mejora .espec-comparison { color: #92400e; }
.info-box-ia { background: #f0fdf4; padding: 0.8rem 1rem; border-radius: 8px; font-size: 0.8rem; color: #065f46; margin-bottom: 1rem; border: 1px solid #bbf7d0; }

/* ===== FORM HELPERS ===== */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 1.5rem; }
.btn-iaprods-sm { padding: 0.4rem 0.8rem; font-size: 0.78rem; white-space: nowrap; }
.btn-iaprods-success { background: #059669; color: white; }
.btn-iaprods-success:hover { background: #047857; }
.modal-wide #modalContent { max-width: min(1100px, 95vw); }
@media (max-width: 768px) { .espec-grid-wide { grid-template-columns: 1fr; } .form-row-2, .form-row-3 { grid-template-columns: 1fr; } }

/* ===== DASHBOARD LAYOUT ===== */
.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e3a5f;
    margin-bottom: 1rem;
    padding-top: 0.5rem;
}
.stat-card { cursor: pointer; }

/* ===== FABRICA ROW LAYOUT ===== */
.fi-row { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.fi-label { font-size: 0.78rem; min-width: 24px; text-align: center; flex-shrink: 0; }
.fi-icon-only { font-size: 1.1rem; cursor: pointer; transition: all 0.15s; padding: 0 1px; }
.fi-icon-only:hover { transform: scale(1.25); filter: brightness(1.2); }
.fi-chip { padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; cursor: pointer; background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; white-space: nowrap; transition: all 0.15s; }
.fi-chip:hover { background: #e5e7eb; transform: translateY(-1px); }
.fi-more { background: #fef3c7; color: #92400e; border-color: #fcd34d; cursor: default; }

.fabrica-accbar { height: 5px; width: 100%; }
