/* =========================================================
   DESIGN TOKENS
   --color-text:       #1e293b  (Slate 800) — texto principal
   --color-muted:      #64748b  (Slate 500) — texto secundario
   --color-subtle:     #94a3b8  (Slate 400) — placeholders, hints
   --color-border:     #e2e8f0  (Slate 200) — bordes
   --color-bg-panel:   #f8fafc  (Slate 50)  — fondos de paneles
   --color-bg-header:  #f1f5f9  (Slate 100) — fondos de thead
   --color-accent:     #2563eb  (Blue 600)  — acento
   Font scale: 0.72 / 0.78 / 0.875 / 0.95 / 1.1 / 1.5rem
========================================================= */

/* =========================================================
   0. LOGIN SCREEN
========================================================= */

:root {
    --container-side-padding: 20px;
    --page-side-padding: 12px;
    --page-side-margin: 0px;
    --login-bg: #f4f7fb;
    --login-card-border: rgba(148, 163, 184, 0.18);
    --login-shadow: 0 32px 80px rgba(15, 23, 42, 0.12);
}

.login-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #ffffff;
    position: relative;
    overflow: hidden;
}

.app-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(244, 247, 251, 0.90);
    backdrop-filter: blur(6px);
    z-index: 50;
}

.app-loading-overlay.hidden { display: none; }

.app-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #dbeafe;
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: app-spin 0.8s linear infinite;
}

.app-loading-overlay p {
    font-size: 0.875rem;
    color: #475569;
}

@keyframes app-spin { to { transform: rotate(360deg); } }

.login-alert {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 320px;
    max-width: 90vw;
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 0.875rem;
    display: none;
    z-index: 100;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
}
.login-alert.show    { display: block; }
.login-alert.success { background: #ecfeff; color: #0f766e; border: 1px solid #67e8f9; }
.login-alert.error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fca5a5; }
.login-alert.info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #93c5fd; }
.login-alert.warning { background: #fffbeb; color: #b45309; border: 1px solid #fcd34d; }

.login-card {
    width: 100%;
    max-width: 380px;
    background: #ffffff;
    padding: 0;
}

/* Brand block: icon + name + tagline */
.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 36px;
}

.login-mark {
    margin-bottom: 16px;
}
.login-mark img {
    border-radius: 50%;
}

.login-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 6px 0;
    letter-spacing: -0.02em;
}

.login-subtitle {
    font-size: 0.82rem;
    color: #94a3b8;
    margin: 0;
}

/* Fields */
.login-form .login-field { margin-bottom: 16px; }

.login-form .login-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}

.login-form .login-field input {
    width: 100%;
    padding: 11px 14px;
    font-size: 0.9rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    color: #1e293b;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.login-form .login-field input:focus {
    outline: none;
    border-color: #0f172a;
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.07);
}

.login-form .login-field input::placeholder { color: #cbd5e1; }

.login-forgot {
    display: block;
    margin-top: 6px;
    font-size: 0.75rem;
    color: #94a3b8;
    text-decoration: none;
    text-align: right;
}
.login-forgot:hover { color: #0f172a; }

/* Actions */
.login-actions { margin-top: 24px; }

.btn-login {
    width: 100%;
    padding: 11px 18px;
    font-size: 0.875rem;
    font-weight: 600;
    background: #0f172a;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
    letter-spacing: 0.01em;
}
.btn-login:hover:not(:disabled) { opacity: 0.85; }
.btn-login:disabled { opacity: 0.4; cursor: not-allowed; }

/* Divider */
.login-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 16px;
    color: #cbd5e1;
    font-size: 0.75rem;
}
.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #f1f5f9;
}

.btn-register {
    width: 100%;
    padding: 10px 18px;
    font-size: 0.875rem;
    font-weight: 500;
    background: #ffffff;
    color: #475569;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.btn-register:hover:not(:disabled) {
    border-color: #94a3b8;
    color: #0f172a;
}
.btn-register:disabled { opacity: 0.4; cursor: not-allowed; }

/* Footer */
.login-footer {
    margin-top: 40px;
    font-size: 0.72rem;
    color: #cbd5e1;
}

@media (max-width: 480px) {
    .login-screen { padding: 20px; }
    .login-card { max-width: 100%; }
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}
.modal-overlay.open { display: flex; }

.modal-card {
    width: 100%;
    max-width: 400px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.20);
    padding: 28px 32px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover { color: #64748b; }

.modal-description {
    font-size: 0.875rem;
    color: #64748b;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Alert modal */
.alert-modal-card {
    max-width: 440px;
    animation: alertModalIn 0.2s ease;
}

.alert-modal-card .modal-header h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-modal-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
}
.alert-modal-icon.error { background: #fef2f2; color: #dc2626; }
.alert-modal-icon.warning { background: #fffbeb; color: #d97706; }
.alert-modal-icon.info { background: #eff6ff; color: #2563eb; }

.alert-modal-body-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.alert-modal-body-list li {
    padding: 6px 10px;
    background: #f8fafc;
    border-left: 3px solid #e2e8f0;
    border-radius: 0 6px 6px 0;
    font-size: 0.82rem;
    color: #1e293b;
}

.alert-modal-body-list li.error-item { border-left-color: #fca5a5; }
.alert-modal-body-list li.warning-item { border-left-color: #fcd34d; }

.alert-modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

@keyframes alertModalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* =========================================================
   1. RESET & BASE
========================================================= */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: #ffffff;
    min-height: 100vh;
    padding: 24px 12px;
    color: #1e293b;
    font-size: 0.875rem;
    line-height: 1.5;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
    padding: 0 var(--container-side-padding);
}

#pagePredicciones,
#pageOptimizacion,
#pagePromos,
#pageAdmin {
    margin-left: var(--page-side-margin);
    margin-right: var(--page-side-margin);
    padding-left: var(--page-side-padding);
    padding-right: var(--page-side-padding);
}

/* Refuerzo visual: mismo sangrado lateral en todas las grillas de página */
#pagePredicciones .main-grid,
#pageOptimizacion .main-grid,
#pagePromos .main-grid,
#pageAdmin .main-grid {
    padding-left: var(--page-side-padding);
    padding-right: var(--page-side-padding);
}

/* =========================================================
   2. HEADER & NAVIGATION
========================================================= */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 8px;
    flex-wrap: wrap;
    gap: 12px;
}

.header-title { display: flex; flex-direction: column; }

.header-user { display: flex; align-items: center; gap: 12px; }

.header-user #userStatus {
    font-size: 0.78rem;
    color: #64748b;
    padding: 5px 10px;
    background: #f1f5f9;
    border-radius: 6px;
    font-weight: 500;
}

#btnLogout {
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: 6px;
    background: transparent;
    color: #64748b;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s ease;
}
#btnLogout:hover { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #2563eb;
    letter-spacing: -0.02em;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 24px;
    margin: 16px 0 24px;
    padding: 10px 2px;
    border-bottom: 1px solid #e2e8f0;
}

.top-nav button {
    background: transparent;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    position: relative;
    transition: color 0.15s ease;
    padding: 0;
}

.top-nav button:hover { color: #1e293b; }

.top-nav button.active {
    color: #1e293b;
    font-weight: 600;
}

.top-nav button.active::after {
    content: "";
    position: absolute;
    bottom: -11px;
    left: 0;
    width: 100%;
    height: 2px;
    background: #2563eb;
    border-radius: 2px;
}

/* =========================================================
   3. LAYOUT
========================================================= */

.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.filters-panel,
.results-panel {
    background: #f8fafc;
    padding: 16px 18px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.content-panel {
    padding: 16px 18px;
}

/* =========================================================
   4. TITLES
========================================================= */

.section-title,
.results-title-bar,
.results-title-summary {
    margin: 0 0 12px 0;
    font-weight: 600;
    font-size: 0.875rem;
    color: #1e293b;
    letter-spacing: -0.01em;
}

/* =========================================================
   5. FILTERS
========================================================= */

.filters-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(80px, 1fr));
    gap: 10px 10px;
    margin-bottom: 16px;
    align-items: end;
}

.filters-grid-predicciones {
    grid-template-columns: repeat(6, minmax(70px, 1fr));
    gap: 10px 8px;
}

.filters-grid-predicciones .filter-ean13 { grid-column: span 2; }
.filters-grid-predicciones .filter-group { padding: 5px 6px; }

/* Font unificado para filtros */
.filters-grid-predicciones .filter-group label,
.filters-grid-predicciones input,
.filters-grid-predicciones select,
.filters-grid-predicciones .dropdown-btn,
.filters-grid-predicciones .dropdown-content,
.filters-grid-predicciones .dropdown-content label,
.filters-grid-predicciones .ean-combobox-item,
.filters-grid-predicciones .ean-selectpicker-btn,
.filters-grid-predicciones .ean-selectpicker-search,
.filters-grid-predicciones .ean-selectpicker-item {
    font-size: 0.78rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    padding: 6px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    overflow: visible;
}

.filter-group label {
    font-size: 0.72rem;
    color: #64748b;
    margin-bottom: 5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-group input[type="text"],
.filter-group input[type="number"],
.filter-group input[type="date"],
.filter-group select,
.filter-group .dropdown-btn {
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 5px 0;
    background: transparent;
    font-size: 0.78rem;
    color: #1e293b;
    transition: border-color 0.15s;
}

.filter-group input:focus,
.filter-group select:focus,
.filter-group .dropdown-btn:focus {
    outline: none;
    border-bottom-color: #2563eb;
}

.filter-group input::placeholder { color: #94a3b8; }

.filter-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-weight: 500;
}

/* Toggle switch */
.toggle-switch-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    cursor: pointer;
}

.toggle-switch-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch-slider {
    position: relative;
    width: 40px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 20px;
    transition: background 0.25s ease;
    flex-shrink: 0;
}

.toggle-switch-slider::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.25s ease;
}

.toggle-switch-input:checked + .toggle-switch-slider { background: #2563eb; }
.toggle-switch-input:checked + .toggle-switch-slider::after { transform: translateX(20px); }

/* EAN combobox */
.ean-combobox-search {
    width: 100%;
    margin-bottom: 8px;
    padding: 5px 0;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    background: transparent;
    font-size: 0.78rem;
    color: #1e293b;
}
.ean-combobox-search:focus { outline: none; border-bottom-color: #2563eb; }
.ean-combobox-list { max-height: 220px; overflow-y: auto; }

/* =========================================================
   6. DROPDOWN DESCUENTO
========================================================= */

.custom-dropdown { position: relative; width: 100%; }

.dropdown-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    text-align: left;
}

.dropdown-content {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 6px;
    min-width: 180px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.10);
    padding: 6px;
    max-height: 220px;
    overflow-y: auto;
    font-size: 0.78rem;
    z-index: 100;
    display: none;
}
.dropdown-content.open { display: block; }

.dropdown-content label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 6px;
    color: #1e293b;
}
.dropdown-content label:hover { background: #f1f5f9; }

/* =========================================================
   7. BUTTONS
========================================================= */

button {
    padding: 7px 14px;
    border-radius: 7px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: 0.15s ease;
}

.btn-primary {
    background: #2e7d32;
    color: #ffffff;
}
.btn-primary:hover { background: #1b5e20; }

.btn-secondary {
    background: #ffffff;
    color: #475569;
    border: 1px solid #e2e8f0;
}
.btn-secondary:hover { background: #f1f5f9; border-color: #cbd5e1; }

.btn-primary.btn-loading,
.btn-secondary.btn-loading {
    pointer-events: none;
    cursor: wait;
    opacity: 0.80;
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
.btn-secondary .spinner {
    border-color: rgba(71, 85, 105, 0.25);
    border-top-color: #475569;
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   8. CHARTS
========================================================= */

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.results-grid-predicciones {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
}

.chart-box {
    background: #ffffff;
    border-radius: 10px;
    padding: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    width: 100%;
    height: 400px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.chart-box canvas { flex: 1; min-height: 0; }

/* =========================================================
   9. TABLES — sistema unificado
========================================================= */

.table-container {
    overflow: auto;
    max-height: 700px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-top: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
}

table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f1f5f9;
}

table th {
    padding: 7px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

table td {
    padding: 6px 10px;
    font-size: 0.78rem;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
}

table tbody tr:hover { background: #f8fafc; }

.empty-state {
    text-align: center !important;
    color: #94a3b8;
    font-style: italic;
    padding: 20px !important;
}

/* Tabla Resumen Promocional (Predicciones) */
#resultsTable {
    table-layout: fixed;
    font-size: 0.72rem;
    width: 100%;
}
#resultsTable th,
#resultsTable td { padding: 5px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#resultsTable thead th { text-align: center; font-weight: 600; }
#resultsTable tbody td { text-align: right; }
#resultsTable thead th:not(:last-child),
#resultsTable tbody td:not(:last-child) { border-right: 1px solid #e2e8f0; }
#resultsTable th:nth-child(1) { width: 110px; }
#resultsTable th:nth-child(2) { width: 180px; }
#resultsTable th:nth-child(n+3) { width: 95px; }

/* Tabla Promociones */
.promos-table { table-layout: fixed; }
.promos-table th,
.promos-table td { padding: 5px 8px; width: 12.5%; }
.promos-table thead th { text-align: center; }
.promos-table tbody td { text-align: right; }
.promos-table thead th:not(:last-child),
.promos-table tbody td:not(:last-child) { border-right: 1px solid #e2e8f0; }
.promos-table thead th:nth-child(3),
.promos-table tbody td:nth-child(3) { width: 25%; }

/* Tablas Optimización: Escenarios + Detalle SKU */
#optScenarioTable,
#optTable {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
}

#optScenarioTable thead,
#optTable thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f1f5f9;
}

#optScenarioTable th,
#optTable th {
    padding: 6px 6px;
    font-size: 0.68rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #e2e8f0;
    text-align: center;
    white-space: nowrap;
}

#optScenarioTable td,
#optTable td {
    padding: 5px 6px;
    font-size: 0.75rem;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
}

#optScenarioTable tbody td:first-child,
#optTable tbody td:first-child,
#optTable tbody td:nth-child(2) {
    text-align: left;
}

#optScenarioTable thead th:not(:last-child),
#optScenarioTable tbody td:not(:last-child),
#optTable thead th:not(:last-child),
#optTable tbody td:not(:last-child) {
    border-right: 1px solid #e2e8f0;
}

#optScenarioTable tbody tr:hover,
#optTable tbody tr:hover { background: #f8fafc; }

#optTable { table-layout: fixed; }
#optTable th:nth-child(1) { width: 105px; }
#optTable th:nth-child(2) { width: 180px; }
#optTable th:nth-child(n+3) { width: 90px; }

.opt-scenario-row {
    cursor: pointer;
    transition: background 0.12s ease;
}
.opt-scenario-row.active {
    background: #eff6ff;
    box-shadow: inset 3px 0 0 #2563eb;
}
.opt-scenario-row:hover { background: #f1f5f9; }

/* =========================================================
   10. FOOTER
========================================================= */

.footer {
    margin-top: 40px;
    text-align: center;
    font-size: 0.72rem;
    color: #94a3b8;
    padding: 20px 0;
    border-top: 1px solid #e2e8f0;
}

/* =========================================================
   11. ALERTS
========================================================= */

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 0.78rem;
    display: none;
}
.alert.show { display: block; }

/* =========================================================
   12. RESPONSIVE
========================================================= */

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

@media (max-width: 768px) {
    .filters-grid,
    .filters-grid-predicciones { grid-template-columns: 1fr; }
    .opt-main-row { flex-direction: column; height: auto; }
    .opt-scatter-right { min-height: 320px; }
    .results-grid,
    .results-grid-predicciones { grid-template-columns: 1fr; }
    button { width: 100%; }
}

/* =========================================================
   EAN SELECTPICKER — Optimización
========================================================= */

.ean-selectpicker-wrapper {
    width: 100%;
    max-width: 50%;
}

.opt-ean-selectpicker-group { grid-column: span 2; }
.opt-ean-selectpicker-group .ean-selectpicker-wrapper { max-width: 100%; }

.ean-selectpicker { position: relative; width: 100%; }

.ean-selectpicker-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    font-size: 0.78rem;
    color: #1e293b;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s;
}
.ean-selectpicker-btn:hover { border-color: #94a3b8; }
.ean-selectpicker-btn[aria-expanded="true"] {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.ean-selectpicker-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ean-selectpicker-arrow {
    margin-left: 6px;
    font-size: 0.65rem;
    color: #94a3b8;
}

.ean-selectpicker-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 100%;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.10);
    z-index: 200;
    overflow: hidden;
}
.ean-selectpicker-dropdown.open { display: block; }

.ean-selectpicker-search {
    width: 100%;
    padding: 6px 8px;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.78rem;
    background: #f8fafc;
    color: #1e293b;
}
.ean-selectpicker-search:focus { outline: none; }

.ean-selectpicker-list { max-height: 320px; overflow-y: auto; }

.ean-family-group {
    border-bottom: 1px solid #e2e8f0;
}
.ean-family-group:last-child { border-bottom: none; }

.ean-family-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    background: #f8fafc;
    user-select: none;
    transition: background 0.12s;
}
.ean-family-header:hover { background: #f1f5f9; }

.ean-family-toggle {
    font-size: 0.6rem;
    color: #94a3b8;
    width: 12px;
    flex-shrink: 0;
}

.ean-family-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: #1e293b;
    flex: 1;
    text-transform: capitalize;
}

.ean-family-count {
    font-size: 0.65rem;
    color: #94a3b8;
    white-space: nowrap;
}

.ean-family-add-btn {
    font-size: 0.62rem;
    font-weight: 600;
    color: #2563eb;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}
.ean-family-add-btn:hover {
    background: rgba(37, 99, 235, 0.16);
    color: #1d4ed8;
}
.ean-family-add-btn.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.ean-family-items {
    padding-left: 20px;
}

.ean-selectpicker-item {
    padding: 5px 8px;
    font-size: 0.74rem;
    color: #334155;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.1s;
}
.ean-selectpicker-item:hover { background: #f1f5f9; }
.ean-selectpicker-item.disabled { opacity: 0.4; cursor: default; }
.ean-selectpicker-item.disabled:hover { background: transparent; }

/* Tabla EANs seleccionados — colapsable */
.opt-ean-collapsible { width: 100%; }

.opt-ean-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    margin-bottom: 6px;
    transition: background 0.15s ease;
    user-select: none;
}
.opt-ean-toggle-btn:hover { background: #f1f5f9; }

.opt-ean-toggle-count {
    font-size: 0.7rem;
    font-weight: 700;
    color: #2563eb;
    background: #eff6ff;
    padding: 1px 7px;
    border-radius: 10px;
}

.opt-ean-table-container-collapsed { display: none; }

.opt-ean-table-wrapper {
    margin-top: 0;
    width: 100%;
    max-width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: auto;
}

.opt-ean-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.opt-ean-table th,
.opt-ean-table td {
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.opt-ean-table th:not(:last-child),
.opt-ean-table td:not(:last-child) { border-right: 1px solid #e2e8f0; }

/* EAN13: columna más angosta */
.opt-ean-table th:nth-child(1),
.opt-ean-table td:nth-child(1) { width: 95px; min-width: 95px; white-space: nowrap; }
/* Producto: ancho ampliado para texto completo */
.opt-ean-table th:nth-child(2),
.opt-ean-table td:nth-child(2) { width: 340px; white-space: normal; word-wrap: break-word; overflow-wrap: break-word; }
/* Precio SCC, GSV, PVS */
.opt-ean-table th:nth-child(3),
.opt-ean-table td:nth-child(3),
.opt-ean-table th:nth-child(4),
.opt-ean-table td:nth-child(4),
.opt-ean-table th:nth-child(5),
.opt-ean-table td:nth-child(5) { width: 90px; min-width: 80px; }
/* Quitar: mitad del ancho de columna precio */
.opt-ean-table th:nth-child(6),
.opt-ean-table td:nth-child(6) { width: 50px; min-width: 50px; padding: 5px 2px; text-align: center; }

.opt-ean-table th {
    background: #f1f5f9;
    font-weight: 700;
    font-size: 0.72rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.opt-ean-table tbody tr:last-child td { border-bottom: none; }
.opt-ean-table tbody tr:hover { background: #f8fafc; }

.opt-ean-empty-row td { color: #94a3b8; font-style: italic; text-align: center; }

.opt-ean-table input[type="number"] {
    width: 100%;
    min-width: 60px;
    padding: 3px 5px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    font-size: 0.75rem;
    color: #1e293b;
}
.opt-ean-table input[type="number"]:focus { outline: none; border-color: #2563eb; }

.opt-ean-table .btn-remove-ean {
    padding: 2px 4px;
    font-size: 0.65rem;
    background: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
}
.opt-ean-table .btn-remove-ean:hover { background: #fecaca; }

/* =========================================================
   EAN COMBOBOX — Predicciones
========================================================= */

.ean-combobox .dropdown-btn { min-width: 0; }
.ean-combobox .dropdown-btn span:first-child {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.ean-combobox .dropdown-content { min-width: 320px; }

.ean-combobox-item {
    padding: 6px 8px;
    font-size: 0.78rem;
    color: #1e293b;
    cursor: pointer;
    border-radius: 5px;
}
.ean-combobox-item:hover { background: #f1f5f9; }

/* Chips */
.ean-chips-container { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ean-chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; margin-top: 8px; }

.ean-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 20px;
    font-size: 0.75rem;
    color: #1e40af;
}
.ean-chip .chip-price { font-weight: 600; }
.ean-chip .chip-remove { cursor: pointer; color: #64748b; font-size: 1rem; line-height: 1; }
.ean-chip .chip-remove:hover { color: #dc2626; }

/* =========================================================
   OPTIMIZACIÓN — Layout específico
========================================================= */

.opt-results {
    min-height: 200px;
    padding: 16px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

/* Secciones del content panel */
.opt-content-section { padding: 16px 0; }
.opt-content-section:first-child { padding-top: 0; }

/* Tarjetas resumen optimización */
.opt-summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.opt-summary-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.opt-summary-card-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}

.opt-summary-card-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
}

@media (max-width: 768px) {
    .opt-summary-cards { grid-template-columns: repeat(2, 1fr); }
}

.opt-section-detail-sku {
    border-top: 1px solid #e2e8f0;
    margin-top: 4px;
    padding-top: 20px;
}

/* Fila filtro escenario */
.opt-scenario-filter-row {
    display: flex;
    align-items: center;
    margin-top: 6px;
    margin-bottom: 10px;
}

.opt-scenario-filter-top {
    margin-top: 0;
    margin-bottom: 14px;
}

.opt-table-left .section-title,
.opt-table-solutions-title,
.opt-scatter-title {
    margin-bottom: 12px;
}

.opt-scenario-filter-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 10px 18px;
}

.opt-scenario-filter-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.opt-scenario-select {
    flex: 1;
    min-width: 200px;
    padding: 7px 12px;
    font-size: 0.78rem;
    border: 1px solid #94a3b8;
    border-radius: 6px;
    background: #ffffff;
    color: #1e293b;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 5.5l6.5 6 6.5-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}
.opt-scenario-select:hover {
    border-color: #64748b;
    background: #f8fafc;
}
.opt-scenario-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}
.opt-scenario-select option {
    background: #ffffff;
    color: #1e293b;
}

/* Fila principal: tabla izquierda | scatter derecha — misma altura */
.opt-main-row {
    display: flex;
    gap: 20px;
    align-items: stretch;
    height: 500px;
}

.opt-table-left {
    flex: 0 0 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.opt-table-left .table-container {
    flex: 1;
    overflow-y: auto;
    max-height: none;
    min-height: 420px;
    margin-top: 0;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

.opt-scatter-right {
    flex: 0 0 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Header scatter: misma estructura que tabla para alineación */
.opt-scatter-header { flex-shrink: 0; }

/* Tabla escenarios: columnas compactas */
.opt-scenario-compact,
.opt-scenario-compact table,
.opt-scenario-compact #optScenarioTable {
    font-size: 0.75rem;
}
.opt-scenario-radio-col { width: 36px; padding: 6px 8px !important; text-align: center; }
.opt-scenario-radio-cell { text-align: center; padding: 6px 8px !important; vertical-align: middle; }
.opt-scenario-radio-cell input[type="radio"] { cursor: pointer; margin: 0; }

#optScenarioTable th,
#optScenarioTable td {
    padding: 5px 5px;
    font-size: 0.72rem;
}

.opt-scenario-compact #optScenarioTable th:nth-child(1),
.opt-scenario-compact #optScenarioTable td:nth-child(1) {
    white-space: nowrap;
    min-width: 150px;
    text-align: left;
}
#optScenarioTable th:last-child,
#optScenarioTable td:last-child {
    width: 50px;
    max-width: 50px;
}

.opt-scatter-wrap { flex: 1; min-width: 0; }

.opt-pareto-note {
    margin: 0 0 6px;
    font-size: 0.75rem;
    color: #94a3b8;
}

.opt-pareto-chart-wrap {
    flex: 1;
    min-height: 420px;
    min-width: 0;
    padding: 14px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.opt-detail-section { margin-top: 0; }

#pageOptimizacion .action-buttons {
    margin-top: 14px;
    gap: 10px;
}

/* =========================================================
   LEGACY / MISC
========================================================= */

.opt-selected-card { display: flex; flex-direction: column; gap: 10px; }
.opt-selected-title { font-size: 0.875rem; font-weight: 600; color: #1e293b; }
.opt-selected-list {
    margin: 0;
    padding-left: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.78rem;
    color: #1e293b;
}
.opt-selected-list li { line-height: 1.4; }

#optLambdaGroup { display: flex; align-items: center; gap: 8px; }
#optLambdaGroup input[type="range"] { flex: 1; min-width: 80px; }

.opt-ean-option {
    display: block;
    padding: 5px 8px;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.opt-ean-option:hover { background: #f1f5f9; border-radius: 5px; }

.ean-multiselect .dropdown-content { min-width: 0; }

.ean-chips-container input {
    flex: 1;
    min-width: 180px;
    padding: 7px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    font-size: 0.78rem;
}
