:root {
    --primary-color: #2563eb;
    --primary-light: #60a5fa;
    --primary-dark: #1e40af;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --surface-color: rgba(255, 255, 255, 0.85); /* Glass effect base */
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: rgba(226, 232, 240, 0.5);
    --secondary-color: #475569;
    --nav-active-bg: rgba(37, 99, 235, 0.1);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1);
    --radius: 12px;
    --font-family: 'KoHo', sans-serif;
    --glass-blur: 12px;

    /* RGB variants for transparent overlays */
    --primary-rgb: 37, 99, 235;
    --success-rgb: 16, 185, 129;
    --danger-rgb: 239, 68, 68;
    --warning-rgb: 245, 158, 11;
}

/* --- Utility Classes (Clean Code) --- */
.flex-center-gap-5 { display: flex; align-items: center; gap: 5px; }
.flex-center-gap-8 { display: flex; align-items: center; gap: 8px; }
.flex-1 { flex: 1; }
.mb-0 { margin-bottom: 0 !important; }
.mt-20 { margin-top: 20px !important; }
.text-center { text-align: center !important; }
.fw-700 { font-weight: 700 !important; }
.cursor-pointer { cursor: pointer; }

/* Grid and Layout Utilities */
.grid-2-cols-gap-10 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.max-w-400 { max-width: 400px !important; }
.max-w-450 { max-width: 450px !important; }
.max-w-700 { max-width: 700px !important; }
.z-10001 { z-index: 10001 !important; }
.mt-1 { margin-top: 1rem !important; }
.mb-1-5 { margin-bottom: 1.5rem !important; }
.p-0 { padding: 0 !important; }
.overflow-hidden { overflow: hidden !important; }
.border-none { border: none !important; }
.no-shadow { box-shadow: none !important; }
.text-muted { color: var(--text-muted) !important; }
.fs-0-9 { font-size: 0.9rem !important; }
.fs-1-5 { font-size: 1.5rem !important; }



[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: rgba(30, 41, 59, 0.8); /* Glass effect base */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(51, 65, 85, 0.5);
    --secondary-color: #94a3b8;
    --nav-active-bg: rgba(96, 165, 250, 0.15);
    --primary-color: #60a5fa;
    --primary-light: #93c5fd;
    --primary-dark: #2563eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.5);
}

[data-theme="dark"] img {
    filter: brightness(0.9);
}

[data-theme="dark"] i.fa-solid {
    /* Forzar iconos a blanco si tienen color oscuro inline */
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    height: 100dvh;
    overflow: hidden;
    /* Soporte para áreas seguras (muescas) */
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

/* Tipografía y Utilidades Generales */
h1,
h2,
h3 {
    font-weight: 600;
}

.hidden {
    display: none !important;
}

.flex-1 {
    flex: 1;
}

.flex-2 {
    flex: 2;
}

.flex-none {
    flex: none;
}

.align-bottom {
    display: flex;
    align-items: flex-end;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-family);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    filter: brightness(0.9);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    filter: brightness(0.9);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--bg-color);
}

.btn-theme {
    background: var(--nav-active-bg);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-theme:hover {
    transform: rotate(15deg) scale(1.1);
    background: var(--primary-color);
    color: white;
}

.btn-block {
    width: 100%;
}

.glass {
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

/* Campos de Formulario */
.form-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--secondary-color);
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background-color: var(--surface-color);
    color: var(--text-main);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-row {
    display: flex;
    gap: 1rem;
}

/* Tarjetas (Contenedores Blancos) */
.card {
    background: var(--surface-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
}

/* Pantallas Completas (Login vs Dashboard) */
.screen {
    height: 100vh;
    width: 100vw;
}

/* Sección de Autenticación (Login/Registro) */
#auth-section {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f172a;
}

.auth-container {
    width: 100%;
    max-width: 480px;
    margin: 2rem;
}

.auth-brand {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

.auth-brand i {
    font-size: 3.5rem;
    margin-bottom: 1rem;
}

.auth-brand h1 {
    font-size: 2rem;
}

.auth-brand p {
    opacity: 0.8;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.auth-box {
    background: var(--surface-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 1.25rem;
    background: none;
    border: none;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.auth-form {
    padding: 2rem;
}

.auth-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1.5rem;
    text-align: center;
}

/* Sección Principal del Dashboard */
#main-section {
    display: flex;
}

.sidebar {
    width: 260px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-dark);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
}

.sidebar-header i {
    font-size: 1.5rem;
}

/* =========================================
   ESTILOS GLOBALES DE TARJETAS (v8.5)
   ========================================= */
.inventory-card {
    background: var(--surface-color);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.card-info {
    flex: 1;
}

.c-code {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: 0.5px;
}

.c-desc {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
    margin-top: 2px;
}

.btn-delete-item {
    background: #fff5f5;
    border: none;
    color: #e53e3e;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
}

.card-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 15px;
}

.form-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-item label {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
}

.form-item input {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--bg-color);
    width: 100%;
    box-sizing: border-box;
}

.card-warehouse-section {
    background: var(--bg-color);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
}

.wh-name-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--secondary-color);
    margin-bottom: 10px;
}

.wh-audit-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 8px;
}

.audit-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.audit-col label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
}

.qty-stepper {
    display: flex;
    align-items: center;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    height: 38px;
    overflow: hidden;
}

.qty-stepper button {
    border: none;
    background: var(--bg-color);
    width: 30px;
    height: 100%;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
}

.qty-stepper button.plus {
    background: var(--primary-color);
    color: #fff;
}

.qty-stepper input {
    border: none;
    width: 100%;
    text-align: center;
    font-weight: 700;
    font-size: 0.95rem;
    background: transparent;
    color: var(--text-main);
}

.value-box {
    height: 38px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

.value-box.diff-positive {
    color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success-color);
}

.value-box.diff-negative {
    color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
}

.card-total-footer {
    margin-top: 15px;
    padding: 12px;
    border-radius: 10px;
    background: var(--bg-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

.card-total-footer.pos {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.card-total-footer.neg {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.card-total-footer span {
    font-size: 0.8rem;
    font-weight: 800;
}

.card-total-footer strong {
    font-size: 1.1rem;
}

.card-time-stamp {
    margin-top: 10px;
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.user-info {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.avatar {
    width: 40px;
    height: 40px;
    background: var(--bg-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
}

.user-info h3 {
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 12px;
    background: var(--bg-color);
    color: var(--text-muted);
    font-weight: 600;
}

.badge.admin {
    background: #DBEAFE;
    color: #1E40AF;
}

.badge.locked {
    background: #FEE2E2;
    color: #991B1B;
}

.badge.active {
    background: #D1FAE5;
    color: #065F46;
}

.nav-menu {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 1.5rem;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--bg-color);
    color: var(--primary-light);
}

.nav-item.active {
    background: var(--nav-active-bg);
    color: var(--primary-light);
    border-right: 3px solid var(--primary-color);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Vistas Internas (Pestañas) */
.view {
    display: none;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.view.active {
    display: flex;
}

.view-header {
    padding: 1.5rem 2rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-header h2 {
    font-size: 1.25rem;
    color: var(--text-main);
}

.header-actions {
    display: flex;
    gap: 12px;
}

.view-body {
    padding: 2rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Específico del Inventario / Auditoría */
.config-card {
    margin-bottom: 0;
}

.config-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.scanner-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    gap: 1rem;
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding-left: 1rem;
    flex: 1;
    max-width: 500px;
    overflow: hidden;
}

.input-group i {
    color: var(--text-muted);
}

.input-group input {
    border: none;
    background: transparent;
    padding: 12px;
    flex: 1;
    outline: none;
    font-size: 1rem;
    min-width: 0;
}

.input-group button {
    border-radius: 0;
    height: 100%;
    white-space: nowrap;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

/* Estilos Generales de Tablas */
.table-container {
    flex: 1;
    padding: 0;
    overflow: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.875rem;
}

th {
    background: var(--bg-color);
    padding: 12px 1rem;
    font-weight: 600;
    color: var(--secondary-color);
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    z-index: 1;
}

td {
    padding: 12px 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #F8FAFC;
}

.cell-number {
    width: 90px;
}

td input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-align: right;
    font-family: inherit;
    font-weight: 500;
}

td input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-light);
}

.item-code {
    font-weight: 600;
    color: var(--primary-dark);
}

.diff-positive {
    color: var(--success-color) !important;
    font-weight: 600;
}

.diff-negative {
    color: var(--danger-color) !important;
    font-weight: 600;
}

.empty-state {
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-muted);
    margin: auto;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Diseño Dividido del Catálogo (Lista + Ficha Técnica) */
.layout-split {
    display: flex;
    flex-direction: row;
    height: 100%;
    gap: 1.5rem;
}

.list-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.filters {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    background-color: var(--surface-color);
    color: var(--text-main);
}

.search-input:focus {
    border-color: var(--primary-light);
}

.conn-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--warning-color, #f59e0b);
    border: 2px solid #fff;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    transition: background-color 0.3s;
}
.conn-dot.online { background-color: var(--success-color, #10b981); }
.conn-dot.offline { background-color: var(--danger-color, #ef4444); }

.item-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.item-list li {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.item-list li:hover {
    background: var(--bg-color);
}

.item-list li.selected {
    background: var(--nav-active-bg);
    border-left: 4px solid var(--primary-color);
    padding-left: calc(1.5rem - 4px);
}

.item-desc {
    font-size: 0.9rem;
    margin-top: 4px;
}

/* --- FICHA TÉCNICA PREMIUM --- */
.detail-pane {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: linear-gradient(145deg, rgba(var(--primary-rgb), 0.02), rgba(255,255,255,0));
}

.ficha-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    animation: fadeIn 0.4s ease;
}

.ficha-hero {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    padding: 1.25rem;
    background: var(--surface-color);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.ficha-img-container {
    width: 140px;
    height: 140px;
    min-width: 140px;
    border-radius: 12px;
    overflow: hidden;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ficha-img-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ficha-no-img {
    width: 140px;
    height: 140px;
    min-width: 140px;
    background: #f1f5f9;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    border-radius: 12px;
}

.ficha-main-info {
    flex: 1;
}

.ficha-main-info .badge {
    margin-bottom: 8px;
    display: inline-block;
}

.ficha-main-info h3 {
    font-size: 1.6rem;
    color: var(--text-main);
    line-height: 1.2;
    margin-bottom: 6px;
}

.ficha-alt-codes {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-family: monospace;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
}

.detail-item {
    padding: 1.25rem;
    background: var(--surface-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
}

.detail-item:hover {
    transform: translateY(-3px);
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
}

.detail-item label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.detail-item label i {
    color: var(--primary-color);
    font-size: 0.9rem;
    width: 16px;
    text-align: center;
}

.detail-item span {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

.ficha-actions-bar {
    display: flex;
    gap: 12px;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Grillas de Modales Responsivas */
.modal-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.modal-product-grid {
    display: grid;
    grid-template-columns: 1.2fr 2fr 100px 80px;
    gap: 10px;
}

.modal-product-grid-alt {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

/* Ventanas Modales Emergentes */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    padding: 0;
    overflow-y: auto;
    max-height: 95vh;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-btn:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 1.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 2rem;
}

/* Notificaciones Flotantes (Toasts) */
#toast-container {
    position: fixed;
    top: env(safe-area-inset-top, 20px);
    right: 20px;
    left: 20px; /* Centrado en móviles */
    z-index: 10005;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

@media (min-width: 768px) {
    #toast-container {
        left: auto;
        width: 350px;
    }
}

.toast {
    pointer-events: auto;
    background: var(--surface-color);
    border-left: 4px solid var(--primary-color);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInDown 0.3s ease;
    font-weight: 500;
    font-size: 0.9rem;
}

@keyframes slideInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.toast.success {
    border-color: var(--success-color);
}

.toast.error {
    border-color: var(--danger-color);
}

.toast.warning {
    border-color: var(--warning-color);
}

.toast i {
    font-size: 1.25rem;
}

.toast.success i {
    color: var(--success-color);
}

.toast.error i {
    color: var(--danger-color);
}

.toast.warning i {
    color: var(--warning-color);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* =========================================
   HAMBURGER / DRAWER Ã¢â‚¬â€ MOBILE NAV
========================================= */

/* Barra superior fija en móvil */
.mobile-topbar {
    display: none;
}

/* Overlay oscuro detrás del drawer */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.28s ease;
}

.sidebar-overlay.active {
    opacity: 1;
}

/* --- DISEÑO ADAPTATIVO (RESPONSIVE) PARA MÓVILES --- */
@media (max-width: 768px) {

    html {
        font-size: 14px;
    }

    /* Auth */
    .auth-container {
        margin: 1rem;
    }

    .auth-brand h1 {
        font-size: 1.5rem;
    }

    .auth-brand i {
        font-size: 2.5rem;
    }

    /* ---- TOP BAR ---- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
        padding-top: env(safe-area-inset-top, 0px); /* Padding extra para el notch */
        height: calc(56px + env(safe-area-inset-top, 0px));
        background: var(--bg-color); 
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 1100; /* Por encima de todo */
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    .mobile-topbar-brand {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--primary-color);
    }

    .btn-hamburger {
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text-main);
        font-size: 1.5rem;
        padding: 6px 8px;
        border-radius: var(--radius);
        transition: background 0.2s;
        display: flex;
        align-items: center;
    }

    .btn-hamburger:hover {
        background: var(--bg-color);
    }

    /* ---- DRAWER (sidebar como panel lateral) ---- */
    #main-section {
        flex-direction: column;
    }

    .modal-product-grid {
        display: inline !important;
    }


    .modal-product-grid-alt {
        display: inline;
    }

    .btn-success:hover {
        margin-bottom: 1rem;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        width: 280px;
        transform: translateX(-105%);
        visibility: hidden;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
        z-index: 1200;
        border-right: 1px solid var(--border-color);
        flex-direction: column;
        background: var(--bg-color);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
        bottom: unset;
        padding: 0 !important;
    }

    .sidebar.open {
        transform: translateX(0) !important;
        visibility: visible !important;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        backdrop-filter: blur(2px);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.28s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-header {
        display: flex !important;
        padding: 1.25rem 1.5rem;
        border-bottom: 1px solid var(--border-color);
    }

    .user-info {
        display: flex !important;
        padding: 1rem 1.5rem;
    }

    .nav-menu {
        flex-direction: column !important;
        overflow-y: auto;
        padding: 0.5rem 0 !important;
        justify-content: flex-start !important;
    }

    .nav-item {
        flex-direction: row !important;
        padding: 14px 1.5rem !important;
        gap: 12px !important;
        font-size: 0.95rem !important;
        justify-content: flex-start !important;
        border-left: 3px solid transparent;
    }

    .nav-item span:not(.badge) {
        display: inline !important;
    }

    .nav-item i {
        font-size: 1.1rem !important;
        width: 20px;
        text-align: center;
    }

    .nav-item.active {
        border-left: 3px solid var(--primary-color) !important;
        background: var(--nav-active-bg);
    }

    .sidebar-footer {
        padding: 1rem !important;
        border-top: 1px solid var(--border-color) !important;
        display: block !important;
    }

    .sidebar-footer .btn {
        padding: 12px 16px !important;
        height: 48px !important;
        justify-content: flex-start;
    }

    /* ---- MAIN CONTENT ---- */
    .main-content {
        order: 1;
        padding: 12px !important;
        padding-bottom: 80px !important;
        /* Aumentado para evitar solapamientos con botones flotantes o elementos inferiores */
        height: calc(100dvh - 56px);
        overflow-y: auto !important;
        overflow-x: hidden !important;
        /* BLOQUEO DE SCROLL LATERAL */
        box-sizing: border-box;
        width: 100vw;
        max-width: 100vw;
        display: block !important;
    }

    /* ---- VIEWS & HEADERS ---- */
    .view-header {
        padding: 15px 10px;
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
        background: var(--surface-color);
        border-radius: var(--radius);
        margin-bottom: 15px;
        box-shadow: var(--shadow-sm);
        width: 100%;
        box-sizing: border-box;
    }

    .view-header h2 {
        font-size: 1.3rem;
        text-align: left;
        margin: 0;
        width: 100%;
    }

    .header-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        width: 100%;
        gap: 8px !important;
    }

    .header-actions .btn {
        width: 100% !important;
        height: 48px !important;
        /* 48px para cumplir estándar táctil */
        font-size: 0.9rem !important;
        padding: 0 10px !important;
        border-radius: 8px !important;
    }

    .view-body {
        padding: 0;
        gap: 15px;
        width: 100%;
    }

    /* ---- SCANNER BAR (The "Botes" / Buttons area) ---- */
    .scanner-bar {
        flex-direction: column;
        padding: 15px !important;
        gap: 15px !important;
    }

    .scanner-bar .input-group {
        width: 100% !important;
        max-width: 100% !important;
        height: 50px !important;
    }

    .scanner-bar .action-buttons {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .scanner-bar .action-buttons .btn {
        width: 100%;
        height: 48px;
        /* 48px para cumplir estándar táctil */
        font-size: 0.9rem;
        padding: 0 8px;
    }

    /* ---- FORMS ---- */
    .form-row {
        flex-direction: column;
        gap: 15px;
    }

    .config-card .form-row {
        flex-direction: column;
        gap: 15px !important;
    }

    .config-card .form-group {
        width: 100%;
        margin-bottom: 5px;
    }

    .form-group input,
    .form-group select,
    .search-input {
        min-height: 48px !important;
        font-size: 1rem !important;
    }

    .form-group .btn,
    .filters .btn {
        min-height: 48px;
    }

    /* ---- MODALS ---- */
    .modal-content {
        width: 95%;
        max-height: 90dvh;
        border-radius: 16px;
        padding: 0;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-actions {
        flex-direction: column;
        gap: 12px;
    }

    .modal-actions .btn {
        width: 100%;
        height: 50px;
    }

    /* ---- TABLES (Horizontal Scroll fix) ---- */
    .table-container {
        width: 100%;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
        background: var(--surface-color);
        border: 1px solid var(--border-color);
    }

    table {
        min-width: 700px;
        /* Reducido para evitar scroll excesivo */
    }

    /* ---- CATALOG ---- */
    .layout-split {
        flex-direction: column;
        gap: 20px;
        height: auto;
        /* Para que el contenido crezca naturalmente en móvil */
    }

    .filters {
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }

    .filters input,
    .filters select {
        width: 100%;
        height: 48px;
    }

    .list-pane {
        flex: none;
        height: 350px;
    }

    .detail-pane {
        flex: none;
        padding: 20px;
        border-radius: 16px;
    }

    /* --- ACTUALIZACIÓN DE APP (Floating UI) --- */
    .pulse-update {
        animation: pulse-green 2s infinite;
    }

    /* El cohete se centra en la pantalla en móviles */
    .update-toast-container {
        z-index: 10000 !important;
        left: 20px !important;
        right: 20px !important;
        width: auto !important;
        max-width: 350px !important;
        margin: 0 auto !important;
    }

    /* LOS MODALES Y ALERTAS DEBEN ESTAR POR ENCIMA DE TODO (20000+) */
    .swal2-container {
        z-index: 30000 !important;
    }

    .modal-overlay, .modal {
        z-index: 25000 !important;
    }

    @keyframes pulse-green {
        0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
        70% { box-shadow: 0 0 0 15px rgba(16, 185, 129, 0); }
        100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
    }

    /* ---- INVENTORY CARDS (MOBILE REDESIGN v8.2) ---- */
    .inventory-card {
        background: var(--surface-color) !important;
        border-radius: 16px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06) !important;
        padding: 18px !important;
        margin-bottom: 20px !important;
        border: 1px solid var(--border-color) !important;
        width: 100%;
        box-sizing: border-box;
    }

    .card-top {
        display: flex !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        margin-bottom: 15px !important;
        gap: 12px !important;
        border-bottom: 1px solid var(--border-color) !important;
        padding-bottom: 12px !important;
    }

    .c-code {
        font-size: 0.8rem !important;
        font-weight: 800 !important;
        color: var(--primary-color) !important;
    }

    .c-desc {
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        color: var(--text-main) !important;
        line-height: 1.2 !important;
    }

    .btn-delete-item {
        width: 44px !important;
        height: 44px !important;
        background: #FEE2E2 !important;
        color: #EF4444 !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1.2rem !important;
    }

    .card-form-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
        margin-bottom: 15px !important;
    }

    .form-item label {
        font-size: 0.7rem !important;
        font-weight: 800 !important;
        color: var(--text-muted) !important;
        margin-bottom: 6px !important;
    }

    .form-item input {
        height: 44px !important;
        font-size: 1rem !important;
        border-radius: 8px !important;
        padding: 0 10px !important;
    }

    .card-warehouse-section {
        background: var(--bg-color) !important;
        border-radius: 12px !important;
        padding: 15px !important;
        margin-bottom: 12px !important;
    }

    .wh-name-title {
        font-size: 0.85rem !important;
        font-weight: 700 !important;
        margin-bottom: 10px !important;
    }

    .wh-audit-row {
        display: grid !important;
        grid-template-columns: 1fr !important;
        /* Stacked columns for better fit on small phones */
        gap: 15px !important;
    }

    /* RE-ESTABLECER GRID EN TABLETS PEQUEÑAS */
    @media (min-width: 400px) {
        .wh-audit-row {
            grid-template-columns: 2fr 1fr 1fr !important;
        }
    }

    .qty-stepper {
        height: 48px !important;
        /* Altura premium */
        border-radius: 10px !important;
        border: 1px solid var(--border-color) !important;
    }

    .qty-stepper button {
        width: 48px !important;
        font-size: 1.4rem !important;
    }

    .qty-stepper input {
        font-size: 1.1rem !important;
    }

    .value-box {
        height: 48px !important;
        border-radius: 10px !important;
        font-size: 1rem !important;
    }

    .card-total-footer {
        padding: 15px !important;
        border-radius: 12px !important;
        margin-top: 15px !important;
        font-size: 1rem !important;
    }

    .card-total-footer strong {
        font-size: 1.2rem !important;
    }
}

/* =========================================
   ANALYSIS / ROTATION STYLES
========================================= */
#rotation-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.rot-kpi-card {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--radius);
    border-left: 4px solid var(--kpi-accent, var(--primary-color));
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 5px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.rot-kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.rot-kpi-card .kpi-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rot-kpi-card .kpi-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
}

.rot-kpi-card .kpi-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.badge.alta { background: rgba(22, 163, 74, 0.1); color: #16a34a; border: 1px solid rgba(22, 163, 74, 0.2); }
.badge.media { background: rgba(202, 138, 4, 0.1); color: #ca8a04; border: 1px solid rgba(202, 138, 4, 0.2); }
.badge.baja { background: rgba(220, 38, 38, 0.1); color: #dc2626; border: 1px solid rgba(220, 38, 38, 0.2); }
.badge.nula { background: rgba(148, 163, 184, 0.1); color: #64748b; border: 1px solid rgba(148, 163, 184, 0.2); }

@media (max-width: 600px) {
    #rotation-kpis {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- Estilos del Dashboard de Inteligencia --- */
.compact-alert-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alert-item {
    display: grid;
    grid-template-columns: 80px 1fr 100px;
    align-items: center;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 8px;
    font-size: 0.85rem;
    border-left: 3px solid transparent;
}

.alert-item.risk { border-left-color: var(--danger-color); }
.alert-item.obsolete { border-left-color: var(--warning-color); }

.alert-item .code { font-weight: 700; color: var(--text-main); }
.alert-item .desc { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-item .val { text-align: right; font-weight: 600; color: var(--text-main); }

.abc-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.75rem;
}
.abc-badge.A { background: rgba(37, 99, 235, 0.1); color: #2563eb; border: 1px solid rgba(37, 99, 235, 0.2); }
.abc-badge.B { background: rgba(202, 138, 4, 0.1); color: #ca8a04; border: 1px solid rgba(202, 138, 4, 0.2); }
.abc-badge.C { background: rgba(100, 116, 139, 0.1); color: #64748b; border: 1px solid rgba(100, 116, 139, 0.2); }

.rot-status {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
}
.rot-status.fast { background: #dcfce7; color: #166534; }
.rot-status.normal { background: #fef9c3; color: #854d0e; }
.rot-status.slow { background: #f1f5f9; color: #475569; }

.row-abc-A { background: rgba(37, 99, 235, 0.02); }

.empty-msg {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

@media (max-width: 600px) {
    .alert-item {
        grid-template-columns: 1fr 1fr;
    }
    .alert-item .desc { display: none; }
}

/* Animaciones de Entrada */
.animate-in {
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Monitor de Sincronización Global (v20.0) */
.sync-monitor {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 15px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 15px;
    font-size: 0.75rem;
    font-weight: 700;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.sync-icon {
    font-size: 1rem;
    transition: all 0.3s ease;
}

/* Estado Activo / Sincronizado */
.sync-monitor.synced .sync-icon {
    color: #10b981;
    animation: sync-pulse 2s infinite;
}

@keyframes sync-pulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(16, 185, 129, 0)); }
    50% { transform: scale(1.15); filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.6)); }
    100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(16, 185, 129, 0)); }
}
