:root {
    /* Paleta de Colores Clara, Moderna y Profesional */
    --primary: #1e3a8a; /* Azul corporativo profundo */
    --primary-light: #3b82f6; /* Azul claro para acentos */
    --secondary: #10b981; /* Verde esmeralda (éxito, dinero) */
    --accent: #f59e0b; /* Ambar para alertas o elementos destacados */
    --danger: #ef4444; /* Rojo suave para errores o bajas de stock */
    
    --bg-color: #f3f4f6; /* Fondo gris muy claro, estilo app */
    --surface: #ffffff; /* Blanco puro para tarjetas */
    --surface-glass: rgba(255, 255, 255, 0.85); /* Glassmorphism */
    
    --text-main: #1f2937; /* Texto principal oscuro */
    --text-muted: #6b7280; /* Texto secundario gris */
    
    --border-color: #e5e7eb;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --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 -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 70px; /* Espacio para navbar inferior en móvil */
}

/* Tipografía */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

p {
    color: var(--text-muted);
}

a {
    color: var(--primary-light);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--primary);
}

/* Layout App-like */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* --- Modals (Popups) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background-color: var(--bg-color);
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 90vh; /* Para que en desktop tampoco desborde */
    margin: auto; /* Centrar por defecto */
}

/* Si el form envuelve el contenido del modal, debe heredar el comportamiento flex */
.modal-content > form {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

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

.modal-content > form {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 90vh; /* Hereda el límite para que el scroll funcione interno */
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--surface);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* Previene el desbordamiento flex */
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: #f9fafb;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0; /* Evita que el footer se aplaste */
}

@media (max-width: 767px) {
    .modal-content {
        margin: auto; /* Mantiene centrado en móviles */
        border-radius: var(--radius-md); /* Mantiene los bordes redondeados */
        max-height: 85vh;
        width: 90%; /* Un poco de margen a los lados */
    }
    
    .modal-content > form {
        max-height: 85vh;
    }
    
    .modal {
        align-items: center; /* Centrar verticalmente en móviles */
        justify-content: center; /* Centrar horizontalmente */
        padding: 1rem;
    }
    
    .modal.active .modal-content {
        transform: translateY(0) scale(1);
    }
    
    .modal .modal-content {
        transform: translateY(100%);
    }
}

/* Top Header */
.top-header {
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Tarjetas (Glassmorphism & Clean) */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-title {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}
.btn-primary:hover { background-color: #1e3a8a; transform: translateY(-1px); box-shadow: var(--shadow-md); color: white; }

.btn-secondary {
    background-color: var(--secondary);
    color: white;
}
.btn-secondary:hover { background-color: #059669; color: white; }

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

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

.btn-block {
    width: 100%;
}

/* Formularios */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: inherit;
    background-color: #f9fafb;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background-color: white;
}

/* --- Tables --- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background-color: #f9fafb;
}
.table tbody tr:hover {
    background-color: #f9fafb;
}

/* Tablas Responsivas Tipo App para Móviles */
@media (max-width: 768px) {
    .table-responsive {
        border: none;
        background: transparent;
        padding: 0;
        box-shadow: none;
    }
    .table, .table tbody, .table tr, .table td {
        display: block;
        width: 100%;
    }
    .table thead {
        display: none;
    }
    .table tr {
        margin-bottom: 1rem;
        background: white;
        border-radius: var(--radius-md);
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
        border: 1px solid var(--border-color);
        padding: 0.5rem 1rem;
    }
    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 0;
        border: none;
        border-bottom: 1px dashed var(--border-color);
        text-align: right;
        font-size: 0.875rem;
    }
    .table td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        gap: 0.5rem;
        padding-top: 1rem;
        padding-bottom: 0.5rem;
    }
    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        text-transform: uppercase;
        font-size: 0.75rem;
        letter-spacing: 0.05em;
    }
    
    /* Toggle Details System */
    .mobile-hide {
        display: none !important;
    }
    tr.show-details .mobile-hide {
        display: flex !important;
    }
    .btn-toggle-details {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Fix table footer on mobile */
    .table tfoot {
        display: block;
    }
    .table tfoot tr {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        gap: 0.5rem;
        background-color: var(--light) !important;
    }
    .table tfoot th, .table tfoot td {
        display: block;
        width: 100%;
        text-align: center !important;
        border: none;
        padding: 0;
    }
    .table tfoot td:empty, .table tfoot th:empty {
        display: none;
    }

    /* Fix form groups in filters */
    form .form-group {
        flex: 1 1 100% !important;
        min-width: 100% !important;
    }
    form button[type="submit"], form a.btn-outline {
        flex: 1 1 100%;
        width: 100%;
        margin-top: 0.5rem;
    }

    /* Responsive grid and modal footer for mobile */
    .grid-cols-2, .grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
    .modal-footer {
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 0.75rem;
    }
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}
@media (min-width: 769px) {
    .btn-toggle-details {
        display: none !important;
    }
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
}

.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-primary { background-color: #dbeafe; color: #1e40af; }
.badge-secondary { background-color: var(--secondary); color: white; }

/* Menú de Navegación Inferior (Mobile App Feel) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 0;
    z-index: 50;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    transition: color 0.2s;
    flex: 1;
    text-align: center;
}

.nav-item i {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.nav-item.active, .nav-item:hover {
    color: var(--primary);
}

/* Grid System básico */
.grid { display: grid; gap: 1rem; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }

/* Menú de Opciones en Móviles (Grid tipo App) */
.mobile-action-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .mobile-action-menu {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
        gap: 0.5rem;
    }
    .mobile-action-menu .btn {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
        padding: 0.5rem;
    }
    
    /* Sistema de Toggle para Menús en Móviles */
    .hide-desktop { display: flex !important; }
    .toggleable-menu { display: none; margin-top: -0.5rem; }
    .toggleable-menu.active { display: grid; }
}
@media (min-width: 769px) {
    .hide-desktop { display: none !important; }
    .toggleable-menu { display: flex !important; }
}

/* Sidebar Desktop Styles */
.desktop-sidebar {
    display: none;
}

@media (min-width: 768px) {
    .grid-md-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-md-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-md-4 { grid-template-columns: repeat(4, 1fr); }
    
    /* En desktop, la barra inferior podría volverse un sidebar, pero lo mantendremos top/bottom por simplicidad inicial o usar menu superior */
    body { padding-bottom: 0; display: flex; background-color: var(--bg-color); }
    .bottom-nav { display: none; }
    .mobile-only { display: none !important; }
    
    .desktop-sidebar {
        display: flex;
        flex-direction: column;
        width: 260px;
        height: 100vh;
        position: fixed;
        left: 0;
        top: 0;
        background-color: var(--surface);
        border-right: 1px solid var(--border-color);
        z-index: 100;
        box-shadow: var(--shadow-sm);
    }
    
    .app-container {
        margin-left: 260px;
        width: calc(100% - 260px);
        padding: 2rem 3rem;
        max-width: none;
    }
    
    .sidebar-brand {
        padding: 1.5rem;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-brand .brand-icon {
        background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
        color: white;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius-sm);
        font-size: 1rem;
    }
    
    .sidebar-brand .brand-text {
        font-weight: 700;
        font-size: 1.25rem;
        color: var(--text-main);
    }
    
    .sidebar-user {
        padding: 1.5rem;
        display: flex;
        align-items: center;
        gap: 1rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-user .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background-color: #e0e7ff;
        color: var(--primary);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
    }
    
    .sidebar-user .user-name {
        font-weight: 600;
        font-size: 0.875rem;
        color: var(--text-main);
    }
    
    .sidebar-user .user-role {
        font-size: 0.75rem;
        color: var(--text-muted);
    }
    
    .sidebar-nav {
        flex: 1;
        padding: 1rem 0;
        overflow-y: auto;
    }
    
    .sidebar-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        padding: 0.75rem 1.5rem;
        color: var(--text-muted);
        text-decoration: none;
        font-weight: 500;
        font-size: 0.875rem;
        transition: all 0.2s ease;
        border-left: 3px solid transparent;
    }
    
    .sidebar-item:hover, .sidebar-item.active {
        color: var(--primary);
        background-color: rgba(59, 130, 246, 0.05);
    }
    
    .sidebar-item.active {
        border-left-color: var(--primary);
    }
    
    .sidebar-item i {
        width: 20px;
        text-align: center;
        font-size: 1.125rem;
    }
    
    .sidebar-heading {
        padding: 1rem 1.5rem 0.5rem;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #9ca3af;
        font-weight: 600;
    }
    
    .sidebar-divider {
        height: 1px;
        background-color: var(--border-color);
        margin: 0.5rem 1.5rem;
    }
    
    .sidebar-footer {
        padding: 1rem;
        border-top: 1px solid var(--border-color);
    }
    
    .text-danger {
        color: var(--danger) !important;
    }
    .text-danger:hover {
        background-color: #fef2f2 !important;
    }
}
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.hidden { display: none; }

/* Menú App Móvil Grid */
.mobile-app-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 1rem;
}
.mobile-app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 0.25rem;
    border-radius: var(--radius-md);
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}
.mobile-app-item:active, .mobile-app-item.active {
    background-color: rgba(59, 130, 246, 0.05);
    border-color: var(--primary-light);
    color: var(--primary);
    box-shadow: none;
}
.mobile-app-item i {
    font-size: 1.75rem;
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.mobile-app-heading {
    grid-column: 1 / -1;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-top: 0.5rem;
    margin-bottom: -0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0.5rem;
}
.mobile-app-divider {
    grid-column: 1 / -1;
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
}
