/* ==========================================================================
   Estilos CSS Premium para Sistema de Gestión de Ferretería (Vanilla CSS)
   ========================================================================== */

:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --primary-color: #0284c7;
    --primary-hover: #0369a1;
    --success-color: #10b981;
    --success-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --warning-color: #f59e0b;
    --warning-hover: #d97706;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --border-radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

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

/* Scrollbars Modernos y Personalizados */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ==========================================================================
   Estructura del Login
   ========================================================================== */

.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    padding: 20px;
}

.login-card {
    background-color: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: 40px;
    text-align: left;
}

.login-logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    color: var(--primary-color);
    margin-bottom: 12px;
}

.login-logo h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-logo p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ==========================================================================
   Estructura del Dashboard (Sidebar + Content)
   ========================================================================== */

.admin-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Barra Lateral (Sidebar) */
/* Barra Lateral (Sidebar) */
.sidebar {
    width: var(--sidebar-width);
    background-color: #0f172a;
    color: #f8fafc;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible; /* Permitir que el botón flote fuera del borde */
}

.sidebar-brand {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #1e293b;
    height: 77px;
    transition: padding 0.3s ease;
    position: relative;
}

.brand-logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    white-space: nowrap;
    transition: all 0.3s ease;
}

.brand-logo-area svg {
    width: 28px;
    height: 28px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.sidebar-brand h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    color: #ffffff;
    background-color: #1e293b;
}

.sidebar-menu {
    list-style: none;
    padding: 20px 8px 20px 12px;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}

/* Scrollbar estilizado y elegante para el menú lateral oscuro */
.sidebar-menu::-webkit-scrollbar {
    width: 5px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.22);
    border-radius: 10px;
    transition: background 0.2s ease;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

.sidebar-menu::-webkit-scrollbar-thumb:active {
    background: var(--primary-color, #0284c7);
}

.sidebar-menu li {
    margin-bottom: 8px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #94a3b8;
    text-decoration: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.sidebar-menu a:hover {
    color: #ffffff;
    background-color: #1e293b;
}

.sidebar-menu li.active > a {
    color: #ffffff;
    background-color: var(--primary-color);
}

/* Submenús en el Sidebar */
.sidebar-menu .has-submenu {
    position: relative;
}

.sidebar-menu .submenu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    cursor: pointer;
}

.sidebar-menu .submenu-arrow {
    margin-left: auto;
    transition: transform 0.25s ease;
    opacity: 0.7;
}

.sidebar-menu .has-submenu.open > .submenu-toggle .submenu-arrow {
    transform: rotate(180deg);
}

.sidebar-menu .has-submenu.active-parent > .submenu-toggle {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.08);
}

.sidebar-submenu {
    list-style: none;
    padding: 4px 0 4px 12px;
    margin: 4px 0 6px 0;
    display: none;
    border-left: 2px solid rgba(255, 255, 255, 0.15);
    margin-left: 24px;
}

.sidebar-menu .has-submenu.open > .sidebar-submenu {
    display: block;
    animation: fadeInSubmenu 0.2s ease;
}

@keyframes fadeInSubmenu {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.sidebar-submenu li {
    margin-bottom: 4px;
}

.sidebar-submenu a {
    padding: 8px 12px;
    font-size: 13px;
    gap: 8px;
    border-radius: var(--border-radius);
    color: #94a3b8;
}

.sidebar-submenu a:hover {
    color: #ffffff;
    background-color: #1e293b;
}

.sidebar-submenu li.active a {
    color: #ffffff;
    background-color: var(--primary-color);
    font-weight: 600;
}

.submenu-bullet {
    font-size: 14px;
    line-height: 1;
    color: inherit;
}


.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid #1e293b;
    font-size: 13px;
    color: #64748b;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
    transition: padding 0.3s ease;
}

.sidebar-footer .user-name {
    color: #f8fafc;
    font-weight: 600;
    white-space: nowrap;
}

.sidebar-footer .logout-link {
    color: #ef4444;
    text-decoration: none;
    font-weight: 500;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
}

.sidebar-footer .logout-link:hover {
    text-decoration: underline;
}

/* Área de Contenido Principal */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    padding: 40px;
    overflow-x: hidden;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Estilos de Sidebar Colapsado (sidebar-collapsed)
   ========================================================================== */
.sidebar-collapsed {
    --sidebar-width: 70px !important;
}

.sidebar-collapsed .brand-text,
.sidebar-collapsed .menu-text,
.sidebar-collapsed .connected-text,
.sidebar-collapsed .sidebar-footer .user-name,
.sidebar-collapsed .logout-text {
    display: none !important;
}

.sidebar-collapsed .sidebar-brand {
    padding: 24px 12px;
    justify-content: center;
}

.sidebar-collapsed .brand-logo-area {
    gap: 0;
}

.sidebar-collapsed .sidebar-toggle {
    position: absolute;
    background-color: #1e293b;
    border: 1px solid #334155;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    right: -13px;
    top: 25px;
    z-index: 110;
    box-shadow: var(--shadow-md);
    color: #f8fafc;
}

.sidebar-collapsed .sidebar-toggle:hover {
    background-color: var(--primary-color);
    color: #ffffff;
}

.sidebar-collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

.sidebar-collapsed .sidebar-menu {
    padding: 24px 8px;
}

.sidebar-collapsed .sidebar-menu a {
    justify-content: center;
    padding: 12px;
}

.sidebar-collapsed .sidebar-submenu {
    display: none !important;
    position: absolute;
    left: 70px;
    top: 0;
    background-color: #0f172a;
    min-width: 190px;
    padding: 8px;
    border-radius: 0 8px 8px 0;
    box-shadow: var(--shadow-lg);
    border: 1px solid #1e293b;
    border-left: none;
    z-index: 200;
    margin: 0;
}

.sidebar-collapsed .has-submenu:hover > .sidebar-submenu {
    display: block !important;
}

.sidebar-collapsed .has-submenu .submenu-arrow {
    display: none !important;
}

.sidebar-collapsed .has-submenu:hover .sidebar-submenu .menu-text {
    display: inline-block !important;
}

.sidebar-collapsed .has-submenu:hover .sidebar-submenu a {
    justify-content: flex-start !important;
    padding: 8px 12px !important;
}

.sidebar-collapsed .sidebar-footer {
    padding: 16px 8px;
    align-items: center;
    justify-content: center;
}

.sidebar-collapsed .logout-link {
    margin-top: 0;
    padding: 8px;
    border-radius: var(--border-radius);
    justify-content: center;
}

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

.content-header h2 {
    font-size: 28px;
    font-weight: 700;
}

.content-header .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ==========================================================================
   Componentes Comunes
   ========================================================================== */

/* Tarjetas (Cards) */
.card {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 30px;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

/* Cuadrícula de Estadísticas (Dashboard) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #ffffff;
}

.stat-icon.primary { background-color: var(--primary-color); }
.stat-icon.success { background-color: var(--success-color); }
.stat-icon.warning { background-color: var(--warning-color); }
.stat-icon.danger { background-color: var(--danger-color); }

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-details h3 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-details .stat-number {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Formularios */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #ffffff;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 40px;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--success-color);
    color: #ffffff;
}

.btn-success:hover {
    background-color: var(--success-hover);
}

.btn-danger {
    background-color: var(--danger-color);
    color: #ffffff;
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

.btn-warning {
    background-color: var(--warning-color);
    color: #ffffff;
}

.btn-warning:hover {
    background-color: var(--warning-hover);
}

.btn-secondary {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

/* Tablas */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th {
    background-color: #f1f5f9;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-primary);
    vertical-align: middle;
}

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

.data-table tr:hover td {
    background-color: #f8fafc;
}

/* Alertas */
.alert {
    padding: 14px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-danger {
    background-color: #fef2f2;
    border-color: #fca5a5;
    color: #b91c1c;
}

.alert-success {
    background-color: #f0fdf4;
    border-color: #86efac;
    color: #15803d;
}

.alert-info {
    background-color: #f0f9ff;
    border-color: #7dd3fc;
    color: #0369a1;
}

/* Badges (Etiquetas) */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-info {
    background-color: #e0f2fe;
    color: #075985;
}

/* Acciones en Tablas */
.actions-cell {
    display: flex;
    gap: 8px;
}

/* ==========================================================================
   Punto de Venta / Formulario de Ventas (POS Layout)
   ========================================================================= */

.pos-wrapper {
    display: flex;
    gap: 24px;
    height: auto;
    min-height: 580px;
}

.products-panel {
    flex: 3;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.cart-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

/* Buscador de productos del POS */
.pos-search-wrapper {
    margin-bottom: 20px;
    position: relative;
}

.pos-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 10;
    max-height: 280px;
    overflow-y: auto;
    display: none;
}

.search-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.search-item:hover {
    background-color: #f1f5f9;
}

.search-item .item-info {
    display: flex;
    flex-direction: column;
}

.search-item .item-title {
    font-weight: 600;
    font-size: 14px;
}

.search-item .item-stock {
    font-size: 12px;
    color: var(--text-secondary);
}

.search-item .item-price {
    font-weight: 700;
    color: var(--primary-color);
}

/* Grid de Productos */
.pos-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding-right: 4px;
    height: auto;
    overflow-y: visible;
}

.pos-product-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 160px;
}

.pos-product-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.pos-product-desc {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 42px;
}

.pos-product-price {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 16px;
    margin-bottom: 4px;
}

.pos-product-stock {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Elementos del Carrito */
.cart-items-wrapper {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 12px;
    background-color: var(--bg-primary);
    min-height: 250px;
    height: auto;
    overflow-y: visible;
}

.cart-item {
    display: table-row !important;
}

.cart-item td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.cart-item:hover td {
    background-color: #f8fafc;
}

.cart-item-qty-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cart-item-qty-input {
    width: 48px;
    text-align: center;
    padding: 4px 2px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    -moz-appearance: textfield; /* Desactivar flechas en Firefox */
}

/* Ocultar flechas de control nativas del navegador (spinners) */
.cart-item-qty-input::-webkit-outer-spin-button,
.cart-item-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-qty {
    padding: 4px 6px;
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 11px;
    line-height: 1;
}

.btn-qty:hover {
    background-color: #e2e8f0;
}

.cart-item-unit-price {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
}

.cart-item-total-price {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

/* Totales y Datos del Cliente */
.pos-client-section {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.pos-totals-section {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.pos-totals-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.pos-totals-row.grand-total {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 8px;
    margin-bottom: 0;
}

/* Búsqueda de RUC en POS */
.ruc-search-group {
    display: flex;
    gap: 8px;
}

/* modal de registro rapido */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 16px;
    overflow-y: auto;
    box-sizing: border-box;
}

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

.modal-container {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 24px;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
    margin: auto;
    box-sizing: border-box;
}

.modal-overlay.active .modal-container {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* ==========================================================================
   Estilos Adaptativos / Media Queries
   ========================================================================== */

@media (max-width: 1024px) {
    .pos-wrapper {
        flex-direction: column;
        height: auto;
    }
    .products-panel, .cart-panel {
        flex: none;
        height: 500px;
    }
}

/* Elementos móviles ocultos por defecto en pantallas de escritorio */
.mobile-topbar {
    display: none;
}
.sidebar-backdrop {
    display: none;
}
.sidebar-mobile-close {
    display: none;
}

@media (max-width: 768px) {
    /* Backdrop oscuro para móvil */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        background-color: rgba(15, 23, 42, 0.65);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }
    .sidebar-backdrop.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Barra superior móvil con botón hamburguesa */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: #0f172a;
        color: #ffffff;
        padding: 10px 16px;
        margin: -20px -16px 20px -16px;
        position: sticky;
        top: 0;
        z-index: 900;
        border-bottom: 1px solid #1e293b;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    }
    .mobile-menu-btn {
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.15);
        color: #ffffff;
        width: 38px;
        height: 38px;
        border-radius: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        flex-shrink: 0;
    }
    .mobile-menu-btn:hover,
    .mobile-menu-btn:active {
        background: var(--primary-color, #0284c7);
        border-color: var(--primary-color, #0284c7);
        transform: scale(0.96);
    }
    .mobile-brand-title {
        font-size: 14px;
        font-weight: 700;
        color: #ffffff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 10px;
        text-align: center;
        letter-spacing: 0.3px;
        flex-grow: 1;
    }
    .mobile-user-badge {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary-color, #0284c7), #0369a1);
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 13px;
        text-transform: uppercase;
        flex-shrink: 0;
        border: 2px solid rgba(255, 255, 255, 0.2);
    }

    /* Sidebar como Drawer Deslizable sobre la pantalla */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        width: 285px !important;
        max-width: 85vw !important;
        z-index: 1050 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: none !important;
        overflow-y: auto !important;
        display: flex !important;
    }
    .sidebar.active,
    .sidebar.mobile-open {
        transform: translateX(0) !important;
        box-shadow: 6px 0 30px rgba(0, 0, 0, 0.6) !important;
    }

    /* Botón para cerrar el menú dentro del sidebar */
    .sidebar-mobile-close {
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.15);
        color: #94a3b8;
        width: 32px;
        height: 32px;
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.2s ease;
        flex-shrink: 0;
    }
    .sidebar-mobile-close:hover,
    .sidebar-mobile-close:active {
        color: #ffffff;
        background-color: #ef4444;
        border-color: #ef4444;
    }

    /* Ocultar el toggle de colapso desktop en móvil */
    .sidebar-toggle {
        display: none !important;
    }

    /* Asegurar que el contenido del sidebar no se colapse a iconos si estaba collapsed en desktop */
    .sidebar-collapsed {
        --sidebar-width: 285px !important;
    }
    .sidebar-collapsed .sidebar {
        width: 285px !important;
    }
    .sidebar-collapsed .brand-text,
    .sidebar-collapsed .menu-text,
    .sidebar-collapsed .connected-text,
    .sidebar-collapsed .sidebar-footer .user-name,
    .sidebar-collapsed .logout-text {
        display: inline-block !important;
    }
    .sidebar-collapsed .sidebar-brand {
        padding: 24px 16px !important;
        justify-content: space-between !important;
    }
    .sidebar-collapsed .sidebar-menu a {
        justify-content: flex-start !important;
        padding: 12px 16px !important;
    }
    .sidebar-collapsed .has-submenu .submenu-arrow {
        display: block !important;
    }
    .sidebar-collapsed .sidebar-submenu {
        position: static !important;
        min-width: auto !important;
        background-color: transparent !important;
        box-shadow: none !important;
        border: none !important;
        border-left: 2px solid rgba(255, 255, 255, 0.15) !important;
        margin-left: 24px !important;
        padding: 4px 0 4px 12px !important;
    }
    .sidebar-collapsed .has-submenu.open > .sidebar-submenu {
        display: block !important;
    }
    .sidebar-collapsed .has-submenu:not(.open) > .sidebar-submenu {
        display: none !important;
    }
    .sidebar-collapsed .sidebar-toggle {
        display: none !important;
    }

    /* Contenido Principal en Móvil */
    .main-content {
        margin-left: 0 !important;
        padding: 20px 16px !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    /* Bloqueo de scroll cuando el menú móvil está abierto */
    body.mobile-menu-active {
        overflow: hidden !important;
        touch-action: none;
    }
}

@media print {
    .mobile-topbar,
    .sidebar-backdrop {
        display: none !important;
    }
}
