/* ============================================================
   Sistema Gestor de Permisos — Estilos Base
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Paleta principal */
    --primary:       #4f46e5;
    --primary-hover:  #4338ca;
    --primary-light:  #eef2ff;
    --secondary:     #0ea5e9;
    --accent:        #8b5cf6;

    /* Semáforo de estados */
    --success:  #10b981;
    --warning:  #f59e0b;
    --danger:   #ef4444;
    --info:     #3b82f6;

    /* Neutros */
    --bg:          #f1f5f9;
    --bg-card:     #ffffff;
    --border:      #e2e8f0;
    --text:        #1e293b;
    --text-muted:  #64748b;
    --text-light:  #94a3b8;

    /* Sidebar */
    --sidebar-bg:     #1e1b4b;
    --sidebar-hover:  #312e81;
    --sidebar-text:   #c7d2fe;
    --sidebar-active: #4f46e5;

    /* Sombras y radios */
    --shadow-sm:  0 1px 2px rgba(0,0,0,.05);
    --shadow:     0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --shadow-lg:  0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
    --radius:     0.5rem;
    --radius-lg:  0.75rem;

    --transition: all .2s ease;
}

/* ─── RESET ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

/* ─── SCROLLBAR PERSONALIZADO ────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-hover); }

/* ─── LAYOUT PRINCIPAL ───────────────────────────── */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ─── SIDEBAR ────────────────────────────────────── */
.sidebar {
    width: 260px;
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transition: var(--transition);
}
.sidebar-brand {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .75rem;
}
.sidebar-brand .icon { font-size: 1.5rem; }

.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1.5rem;
    color: var(--sidebar-text);
    font-size: .9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: var(--transition);
}
.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: #fff;
    border-left-color: var(--accent);
}
.sidebar-nav a.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: #fff;
}
.sidebar-nav .icon { font-size: 1.1rem; width: 1.3rem; text-align: center; }

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .82rem;
}

/* ─── MAIN CONTENT ───────────────────────────────── */
.main-content {
    margin-left: 260px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
}

/* Topbar */
.topbar {
    background: var(--bg-card);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title { 
    font-size: 1.15rem; 
    font-weight: 600; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    min-width: 0; 
    flex: 1 1 auto; 
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    flex-shrink: 0;
}

/* Container */
.content-area { padding: 2rem; flex: 1; }

/* ─── CARDS ──────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
    min-width: 0; /* Evita que crezca más que su contenedor en grids */
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1.1rem; font-weight: 600; }

/* ─── STATS GRID ─────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: #fff;
}
.stat-icon.primary  { background: linear-gradient(135deg, var(--primary), var(--accent)); }
.stat-icon.success  { background: linear-gradient(135deg, var(--success), #34d399); }
.stat-icon.warning  { background: linear-gradient(135deg, var(--warning), #fbbf24); }
.stat-icon.info     { background: linear-gradient(135deg, var(--info), var(--secondary)); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .82rem; color: var(--text-muted); margin-top: .2rem; }

/* ─── TABLAS ─────────────────────────────────────── */
.table-wrapper { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    padding-bottom: 5px; 
    width: 100%;
    position: relative;
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; white-space: nowrap; }
thead { background: var(--bg); }
th {
    text-align: left;
    padding: .75rem 1rem;
    font-weight: 600;
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}
td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr { transition: var(--transition); }
tbody tr:hover { background: var(--primary-light); }

/* ─── FILTROS ────────────────────────────────────── */
.filter-row {
    display: flex;
    gap: .75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    padding: 0 1rem;
    align-items: center;
}
.filter-row .form-control { flex: 1; min-width: 150px; }
.filter-row .btn { flex-shrink: 0; }

@media (max-width: 768px) {
    .filter-row { gap: .5rem; padding: 0 .5rem; }
    .filter-row .form-control { 
        min-width: calc(50% - .5rem); 
        max-width: none !important; 
    }
}
@media (max-width: 480px) {
    .filter-row .form-control { 
        min-width: 100%; 
    }
}

/* ─── BADGES ─────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-activo    { background: #d1fae5; color: #065f46; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-suspendido{ background: #fee2e2; color: #991b1b; }
.badge-vencido   { background: #e2e8f0; color: #475569; }

/* ─── BOTONES ────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem 1.25rem;
    font-size: .9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    font-family: 'Inter', sans-serif;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #dc2626; }
.btn-outline   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-sm { padding: .35rem .75rem; font-size: .82rem; }
.btn-lg { padding: .75rem 1.75rem; font-size: 1rem; }

/* ─── FORMULARIOS ────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: .35rem;
    font-size: .85rem;
    font-weight: 500;
    color: var(--text);
}
.form-control {
    width: 100%;
    padding: .6rem .85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    font-family: 'Inter', sans-serif;
    background: #fff;
    transition: var(--transition);
    color: var(--text);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8.825L.475 3.3l.85-.85L6 7.125 10.675 2.45l.85.85z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2rem; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* ─── MODALES ────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn .25s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
    background: none; border: none; font-size: 1.4rem;
    cursor: pointer; color: var(--text-muted);
    transition: var(--transition);
}
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 1.5rem; }
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
}

/* ─── MAP CONTAINER ──────────────────────────────── */
.map-container {
    width: 100%;
    height: 350px;
    border-radius: var(--radius);
    border: 1.5px solid var(--border);
    overflow: hidden;
    margin-bottom: 1rem;
}

/* ─── TOAST / NOTIFICACIONES ─────────────────────── */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.toast {
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 500;
    color: #fff;
    min-width: 280px;
    box-shadow: var(--shadow-lg);
    animation: toastIn .3s ease, toastOut .3s ease 3.7s forwards;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--info); }
@keyframes toastIn  { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-20px); } }

/* ─── QUICK DATE BUTTONS ─────────────────────────── */
.date-quick-btns {
    display: flex;
    gap: .5rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}
.date-quick-btns .btn {
    padding: .3rem .7rem;
    font-size: .78rem;
    border-radius: 99px;
}

/* ─── LOGIN PAGE ─────────────────────────────────── */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4f46e5 100%);
    padding: 1rem;
}
.login-card {
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    color: var(--sidebar-bg);
    margin-bottom: .5rem;
}
.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .9rem;
    margin-bottom: 2rem;
}
.login-card .btn { width: 100%; justify-content: center; padding: .75rem; }

/* ─── PUBLIC QR PAGES ────────────────────────────── */
.public-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 1rem;
}
.public-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.public-card .status-badge {
    display: inline-block;
    padding: .4rem 1.2rem;
    border-radius: 99px;
    font-size: .9rem;
    font-weight: 700;
    text-transform: uppercase;
    margin: 1rem 0;
}
.status-valid   { background: #d1fae5; color: #065f46; }
.status-invalid { background: #fee2e2; color: #991b1b; }

/* ─── OVERLAY MENU MÓVIL ─────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 90;
}
.sidebar.open ~ .sidebar-overlay {
    display: block;
}

/* ─── RESPONSIVO ─────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 240px;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .content-area { padding: 1rem; }
    
    /* Mostrar botón de menú */
    #menuToggle { display: inline-flex !important; }
    
    .topbar { padding: 0.75rem 1rem; }
    .topbar-title { font-size: 1rem; max-width: none; }
    .topbar-user span { display: none; } /* Ocultar nombre en móvil para dar espacio */
    
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    
    /* Forzar grids manuales en dashboard y modales */
    div[style*="display:grid"][style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="minmax(300px"] {
        grid-template-columns: 1fr !important;
        min-width: 0;
    }
    
    div[style*="display:grid"] > * {
        min-width: 0;
    }

    /* Fix flex layouts in modales details */
    #detalleBody > div:first-child { flex-direction: column !important; }
    #detalleBody > div:first-child > div { width: 100% !important; margin-bottom: 15px; }
    
    .modal { width: 95%; margin: 10px; }

    /* Botones compactos en móvil */
    .btn .btn-text { display: none; }
    .btn i { margin-right: 0 !important; font-size: 1.2rem; }
    .btn { padding: 0.5rem 0.75rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .content-area { padding: 0.75rem; }
    .topbar-title { font-size: 0.9rem; max-width: 100px; }
}

/* ─── SEARCH LOADER ──────────────────────────────── */
.search-loader {
    display: none;
    align-items: center;
    gap: .5rem;
    font-size: .85rem;
    color: var(--primary);
    font-weight: 500;
    margin-left: 0.5rem;
}
.search-loader.active { display: inline-flex; }
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
