:root {
    /* ── Paleta legacy: NO TOCAR (el chat IA depende de estos valores) ── */
    --bg-color: hsl(210, 20%, 98%);
    --surface-color: hsl(0, 0%, 100%);
    --border-color: hsl(214, 15%, 91%);
    --text-main: hsl(215, 25%, 15%);
    --text-muted: hsl(215, 15%, 45%);
    --brand-primary: hsl(215, 90%, 45%);
    --brand-primary-hover: hsl(215, 90%, 35%);
    --brand-accent: hsl(150, 60%, 40%);
    --brand-warning: hsl(35, 90%, 50%);
    --danger: hsl(350, 70%, 50%);
    --success: hsl(192, 75%, 38%);

    /* ── Estilo Igor: 3D isométrico táctil ── */
    --ig-base: hsl(33, 65%, 95%);          /* crema papel de fondo */
    --ig-violet: hsl(262, 62%, 57%);       /* morado vibrante dominante */
    --ig-violet-deep: hsl(260, 55%, 44%);
    --ig-violet-soft: hsl(262, 75%, 94%);  /* lila pálido */
    --ig-orange: hsl(24, 92%, 55%);        /* acento naranja lúdico */
    --ig-sky: hsl(192, 80%, 40%);          /* celeste/turquesa */
    --ig-paper: hsl(45, 100%, 99%);        /* blanco hoja cálida */
    --ig-ink: hsl(262, 32%, 22%);          /* tinta principal */
    --ig-muted: hsl(262, 16%, 52%);
    --ig-line: hsl(34, 45%, 84%);          /* línea cutting mat */

    --shadow-sm: 0 1px 3px rgba(84, 48, 150, 0.08);
    --shadow-md: 0 8px 20px -4px rgba(84, 48, 150, 0.14);
    --shadow-lg: 0 24px 48px -12px rgba(84, 48, 150, 0.28);
    /* Arcilla: luz arriba-izquierda + oclusión suave abajo-derecha */
    --clay: inset 2px 2px 6px rgba(255,255,255,0.9), inset -3px -4px 10px rgba(120, 80, 200, 0.07);
    --radius-md: 18px;
    --radius-lg: 26px;

    --transition: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--ig-base);
    /* Cutting mat: cuadrícula técnica sobre la base de trabajo */
    background-image:
        linear-gradient(hsla(34, 45%, 78%, 0.35) 1px, transparent 1px),
        linear-gradient(90deg, hsla(34, 45%, 78%, 0.35) 1px, transparent 1px);
    background-size: 28px 28px;
    color: var(--ig-ink);
    display: flex;
    justify-content: center;
    padding: 2.5rem 1rem;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.header-titles h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 0.4rem 0;
    color: var(--ig-ink);
}

/* Ruta ERP→Tienda como sticker pegado */
.route-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ig-muted);
    box-shadow: var(--shadow-sm), var(--clay);
    transform: rotate(-1deg);
}

.route-chip .route-arrow {
    color: var(--ig-orange);
    font-size: 1rem;
    line-height: 1;
}

/* Custom Select */
.select-wrapper {
    position: relative;
    display: inline-block;
}

.select-wrapper select {
    appearance: none;
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: 14px;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ig-ink);
    cursor: pointer;
    box-shadow: var(--shadow-sm), var(--clay);
    transition: var(--transition);
}

.select-wrapper select:hover {
    border-color: var(--ig-violet);
}

.select-wrapper select:focus {
    outline: none;
    border-color: var(--ig-violet);
    box-shadow: 0 0 0 3px hsla(262, 62%, 57%, 0.18), var(--clay);
}

.select-wrapper svg {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    pointer-events: none;
    color: var(--ig-muted);
}

/* Sync Banner: base morada con cuadrícula blanca tipo cutting mat */
.sync-banner {
    background:
        linear-gradient(hsla(0, 0%, 100%, 0.12) 1px, transparent 1px),
        linear-gradient(90deg, hsla(0, 0%, 100%, 0.12) 1px, transparent 1px),
        linear-gradient(160deg, var(--ig-violet), var(--ig-violet-deep));
    background-size: 22px 22px, 22px 22px, cover;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-lg), var(--clay);
    flex-wrap: wrap;
    gap: 1rem;
}

/* Stats como stickers de papel pegados a la base */
.stat-badge {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ig-ink);
    margin-right: 0.5rem;
    display: inline-block;
    box-shadow: var(--shadow-sm), var(--clay);
    transform: rotate(-2deg);
}

.sync-stats .stat-badge:nth-child(2) {
    transform: rotate(1.5deg);
}

.sync-controls {
    display: flex;
    gap: 0.75rem;
}

/* Buttons: bloques táctiles con efecto presión */
.btn {
    appearance: none;
    border: none;
    border-radius: 16px;
    padding: 0.65rem 1.3rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(160deg, var(--ig-violet), var(--ig-violet-deep));
    color: #fffdf8;
    box-shadow: var(--shadow-md), var(--clay);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(160deg, hsl(262, 62%, 61%), var(--ig-violet));
    transform: translateY(-2px) rotate(-0.5deg);
    box-shadow: var(--shadow-lg), var(--clay);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-sm), var(--clay);
}

.btn-secondary {
    background: var(--ig-paper);
    color: var(--ig-ink);
    border: 1.5px solid var(--ig-line);
    box-shadow: var(--shadow-sm), var(--clay);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--ig-violet-soft);
    border-color: var(--ig-violet);
    color: var(--ig-violet-deep);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), var(--clay);
}

.btn-secondary:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

/* Botón análisis offline: acento turquesa */
.btn-offline {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-sky);
    color: var(--ig-sky);
}

.btn-offline:hover:not(:disabled) {
    background: var(--ig-paper);
    box-shadow: var(--shadow-md), var(--clay);
}

/* Split View */
.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.panel {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: 60vh;
    min-height: 400px;
    box-shadow: var(--shadow-md), var(--clay);
    overflow: hidden;
}

.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1.5px solid var(--ig-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--ig-violet-soft);
}

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    color: var(--ig-violet-deep);
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: var(--ig-orange);
    border-radius: 50%;
    box-shadow: 0 0 0 rgba(255, 140, 66, 0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 140, 66, 0.5); }
    70% { box-shadow: 0 0 0 7px rgba(255, 140, 66, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 140, 66, 0); }
}

.panel-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* List Items */
.list-item {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--ig-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.list-item:hover {
    background: var(--ig-violet-soft);
}

.list-item:last-child {
    border-bottom: none;
}

.item-main {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-width: 70%;
}

.item-sku {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    color: var(--ig-muted);
}

.item-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ig-ink);
}

.item-price {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ig-ink);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: hsla(262, 45%, 30%, 0.35);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: var(--radius-lg);
    width: 80%;
    max-width: 80vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg), var(--clay);
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition);
}

.modal-overlay.active .modal-card {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1.5px solid var(--ig-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--ig-violet-soft);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ig-violet-deep);
}

.btn-close {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    font-size: 1.2rem;
    color: var(--ig-muted);
    cursor: pointer;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

.btn-close:hover {
    background: var(--ig-paper);
    border-color: var(--ig-orange);
    color: var(--ig-orange);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1.5px solid var(--ig-line);
    display: flex;
    justify-content: flex-end;
    background: var(--ig-base);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.diff-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.diff-table th {
    text-align: left;
    padding: 0.75rem;
    color: var(--ig-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--ig-line);
}

.diff-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--ig-line);
    color: var(--ig-ink);
}

.diff-table tr:hover td {
    background: var(--ig-violet-soft);
}

.status-text {
    color: var(--ig-violet);
    font-weight: 600;
}

/* Skeleton loader */
.skeleton-loader {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--ig-paper) 25%, var(--ig-violet-soft) 50%, var(--ig-paper) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (max-width: 768px) {
    .split-view {
        grid-template-columns: 1fr;
    }
    .panel {
        height: 50vh;
    }
}

/* ============================================================
   Sistema Panel – Estado APIs + Logs + Snapshots
   ============================================================ */
.sistema-panel {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm), var(--clay);
    overflow: hidden;
}

.sistema-toggle {
    width: 100%;
    background: none;
    border: none;
    padding: 0.9rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ig-ink);
    transition: background var(--transition);
}

.sistema-toggle:hover {
    background: var(--ig-violet-soft);
}

.sistema-toggle-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sistema-toggle .chevron {
    transition: transform 0.25s ease;
    color: var(--ig-muted);
}

.sistema-panel.open .chevron {
    transform: rotate(180deg);
}

.api-status-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
    background: var(--ig-base);
    border: 1px solid var(--ig-line);
    color: var(--ig-muted);
}

.api-status-badge.ok   { background: hsl(192 80% 40% / 0.12); border-color: var(--ig-sky); color: var(--ig-sky); }
.api-status-badge.warn { background: hsl(24 92% 55% / 0.14);  border-color: var(--ig-orange); color: hsl(24, 80%, 42%); }
.api-status-badge.err  { background: hsl(350 70% 50% / 0.12); border-color: var(--danger); color: var(--danger); }

/* collapsible body */
.sistema-body {
    display: none;
    border-top: 1.5px solid var(--ig-line);
}

.sistema-panel.open .sistema-body {
    display: block;
}

.sistema-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 0;
}

/* Left col – API status + snapshot buttons */
.sistema-status-col {
    padding: 1rem;
    border-right: 1.5px solid var(--ig-line);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.api-status-card {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.api-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--ig-muted);
}

.api-label {
    font-weight: 600;
    color: var(--ig-ink);
}

.api-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: background 0.3s;
}

.api-dot-unknown { background: var(--ig-line); }
.api-dot-ok      { background: var(--ig-sky);    box-shadow: 0 0 0 3px hsl(192 80% 40% / 0.2); }
.api-dot-err     { background: var(--danger);    box-shadow: 0 0 0 3px hsl(350 70% 50% / 0.2); }

.snapshot-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn-snapshot {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    color: var(--ig-ink);
    font-size: 0.8rem;
    padding: 0.45rem 0.8rem;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    box-shadow: var(--shadow-sm), var(--clay);
}

.btn-snapshot:hover:not(:disabled) {
    background: var(--ig-violet-soft);
    border-color: var(--ig-violet);
    color: var(--ig-violet-deep);
}

.btn-snapshot:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Right col – log terminal */
.sistema-log-col {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.log-header {
    padding: 0.55rem 1rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ig-violet-deep);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1.5px solid var(--ig-line);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--ig-violet-soft);
}

.log-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ig-line);
    transition: background 0.3s;
}

.log-dot.active {
    background: var(--ig-orange);
    animation: pulse 2s infinite;
}

.log-output {
    height: 180px;
    max-height: 180px;
    overflow-y: auto;
    padding: 0.6rem 1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.72rem;
    line-height: 1.6;
    color: hsl(262, 20%, 75%);
    /* Pantilla de juguete: violeta noche en vez de negro puro */
    background: hsl(262, 35%, 13%);
    white-space: pre-wrap;
    word-break: break-all;
}

.log-output .log-line { display: block; }
.log-output .log-line.err  { color: hsl(350, 80%, 72%); }
.log-output .log-line.warn { color: hsl(30, 95%, 68%); }
.log-output .log-line.ok   { color: hsl(178, 70%, 62%); }

@media (max-width: 700px) {
    .sistema-grid { grid-template-columns: 1fr; }
    .sistema-status-col { border-right: none; border-bottom: 1.5px solid var(--ig-line); }
}

/* Chat AI Styles */
.chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-primary), #162d52);
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(26, 54, 93, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 1000;
}

.chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(26, 54, 93, 0.5);
}

.chat-container {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 360px;
    height: 520px;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.97);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-container.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.chat-header {
    background: linear-gradient(135deg, var(--brand-primary) 0%, #162d52 100%);
    color: white;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-avatar {
    font-size: 22px;
    line-height: 1;
    background: rgba(255,255,255,0.15);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
}

.chat-status {
    font-size: 11px;
    opacity: 0.75;
    display: block;
    margin-top: 1px;
}

.btn-close-sm {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    cursor: pointer;
    font-size: 14px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-close-sm:hover {
    background: rgba(255,255,255,0.25);
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: var(--bg-color);
    min-height: 0;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    animation: msgFadeIn 0.2s ease;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-msg {
    align-self: flex-start;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.user-msg {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--brand-primary), #162d52);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    padding: 12px 14px;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

#chatInput {
    flex: 1;
    padding: 9px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 22px;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    background-color: var(--bg-color);
    color: var(--text-main);
    transition: border-color 0.2s;
}

#chatInput:focus {
    border-color: var(--brand-primary);
}

.btn-chat-send {
    background: linear-gradient(135deg, var(--brand-primary), #162d52);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.btn-chat-send:hover {
    opacity: 0.85;
    transform: scale(1.05);
}

.btn-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Chat thinking indicator */
.chat-msg.ai-msg.loading {
    color: transparent;
    min-width: 60px;
}

.chat-msg.ai-msg.loading::after {
    content: "";
    position: absolute;
    left: 14px;
    top: 50%;
    margin-top: -8px;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

@media (max-width: 420px) {
    .chat-container {
        width: calc(100vw - 24px);
        right: 12px;
        height: 480px;
    }
}


/* ===== Autenticación OTP ===== */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(24, 34, 96, 0.72);
    backdrop-filter: blur(6px);
}

body.authenticated .auth-overlay {
    display: none;
}

.auth-card {
    width: min(420px, 100%);
    padding: 1.75rem;
    border-radius: 1.25rem;
    background: var(--cream, #fffdf5);
    box-shadow: 0 24px 60px rgba(24, 34, 96, 0.35);
}

.auth-card h2 {
    margin: 0 0 0.35rem;
    color: var(--brand-primary, #182260);
}

.auth-help {
    margin: 0 0 1.25rem;
    color: var(--text-muted, #667085);
    font-size: 0.92rem;
}

.auth-card label {
    display: block;
    margin: 0.75rem 0 0.35rem;
    color: var(--brand-primary, #182260);
    font-size: 0.85rem;
    font-weight: 600;
}

.auth-card input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.75rem 0.85rem;
    border: 1px solid rgba(24, 34, 96, 0.2);
    border-radius: 0.75rem;
    background: #fff;
    color: #182260;
    font: inherit;
}

.auth-code-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.auth-code-row > div {
    flex: 1;
}

.auth-code-row .btn {
    margin-bottom: 0.05rem;
    white-space: nowrap;
}

.auth-submit {
    width: 100%;
    margin-top: 1rem;
}

.auth-message {
    min-height: 1.25rem;
    margin-top: 0.85rem;
    font-size: 0.85rem;
    color: var(--danger, #b42318);
}

.auth-message.ok {
    color: var(--success, #067647);
}

.btn-logout {
    display: none;
}

body.authenticated .btn-logout {
    display: inline-flex;
}

/* --- Ventas (ERP) Modal & Controls (Estilo Igor) --- */
.btn-ventas {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-orange);
    color: var(--ig-orange);
    box-shadow: var(--shadow-sm), var(--clay);
}

.btn-ventas:hover:not(:disabled) {
    background: hsla(24, 95%, 53%, 0.1);
    border-color: var(--ig-orange);
    color: var(--ig-orange);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), var(--clay);
}

.modal-card-sales {
    width: 94%;
    max-width: 1080px;
}

.modal-header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.sales-chip {
    transform: none !important;
    font-size: 0.75rem !important;
    padding: 0.2rem 0.65rem !important;
}

.sales-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1.5px solid var(--ig-line);
}

.sales-presets {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.btn-preset {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ig-muted);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.btn-preset:hover {
    border-color: var(--ig-violet);
    color: var(--ig-violet-deep);
}

.btn-preset.active {
    background: var(--ig-violet);
    border-color: var(--ig-violet-deep);
    color: #fff;
    box-shadow: var(--shadow-sm), var(--clay);
}

.sales-dates {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sales-date-sep {
    color: var(--ig-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.sales-input-date,
.sales-input-search {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: 12px;
    padding: 0.4rem 0.65rem;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--ig-ink);
    box-shadow: var(--shadow-sm), var(--clay);
    outline: none;
    transition: var(--transition);
}

.sales-input-date:focus,
.sales-input-search:focus {
    border-color: var(--ig-violet);
    box-shadow: 0 0 0 3px hsla(262, 62%, 57%, 0.18), var(--clay);
}

.sales-search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 240px;
    justify-content: flex-end;
}

.sales-input-search {
    flex: 1;
    max-width: 280px;
}

.btn-sm {
    padding: 0.4rem 0.85rem !important;
    font-size: 0.82rem !important;
    border-radius: 12px !important;
}

.sales-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.sales-kpi-card {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: var(--radius-md, 14px);
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    box-shadow: var(--shadow-sm), var(--clay);
}

.sales-kpi-card .kpi-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ig-muted);
}

.sales-kpi-card .kpi-val {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ig-violet-deep);
    font-family: monospace;
}

.sales-kpi-card .kpi-sub {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--ig-muted);
}

.badge-cost {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-cost-ok {
    background: hsla(140, 60%, 90%, 0.9);
    color: #1b663e;
    border: 1px solid #7dc79d;
}

.badge-cost-incomplete {
    background: hsla(38, 95%, 92%, 0.9);
    color: #9a580a;
    border: 1px solid #f2b86b;
}

.badge-cost-zero {
    background: hsla(0, 80%, 93%, 0.9);
    color: #a32222;
    border: 1px solid #f09595;
}

.badge-cost-none {
    background: hsla(220, 15%, 92%, 0.9);
    color: #5c6479;
    border: 1px solid #c2c7d6;
}

.sales-table-wrapper {
    overflow-x: auto;
    max-height: 480px;
    overflow-y: auto;
    border: 1.5px solid var(--ig-line);
    border-radius: 14px;
    background: var(--ig-paper);
}

.sales-table th {
    position: sticky;
    top: 0;
    background: var(--ig-violet-soft);
    z-index: 2;
    padding: 0.75rem 0.85rem;
}

.sales-table td {
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--ig-line);
    font-size: 0.86rem;
}

.sales-table tr:hover td {
    background: hsla(262, 45%, 94%, 0.4);
}

/* ============================================================
   Módulo Solicitud de Cotización a Proveedores (RFQ) — Estilo Igor
   ============================================================ */

.btn-rfq {
    border-color: #2563eb;
    color: #1d4ed8;
    background: #eff6ff;
}

.btn-rfq:hover {
    background: #dbeafe;
    border-color: #1d4ed8;
    color: #1e40af;
}

.rfq-modal-content {
    max-width: 960px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.rfq-modal-body {
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
}

.rfq-section {
    background: var(--ig-paper);
    border: 1.5px solid var(--ig-line);
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.rfq-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ig-ink);
    margin: 0 0 1rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rfq-supplier-row {
    display: grid;
    grid-template-columns: 1.5fr 1.2fr 1fr;
    gap: 0.85rem;
}

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

.rfq-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    position: relative;
}

.rfq-field label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ig-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rfq-input,
.rfq-textarea {
    background: #fff;
    border: 1.5px solid var(--ig-line);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 0.88rem;
    color: var(--ig-ink);
    box-shadow: var(--shadow-sm);
    outline: none;
    transition: var(--transition);
}

.rfq-input:focus,
.rfq-textarea:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.rfq-dropdown-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1.5px solid var(--ig-line);
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
    z-index: 50;
    display: none;
}

.rfq-dropdown-item {
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--ig-line);
    font-size: 0.85rem;
    transition: background 0.15s ease;
}

.rfq-dropdown-item:last-child {
    border-bottom: none;
}

.rfq-dropdown-item:hover {
    background: #eff6ff;
}

.rfq-dropdown-item-title {
    font-weight: 600;
    color: var(--ig-ink);
}

.rfq-dropdown-item-sub {
    font-size: 0.75rem;
    color: var(--ig-muted);
    margin-top: 2px;
}

.rfq-supplier-chip {
    margin-top: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
}

.btn-chip-clear {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #3b82f6;
    font-weight: bold;
    padding: 0 0.2rem;
}

.rfq-items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.85rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.rfq-items-actions {
    display: flex;
    gap: 0.5rem;
}

.rfq-catalog-search-box {
    position: relative;
    margin-bottom: 1rem;
}

.rfq-table-wrapper {
    overflow-x: auto;
    border: 1.5px solid var(--ig-line);
    border-radius: 10px;
    background: #fff;
    max-height: 280px;
    overflow-y: auto;
}

.rfq-table {
    width: 100%;
    border-collapse: collapse;
}

.rfq-table th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--ig-muted);
    padding: 0.6rem 0.75rem;
    border-bottom: 2px solid var(--ig-line);
    z-index: 2;
}

.rfq-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--ig-line);
    font-size: 0.85rem;
}

.rfq-table input {
    width: 100%;
    border: 1px solid var(--ig-line);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
    font-family: inherit;
}

.rfq-table input:focus {
    border-color: #2563eb;
    outline: none;
}

.btn-row-delete {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.btn-row-delete:hover {
    background: #fee2e2;
}

.rfq-conditions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}

.rfq-field-full {
    grid-column: 1 / -1;
}

.rfq-status-msg {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 500;
}

.rfq-status-msg.success {
    background: #ecfdf5;
    border: 1.5px solid #a7f3d0;
    color: #065f46;
}

.rfq-status-msg.error {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    color: #991b1b;
}

.rfq-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1.5px solid var(--ig-line);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.rfq-footer-right {
    display: flex;
    gap: 0.75rem;
}

