:root {
    --bg-dark: hsl(222, 47%, 8%);
    --bg-card: hsla(223, 47%, 11%, 0.85);
    --primary: hsl(220, 95%, 60%);
    --primary-hover: hsl(220, 95%, 50%);
    --primary-glow: rgba(59, 130, 246, 0.45);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    
    /* Status Colors */
    --status-available: #10b981;
    --status-assigned: #f59e0b;
    --status-repair: #ef4444;
    --status-obsolete: #64748b;
    --status-pending: #8b5cf6;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-lg: 12px;
    --radius-md: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow-x: hidden;
}

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

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    padding: 2rem 0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 2rem;
    margin-bottom: 3rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: var(--shadow);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.nav-links {
    list-style: none;
    padding: 0 1rem;
}

.nav-links li {
    padding: 1rem 1.5rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    transition: var(--transition);
    font-weight: 500;
}

.nav-links li:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-links li.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Topbar */
.topbar {
    height: 80px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background-color: var(--bg-card);
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: var(--bg-dark);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    width: 400px;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.search-bar i {
    color: var(--text-muted);
    margin-right: 10px;
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-main);
    width: 100%;
    outline: none;
    font-size: 0.9rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    background-color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Views */
.view-section {
    display: none;
    padding: 2rem;
    animation: fadeIn 0.4s ease forwards;
}

.view-section.active {
    display: block;
}

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

.header-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-action h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

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

.stat-card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.6), 0 0 12px var(--primary-glow);
    border-color: var(--primary);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 5px;
}

.stat-info p {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Charts Area */
.dashboard-charts {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.chart-container, .recent-activity {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

.chart-container h2, .recent-activity h2 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.type-bars {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.type-bar-row {
    display: flex;
    align-items: center;
    gap: 15px;
}

.type-label {
    width: 100px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.type-progress-bg {
    flex: 1;
    height: 10px;
    background-color: var(--bg-dark);
    border-radius: 5px;
    overflow: hidden;
}

.type-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    border-radius: 5px;
    transition: width 1s ease-out;
}

.type-count {
    width: 30px;
    text-align: right;
    font-weight: 600;
}

.recent-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.recent-item {
    display: flex;
    gap: 15px;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.recent-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.recent-icon {
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.recent-details h4 {
    font-size: 0.95rem;
    color: var(--text-main);
}

.recent-details p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Inventory Tabs */
.inventory-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 2px;
}

.nav-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px 18px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    transition: var(--transition);
    position: relative;
    outline: none;
}

.nav-tab:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
    color: var(--primary);
    background-color: rgba(59, 130, 246, 0.1);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--primary);
    border-radius: 3px 3px 0 0;
}

/* Table */
.table-container {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow-x: auto; /* Asegura scroll horizontal si la tabla es grande */
}

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

.inventory-table th, .inventory-table td {
    padding: 1rem 1.5rem;
    text-align: center;
    vertical-align: middle;
}

.inventory-table th {
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.inventory-table tr {
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.inventory-table tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

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

.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    display: inline-block;
}

.status-badge.disponible { background: rgba(16, 185, 129, 0.1); color: var(--status-available); }
.status-badge.asignado { background: rgba(245, 158, 11, 0.1); color: var(--status-assigned); }
.status-badge.reparacion { background: rgba(239, 68, 68, 0.1); color: var(--status-repair); }
.status-badge.obsoleto { background: rgba(100, 116, 139, 0.1); color: var(--status-obsolete); }
.status-badge.pendiente { background: rgba(139, 92, 246, 0.1); color: var(--status-pending); }

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 5px;
    margin: 0 3px;
    transition: var(--transition);
}

.action-btn.edit:hover { color: var(--primary); }
.action-btn.delete:hover { color: var(--status-repair); }

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

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

.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    width: 700px; /* Aumentado ligeramente para el grid de periféricos */
    max-width: 95vw;
    max-height: 90vh; /* Límite de altura máxima respecto a la pantalla */
    display: flex;
    flex-direction: column;
    transform: translateY(20px) scale(0.95);
    transition: var(--transition);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-overlay.open .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover { color: var(--text-main); }

.modal-content form {
    padding: 1.5rem 2rem;
    overflow-y: auto; /* Scroll vertical dentro del modal */
    overflow-x: hidden;
}

/* Personalizando la barra de scroll para el modal */
.modal-content form::-webkit-scrollbar {
    width: 8px;
}

.modal-content form::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.modal-content form::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.section-title h3 {
    margin-top: 10px;
    margin-bottom: 5px;
    font-size: 1.1rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.peripheral-grid {
    display: grid;
    /* Ajuste automático cuando la pantalla es pequeña reduce columnas en lugar de apretarlas */
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); 
    gap: 10px;
}

.peripheral-grid input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
    width: 100%;
}

.peripheral-grid input:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
}

.border-bottom {
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 5px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input, .form-group select, .form-group textarea {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

/* ----------------------------------------
   R E S P O N S I V I D A D (MÓVIL) - Consolidado al final del archivo
---------------------------------------- */


.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
}

/* Hacer visible el icono del calendario en modo oscuro */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.form-group select option {
    background: var(--bg-card);
    color: var(--text-main);
}

.modal-footer {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}

/* Ticket Filters UI */
.ticket-filters select.filter-select {
    background-color: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 5px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.ticket-filters select.filter-select:focus {
    border-color: var(--primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.ticket-filters select.filter-select option {
    background-color: #1e293b; /* Color oscuro (var(--bg-card)) */
    color: white;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* =========================================
   LOGIN SCREEN (GLASSMORPHISM)
   ========================================= */
.login-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-dark), #1e3a8a);
    padding: 1rem;
}

.login-box {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    padding: 3rem 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: fadeIn 0.8s ease forwards;
}

.login-header {
    margin-bottom: 2rem;
}

.logo-icon-large {
    width: 70px;
    height: 70px;
    margin: 0 auto 1.5rem auto;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.5);
    color: white;
}

.login-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.4;
}

.login-box .form-group {
    text-align: left;
    margin-bottom: 15px;
}

.login-box label {
    font-size: 0.85rem;
    margin-bottom: 5px;
}

.input-with-icon {
    position: relative;
    width: 100%;
}

.input-with-icon i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.1rem;
}

.input-with-icon input {
    width: 100%;
    padding-left: 45px;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.login-btn {
    width: 100%;
    justify-content: center;
    margin-top: 1.5rem;
    padding: 1rem;
    font-size: 1.05rem;
}

.login-error {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 10px;
    border-radius: var(--radius-md);
    margin-top: 15px;
    font-size: 0.85rem;
}

/* =========================================
   READ-ONLY MODE (DEMO / VIEWER)
   ========================================= */
body.readonly-mode .btn-primary { 
    display: none !important; 
}

body.readonly-mode .action-btn.edit, 
body.readonly-mode .action-btn.delete { 
    display: none !important; 
}


/* QR Grid Formato Carta */
.qr-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(5, 1fr); gap: 10px; padding: 10px; background: var(--bg-dark); border-radius: 8px; border: 1px solid var(--border-color); margin-bottom: 20px; }
.btn-position { background-color: var(--surface); border: 1px dashed var(--border-color); color: var(--text-main); padding: 15px 0; border-radius: 4px; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-position:hover { background-color: var(--primary); border-color: var(--primary); color: white; }


/* === Alertas Semestrales Mantenimiento === */
.maintenance-warning {
    background-color: rgba(239, 68, 68, 0.05);
    border-left: 3px solid var(--danger);
}
.mtnc-alert-text {
    color: var(--danger);
    font-weight: 600;
}


/* === L�nea de Tiempo (Timeline) === */
.timeline { position: relative; padding: 20px 0; margin-top: 10px; }
.timeline::before { content: ''; position: absolute; left: 20px; top: 0; bottom: 0; width: 2px; background: var(--border-color); }
.timeline-item { position: relative; padding-left: 45px; margin-bottom: 25px; }
.timeline-dot { position: absolute; left: 14px; top: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 3px solid var(--surface); z-index: 1; }
.timeline-content { background: var(--bg-dark); padding: 12px 15px; border-radius: 8px; border: 1px solid var(--border-color); }
.timeline-date { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; display: block; }
.timeline-title { font-weight: 600; font-size: 0.9rem; color: var(--primary); margin-bottom: 4px; display: block; }
.timeline-desc { font-size: 0.85rem; color: var(--text-main); line-height: 1.4; }
.timeline-user { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; display: block; font-style: italic; }

/* Colores por acci�n */
.timeline-item.mantenimiento .timeline-dot { background: #10b981; }
.timeline-item.mantenimiento .timeline-title { color: #10b981; }
.timeline-item.asignacion .timeline-dot { background: #8b5cf6; }
.timeline-item.asignacion .timeline-title { color: #8b5cf6; }
.timeline-item.baja .timeline-dot { background: #ef4444; }
.timeline-item.baja .timeline-title { color: #ef4444; }


/* === Alertas Sem�nticas de Pr�ximo Mantenimiento === */
.txt-maint-ok { color: #10b981; font-weight: 600; }
.txt-maint-soon { color: #f59e0b; font-weight: 600; }
.txt-maint-overdue { color: #ef4444; font-weight: 700; }


/* Scanner Styles */
.input-with-button {
    display: flex;
    gap: 8px;
    width: 100%;
}

.input-with-button input {
    flex: 1;
}

.btn-scan {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0 15px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-scan:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.btn-scan i {
    font-size: 1.1rem;
}

#scanner-reader video {
    width: 100% !important;
    border-radius: 8px;
}

#scanner-reader {
    border: none !important;
}

#scanner-reader button {
    background: var(--primary) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--radius-md) !important;
    padding: 8px 15px !important;
    margin-top: 10px !important;
    cursor: pointer !important;
}

#scanner-reader select {
    background: var(--bg-card) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--radius-md) !important;
    padding: 5px !important;
}

/* Scanner Tabs & OCR */
.scanner-tabs {
    display: flex;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

.scanner-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 500;
}

.scanner-tab.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    box-shadow: inset 0 -2px 0 var(--primary);
}

.scanner-tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

#ocr-loader {
    color: var(--primary);
    font-weight: 600;
    padding: 10px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: var(--radius-md);
    margin-top: 15px;
    animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}


/* Focus Box GUI for OCR/Barcode */
.scanner-focus-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 260px;
    height: 100px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.4);
    z-index: 10;
    pointer-events: none;
    transition: var(--transition);
}

.scanner-focus-box::after {
    content: "";
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
}

#scannerModal[data-mode="ocr"] .scanner-focus-box {
    border-color: #f59e0b; /* Yellow/Orange focus for OCR */
    width: 280px;
    height: 80px;
}

#scannerModal[data-mode="barcode"] .scanner-focus-box {
    width: 250px;
    height: 250px; /* Square for barcodes */
}


/* Fix layout cuts */
.form-group input, .form-group select, .form-group textarea { width: 100%; }
.input-with-button input, .input-with-button select { flex: 1; min-width: 0; }

/* Ticket History Timeline */
.history-timeline { display: flex; flex-direction: column; gap: 12px; max-height: 250px; overflow-y: auto; padding-right: 5px; }
.history-item { background: rgba(0, 0, 0, 0.2); border-left: 3px solid var(--primary); padding: 10px 15px; border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.history-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 5px; display: flex; justify-content: space-between; }
.history-text { font-size: 0.9rem; color: var(--text-main); line-height: 1.4; }

/* === Mobile Performance Optimizations === */
@media (max-width: 768px) {
    .modal-overlay {
        display: flex;
        justify-content: center;
        align-items: flex-start; /* Alinear arriba para evitar que el menu cubra el fondo */
        padding: 15px;
        padding-top: 20px;
        overflow-y: auto;
    }

    .modal-overlay {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .modal-content {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        width: 100%;
        max-width: 100%;
        margin-bottom: 85px; /* Limite justo antes de llegar al menu de 70px + margen */
        max-height: calc(100dvh - 105px) !important;
    }

    .login-box {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    .app-container {
        min-height: 100vh !important;
        min-height: 100dvh !important;
    }
    .sidebar {
        width: 100% !important;
        position: fixed;
        bottom: 0;
        left: 0;
        height: auto !important;
        flex-direction: row !important;
        z-index: 1001;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--border-color);
        overflow-x: auto !important;
        white-space: nowrap; -webkit-overflow-scrolling: touch;
    }
    .sidebar-header { display: none; }
    .nav-links {
        display: flex;
        width: 100%;
        padding: 0;
        margin: 0;
        justify-content: space-around;
        list-style: none;
    }
    .nav-links li {
        padding: 10px;
        margin: 0;
        flex-direction: column;
        gap: 2px;
        font-size: 0.7rem;
        flex: 1;
        text-align: center;
        border-radius: 0;
    }
    .nav-links li i { font-size: 1.2rem; }
    .nav-links li span { display: block; }
    
    .main-content {
        padding-bottom: 70px; /* Space for bottom nav */
    }
    
    .view-section {
        padding: 1.5rem 1rem;
    }
    
    .header-action {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .dashboard-charts {
        grid-template-columns: 1fr;
    }

    /* Force GPU acceleration on elements that transition to avoid flickering */
    /* Limited to specific containers to avoid GPU memory pressure */
    .view-section.active, .modal-overlay.open, .modal-content {
        will-change: transform, opacity;
        transform: translateZ(0);
    }
}

/* Disable hover effects on touch devices to prevent jitter */
@media (hover: none) {
    .nav-links li:hover, .stat-card:hover, .btn-primary:hover, .btn-secondary:hover {
        transform: none !important;
        box-shadow: none !important;
    }
}

/* Force uppercase for uniformity */
table td, .stat-info p, .stat-info h3, input[type="text"]:not(.toggle-password-input), select { text-transform: uppercase; }

/* Exception for Helpdesk Button in Readonly Mode */
body.readonly-mode #helpdesk-view .btn-primary { display: flex !important; }

/* Restricted Capture-Only Mode Logic */
body.capture-only-mode .sidebar, 
body.capture-only-mode .topbar, 
body.capture-only-mode .search-bar,
body.capture-only-mode #tickets-view .header-action,
body.capture-only-mode .stats-grid, 
body.capture-only-mode .table-container,
body.capture-only-mode #dashboard-view,
body.capture-only-mode .nav-toggle { 
    display: none !important; 
}

body.capture-only-mode .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 0 !important;
}

/* Permitir botones de cierre y cancelación en modo captura */
body.capture-only-mode #ticketModal .close-btn,
body.capture-only-mode #ticketModal .btn-secondary {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Exception for Modal Buttons in Readonly/Capture Mode so tickets can be saved */
body.readonly-mode .modal-overlay .btn-primary,
body.capture-only-mode .modal-overlay .btn-primary { 
    display: flex !important; 
}

/* =========================================
   SURVEY MODAL & SATISFACTION STATS
   ========================================= */
.survey-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--glass-border);
}

.survey-row:last-child {
    border-bottom: none;
}

.survey-question {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
    padding-right: 15px;
}

.rating-scale {
    display: flex;
    gap: 8px;
    align-items: center;
}

.rating-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: rgba(0,0,0,0.2);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rating-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.1);
}

.rating-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.scale-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 70px;
}

.scale-label.low { text-align: right; margin-right: 5px; }
.scale-label.high { text-align: left; margin-left: 5px; }

/* Satisfaction Dashboard Stats */
.satisfaction-stats-container {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.satisfaction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.sat-mini-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
    transition: var(--transition);
}

.sat-mini-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--primary);
}

.sat-mini-card h4 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
}

.sat-mini-card .score {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
}

.sat-mini-card .stars {
    color: #f59e0b;
    font-size: 0.7rem;
    margin-top: 3px;
}
