/**
 * PAO v2 - Sistema de Permisos Atómicos
 * Estilos principales del sistema
 */

/* ============================================
   CSS Variables & Design Tokens
   ============================================ */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-card: #1c2128;
    --bg-hover: rgba(255, 255, 255, 0.05);

    /* Accent Colors */
    --accent-primary: #58a6ff;
    --accent-secondary: #7ee787;
    --accent-warning: #f0883e;
    --accent-danger: #f85149;
    --accent-purple: #a371f7;
    --accent-pink: #db61a2;

    /* Text Colors */
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;

    /* Border Colors */
    --border-primary: #30363d;
    --border-hover: #484f58;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-accent: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-success: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --gradient-card: linear-gradient(145deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0) 100%);

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.3);

    /* Spacing */
    --sidebar-width: 280px;
    --sidebar-collapsed: 70px;
    --header-height: 60px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 50%;
}

/* ============================================
   Base Styles
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-secondary);
}

/* ============================================
   Layout
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.content-body {
    padding: 2rem;
    flex: 1;
}

.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width var(--transition-normal);
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border-primary);
    position: relative;
    /* Ensure toggle button is positioned relative to header */
}

/* Logo Container - Vertical Layout */
.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    padding-right: 40px;
    /* Prevent overlap with toggle button */
}

.logo-img {
    height: 40px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    transition: all var(--transition-normal);
}

/* Toggle Button - Positioned to the right */
/* UPDATED: 2026-01-26 11:45 - Fixed overlap issue with absolute positioning */
.sidebar-toggle-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-md);
    color: #ffffff;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);

    /* Absolute positioning to float correctly */
    position: absolute !important;
    right: .25rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.sidebar-toggle-btn:hover {
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    box-shadow: 0 2px 12px rgba(88, 166, 255, 0.4);
    transform: translateY(-50%) scale(1.05);
    /* Maintain vertical centering while scaling */
}

.sidebar-toggle-btn i {
    transition: transform var(--transition-normal);
    font-size: 0.875rem;
}

.sidebar-collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

/* Collapsed State */
.sidebar-collapsed .logo-img {
    height: 30px;
}

/* User Section */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-primary);
}

.user-avatar {
    width: 44px;
    height: 44px;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-collapsed .user-info {
    display: none;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: hidden;
    /* Only show scrollbar on hover */
    padding: 1rem 0;
}

.sidebar-nav:hover {
    overflow-y: auto;
}

.sidebar-collapsed .sidebar-nav {
    overflow: hidden;
}

/* Sidebar Scrollbar Customization */
.sidebar-nav::-webkit-scrollbar {
    width: 10px;
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--border-primary);
    border-radius: 20px;
    border: 2px solid var(--bg-secondary);
}

.sidebar-nav::-webkit-scrollbar-button {
    display: none;
}

.nav-list {
    list-style: none;
}

.nav-item {
    padding: 0 0.75rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    position: relative;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent-primary);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent-primary);
    border-radius: 0 4px 4px 0;
}

.nav-link i {
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
}

.nav-divider {
    height: 1px;
    background: var(--border-primary);
    margin: 1rem 1.5rem;
}

.sidebar-collapsed .nav-link span {
    display: none;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-primary);
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    color: var(--accent-danger);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.logout-btn:hover {
    background: rgba(248, 81, 73, 0.1);
}

.sidebar-collapsed .logout-btn span {
    display: none;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition-normal);
}

.card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.btn-success {
    background: var(--gradient-success);
    color: white;
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #da3633;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    cursor: pointer;
}

/* Fix for Browser Autofill background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--bg-tertiary) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s;
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

/* ============================================
   Tables
   ============================================ */
/* ============================================
   Tables (Dark Theme Overrides)
   ============================================ */
.table-responsive {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
    overflow: hidden;
    /* Ensure border radius works */
}

.table {
    width: 100%;
    margin-bottom: 0;
    color: var(--text-primary);
    border-color: var(--border-primary);
    --bs-table-hover-bg: var(--bg-hover);
    /* Bootstrap override */
}

.table> :not(caption)>*>* {
    background-color: transparent;
    /* Remove Bootstrap default white bg */
    border-bottom-color: var(--border-primary);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    vertical-align: middle;
}

.table thead th {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-primary);
    padding: 1rem;
    white-space: nowrap;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background-color: var(--bg-hover) !important;
}

/* Force Dark Text Overrides global Bootstrap classes */
.text-dark {
    color: var(--text-primary) !important;
}

.text-muted {
    color: var(--text-secondary) !important;
}

.bg-light {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-secondary);
}

/* ============================================
   Badges
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
}

.badge-success {
    background: rgba(126, 231, 135, 0.15);
    color: var(--accent-secondary);
}

.badge-warning {
    background: rgba(240, 136, 62, 0.15);
    color: var(--accent-warning);
}

.badge-danger {
    background: rgba(248, 81, 73, 0.15);
    color: var(--accent-danger);
}

.badge-info {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent-primary);
}

/* ============================================
   Alerts
   ============================================ */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background: rgba(126, 231, 135, 0.1);
    border: 1px solid rgba(126, 231, 135, 0.3);
    color: var(--accent-secondary);
}

.alert-danger {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    color: var(--accent-danger);
}

.alert-warning {
    background: rgba(240, 136, 62, 0.1);
    border: 1px solid rgba(240, 136, 62, 0.3);
    color: var(--accent-warning);
}

.alert-info {
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid rgba(88, 166, 255, 0.3);
    color: var(--accent-primary);
}

.alert-dismissible {
    position: relative;
    padding-right: 3rem;
}

.btn-close {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    font-size: 1.25rem;
}

.btn-close:hover {
    opacity: 1;
}

/* ============================================
   Page Header
   ============================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-primary);
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-description {
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ============================================
   Stats Cards
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all var(--transition-normal);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.primary {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent-primary);
}

.stat-icon.success {
    background: rgba(126, 231, 135, 0.15);
    color: var(--accent-secondary);
}

.stat-icon.warning {
    background: rgba(240, 136, 62, 0.15);
    color: var(--accent-warning);
}

.stat-icon.purple {
    background: rgba(163, 113, 247, 0.15);
    color: var(--accent-purple);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ============================================
   Login Page
   ============================================ */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(88, 166, 255, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(163, 113, 247, 0.1) 0%, transparent 50%),
        var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    width: 64px;
    height: 64px;
    background: var(--gradient-primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    margin: 0 auto 1.5rem;
    box-shadow: var(--shadow-glow);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ============================================
   Permissions Matrix
   ============================================ */
.permissions-matrix {
    overflow-x: auto;
}

.permissions-matrix table {
    width: 100%;
    border-collapse: collapse;
}

.permissions-matrix th,
.permissions-matrix td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-primary);
    text-align: center;
}

.permissions-matrix th {
    background: var(--bg-tertiary);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.permissions-matrix .module-name {
    text-align: left;
    font-weight: 500;
}

.permission-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.fade-in {
    animation: fadeIn var(--transition-normal) ease-out;
}

/* ============================================
   Sidebar Submenu (Hierarchical Modules)
   ============================================ */
.nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    padding: 0 0.75rem;
    margin-bottom: 2px;
}

.nav-item.has-submenu {
    padding: 0 0.75rem;
}

.submenu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.submenu-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.submenu-toggle .nav-text {
    flex: 1;
    text-align: left;
    margin-left: 0.75rem;
}

.submenu-arrow {
    font-size: 0.7rem;
    transition: transform var(--transition-fast);
}

.nav-item.expanded .submenu-arrow {
    transform: rotate(180deg);
}

/* Submenu container */
.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-normal) ease;
}

.submenu.open {
    max-height: 500px;
}

.submenu-item {
    padding: 0;
}

.submenu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem 0.6rem 2.75rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    margin: 2px 0.5rem;
    transition: all var(--transition-fast);
    position: relative;
}

.submenu-link::before {
    content: '';
    position: absolute;
    left: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--border-primary);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.submenu-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.submenu-link:hover::before {
    background: var(--accent-primary);
}

.submenu-link.active {
    color: var(--accent-primary);
    background: rgba(88, 166, 255, 0.1);
}

.submenu-link.active::before {
    background: var(--accent-primary);
    box-shadow: 0 0 8px var(--accent-primary);
}

.submenu-link i {
    width: 18px;
    font-size: 0.85rem;
    text-align: center;
}

/* Sidebar Footer with user info */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.sidebar-footer .user-avatar {
    width: 36px;
    height: 36px;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    color: white;
    flex-shrink: 0;
}

.sidebar-footer .user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-footer .user-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .logout-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-footer .logout-btn:hover {
    color: var(--accent-danger);
    background: rgba(248, 81, 73, 0.1);
}

.sidebar-footer-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sidebar-footer .footer-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-footer .footer-btn:hover {
    color: var(--accent-primary);
    background: rgba(88, 166, 255, 0.1);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {

    /* En móvil, ocultar el toggle de colapso */
    .sidebar-toggle-btn {
        display: none;
    }

    /* Sidebar oculto por defecto en móvil */
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .main-content {
        margin-left: 0 !important;
    }

    /* Remover clase collapsed en móvil */
    .sidebar-collapsed .sidebar {
        width: var(--sidebar-width) !important;
    }
}

@media (min-width: 1025px) {

    /* En desktop, el toggle siempre visible */
    .sidebar-toggle-btn {
        display: flex;
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Global Components & Helpers (Added for Project-wide Consistency)
   ============================================ */

/* Avatars */
.avatar-initials {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

/* Role Badges */
.role-badge {
    font-size: 0.7rem;
    padding: 0.35em 0.8em;
    border-radius: 20px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid transparent;
}

.role-admin_global {
    background: rgba(248, 81, 73, 0.15);
    color: var(--accent-danger);
    border-color: rgba(248, 81, 73, 0.2);
}

.role-admin_area {
    background: rgba(240, 136, 62, 0.15);
    color: var(--accent-warning);
    border-color: rgba(240, 136, 62, 0.2);
}

.role-SUPERADMIN {
    background: rgba(163, 113, 247, 0.15);
    color: var(--accent-purple);
    border-color: rgba(163, 113, 247, 0.2);
}

.role-usuario {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-color: var(--border-primary);
}

/* Status Dots */
.estatus-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.estatus-ACTIVO {
    background-color: var(--accent-secondary);
    box-shadow: 0 0 8px rgba(126, 231, 135, 0.4);
}

.estatus-BAJA {
    background-color: var(--accent-danger);
}

.estatus-LICENCIA {
    background-color: var(--accent-warning);
}

.estatus-PENDIENTE {
    background-color: var(--text-secondary);
}

/* Premium Filters Bar */
.search-filters-bar {
    display: flex;
    gap: 1rem;
    align-items: center;
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

.search-input-group {
    flex: 2;
    position: relative;
}

.search-input-group i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-input-group input {
    padding-left: 2.75rem !important;
    background: var(--bg-tertiary);
    border-color: var(--border-primary);
    color: var(--text-primary);
}

.search-input-group input:focus {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.filter-select-group {
    flex: 1;
}

.filter-select-group select {
    width: 100%;
    cursor: pointer;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-primary);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238b949e' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 16px 12px;
    appearance: none;
}

.btn-clear {
    color: var(--text-secondary);
    transition: color var(--transition-fast);
    padding: 0.5rem;
}

.btn-clear:hover {
    color: var(--accent-danger);
}

@media (max-width: 992px) {
    .search-filters-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

/* Botón hamburguesa para móviles */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    width: 44px;
    height: 44px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

/* Overlay para cerrar sidebar en móvil */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
    opacity: 1;
}

/* Tablets y pantallas medianas */
@media (max-width: 1024px) {
    .main-content {
        padding: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Móviles */
@media (max-width: 768px) {

    /* Mostrar botón hamburguesa */
    .mobile-menu-btn {
        display: flex;
    }

    /* Mostrar overlay cuando sidebar está activo */
    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }

    /* Sidebar oculto por defecto en móvil */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    /* Sidebar visible cuando tiene clase mobile-open */
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Main content ocupa todo el ancho */
    .main-content {
        margin-left: 0;
        padding: 4.5rem 1rem 1rem 1rem;
    }

    .sidebar-collapsed .main-content {
        margin-left: 0;
    }

    /* Page header responsivo */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .page-header .btn {
        width: 100%;
        justify-content: center;
    }

    /* Stats en una columna */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Tablas scroll horizontal */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* Formularios en una columna */
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    /* Search filters bar apilados */
    .search-filters-bar {
        flex-direction: column;
        gap: 0.75rem;
    }

    .search-filters-bar .search-input-group,
    .search-filters-bar .filter-select-group {
        width: 100%;
        min-width: unset;
    }

    /* Campo de búsqueda siempre visible */
    .search-input-group {
        display: flex !important;
    }

    .search-input-group input {
        font-size: 16px;
        /* Prevenir zoom en iOS */
    }

    /* Botones de acción más grandes para touch */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }

    .btn-sm {
        min-height: 36px;
    }

    /* Cards más compactas */
    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Pantallas muy pequeñas */
@media (max-width: 480px) {
    .main-content {
        padding: 4rem 0.75rem 0.75rem 0.75rem;
    }

    .page-title {
        font-size: 1.35rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    /* Tabla más compacta */
    .table> :not(caption)>*>* {
        padding: 0.75rem;
        font-size: 0.85rem;
    }
}

/* ============================================
   Select2 Dark Theme
   ============================================ */
.select2-container--bootstrap-5 .select2-selection {
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary) !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted) !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-secondary) transparent transparent transparent !important;
}

/* Dropdown */
.select2-container--bootstrap-5 .select2-dropdown {
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border-primary) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-lg) !important;
}

/* Search input inside dropdown */
.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15) !important;
}

/* Results/options */
.select2-container--bootstrap-5 .select2-results__option {
    background-color: transparent !important;
    color: var(--text-primary) !important;
    padding: 0.5rem 0.75rem !important;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: rgba(88, 166, 255, 0.2) !important;
    color: var(--text-primary) !important;
}

.select2-container--bootstrap-5 .select2-results__option--selected {
    background-color: rgba(88, 166, 255, 0.15) !important;
    color: var(--accent-primary) !important;
}

/* No results message */
.select2-container--bootstrap-5 .select2-results__message {
    color: var(--text-secondary) !important;
}

/* Clear button */
.select2-container--bootstrap-5 .select2-selection__clear {
    color: var(--text-secondary) !important;
}

.select2-container--bootstrap-5 .select2-selection__clear:hover {
    color: var(--accent-danger) !important;
}

/* ============================================
   Bootstrap form-select Dark Theme
   ============================================ */
.form-select {
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238b949e' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") !important;
}

.form-select:focus {
    border-color: var(--accent-primary) !important;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15) !important;
}

.form-select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.topbar {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 900;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.nav-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.notif-badge {
    position: absolute;
    top: 6px;
    right: 4px;
    background: var(--accent-danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-secondary);
}

/* Notifications Dropdown */
.notifications-dropdown {
    position: relative;
}

#notifMenu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    margin-top: 0.5rem;
}

#notifMenu.show {
    display: flex;
}

.dropdown-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 600;
}

.dropdown-header a {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--accent-primary);
}

.dropdown-body {
    max-height: 400px;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-primary);
    transition: background var(--transition-fast);
}

.notif-item:hover {
    background: var(--bg-hover);
}

.notif-item.unread {
    background: rgba(88, 166, 255, 0.05);
}

.notif-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
}

.bg-primary-light {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent-primary);
}

.bg-warning-light {
    background: rgba(240, 136, 62, 0.15);
    color: var(--accent-warning);
}

.bg-info-light {
    background: rgba(163, 113, 247, 0.15);
    color: var(--accent-purple);
}

.notif-content {
    flex: 1;
    min-width: 0;
}

.notif-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.notif-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notif-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.dropdown-footer {
    padding: 0.75rem;
    text-align: center;
    border-top: 1px solid var(--border-primary);
    font-size: 0.8rem;
}

/* User Profile Mini */
.user-profile-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 1.5rem;
    border-left: 1px solid var(--border-primary);
}

.user-avatar-sm {
    width: 32px;
    height: 32px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
}

.user-info-mini {
    display: flex;
    flex-direction: column;
}

.user-info-mini .name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
}

.user-info-mini .role {
    font-size: 0.7rem;
    color: var(--text-secondary);
}