/* =========================================
   SISTEMA JUGUETES - ESTILOS BASE GENERALES
   ========================================= */

body, html {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f4f6f9;
    min-height: 100vh;
}

/* Ocultar header y menú móvil en escritorio */
.app-header-bar { display: none; }
.mobile-menu-btn { display: none; }
.sidebar-overlay { display: none; }

/* =========================================
   MENÚ LATERAL (SIDEBAR) - ESCRITORIO
   ========================================= */
.sidebar {
    width: 260px;
    background-color: #2c3e50; 
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000; /* Alto para estar sobre todo */
}

.sidebar-header {
    padding: 20px;
    font-size: 20px;
    font-weight: bold;
    background-color: #1a252f;
    text-align: center;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu li {
    border-bottom: 1px solid #34495e;
}

.sidebar-menu li a {
    display: block;
    padding: 15px 20px;
    color: #ecf0f1;
    text-decoration: none;
    transition: background 0.3s;
    border-left: 4px solid transparent; 
}

.sidebar-menu li a:hover, 
.sidebar-menu li.active a {
    background-color: #34495e;
    border-left: 4px solid #3498db; 
}

/* =========================================
   CONTENEDOR PRINCIPAL Y FORMULARIOS
   ========================================= */
.main-content {
    margin-left: 260px;
    padding: 20px;
    width: calc(100% - 260px);
    box-sizing: border-box;
    min-height: 100vh;
    background: linear-gradient(160deg, #dbeafe 0%, #f1f5f9 55%, #e0f2fe 100%);
    background-attachment: fixed;
}

/* Elementos de formulario por defecto */
input[type="text"], 
input[type="number"], 
input[type="password"], 
select {
    width: 100%;
    padding: 10px;
    margin: 5px 0 15px 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-family: inherit;
}

/* Tablas por defecto */
table {
    width: 100%;
    border-collapse: collapse;
}

/* =========================================
   REGLAS RESPONSIVAS (MENÚ DESLIZABLE TIPO APP)
   ========================================= */
@media (max-width: 768px) {
    
    body, html {
        display: block !important; 
        overflow-x: hidden !important; 
    }

    .app-header-bar {
        display: flex !important;
    }

    .mobile-menu-btn {
        display: flex !important;
    }

    body.menu-open {
        overflow: hidden !important;
    }

    .sidebar-overlay.active {
        display: block !important;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.6);
        z-index: 9998;
    }

    .sidebar {
        position: fixed !important;
        top: 56px !important;
        left: 0 !important;
        width: 260px !important;
        height: calc(100vh - 56px) !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease-in-out !important;
        z-index: 9999 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .sidebar.active {
        transform: translateX(0) !important;
    }

    .main-content {
        position: relative !important;
        margin-left: 0 !important;
        width: 100% !important;
        padding: 68px 15px 15px !important;
        box-sizing: border-box !important;
        background: linear-gradient(160deg, #dbeafe 0%, #f1f5f9 55%, #e0f2fe 100%) !important;
        background-size: auto !important;
    }

    /* Reglas de Formularios y Cajas Blancas (Cards) al máximo ancho disponible */
    div[style*="max-width"], 
    div[style*="width: 100%"],
    div[style*="padding: 40px"], 
    div[style*="padding: 30px"] {
        padding: 20px 15px !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 auto !important;
    }

    /* Apilar Campos de Formularios (Edad, Sexo, etc.) */
    div[style*="display: flex"] { display: block !important; }
    div[style*="flex: 1"] { width: 100% !important; margin-bottom: 15px !important; display: block !important; }
    
    /* Entradas amigables al tacto */
    input, select, button, input[type="submit"] { box-sizing: border-box !important; width: 100% !important; }
    button, .btn-login, input[type="submit"], .btn-exit, .app-logout, .logout-btn { padding: 15px !important; font-size: 16px !important; margin-top: 15px !important; text-align: center !important; }

    /* Arreglo específico: Título Padrón Comunal y Botones de Excel */
    div[style*="justify-content: space-between"] { display: flex !important; flex-direction: column !important; align-items: flex-start !important; gap: 15px !important; }
    div[style*="justify-content: space-between"] > div { display: flex !important; flex-direction: column !important; gap: 10px !important; width: 100% !important; }
    div[style*="justify-content: space-between"] > div > a, div[style*="justify-content: space-between"] > div > span { display: block !important; width: 100% !important; margin: 0 !important; text-align: center !important; padding: 12px !important; box-sizing: border-box !important; border-radius: 8px !important; }

    /* Arreglo de Tablas (Evita que el texto colapse) */
    table { font-size: 13px !important; white-space: nowrap !important; }
    th, td { padding: 10px !important; }
    div[style*="overflow-x: auto"] { width: 100% !important; display: block !important; border-radius: 8px; }
}
/* =========================================
   TABLAS DE REGISTROS (listar_registros, padrón municipal)
   ========================================= */
.app-table-container {
    background: #ffffff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
    margin-top: 20px;
    overflow-x: auto;
}

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

.app-table th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 600;
    padding: 14px 15px;
    border-bottom: 2px solid #e2e8f0;
    font-size: 14px;
}

.app-table td {
    padding: 14px 15px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    font-size: 14.5px;
}

.app-table tbody tr:hover {
    background-color: #f8fafc;
}

.badge-yes {
    background: #0eb337;
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    display: inline-block;
}

.badge-no {
    background: #c03030;
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    display: inline-block;
}

.empty-state {
    text-align: center;
    padding: 50px 20px;
}

.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.search-box {
    flex: 1;
    min-width: 250px;
    max-width: 400px;
    position: relative;
}

.search-box > span {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 16px;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 12px 15px 12px 40px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14.5px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.search-input:focus {
    border-color: #3b82f6;
}

.btn-nuevo {
    background-color: #3b82f6;
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14.5px;
    transition: background-color 0.2s;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.2);
}

.btn-nuevo:hover {
    background-color: #2563eb;
}

.btn-excel {
    background-color: #10b981;
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14.5px;
    transition: background-color 0.2s;
    border: none;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-excel:hover {
    background-color: #059669;
}

/* Acciones en tabla de usuarios (configuración) */
.tabla-acciones {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

.tabla-acciones form {
    display: inline;
    margin: 0;
}

.tabla-btn {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #475569;
    text-decoration: none;
}

.tabla-btn--primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

.tabla-btn--primary:hover {
    background: #2563eb;
}

.tabla-btn--danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.tabla-btn--success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.tabla-clave-panel {
    margin-top: 8px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    min-width: 220px;
}

.tabla-clave-panel label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    margin: 6px 0 4px 0;
}

.tabla-clave-panel .app-form-control {
    margin-bottom: 8px;
    padding: 8px 10px;
    font-size: 13px;
}

.tabla-clave-details summary {
    list-style: none;
    cursor: pointer;
}

.tabla-clave-details summary::-webkit-details-marker {
    display: none;
}

/* Modales (configuración usuarios) */
body.app-modal-open {
    overflow: hidden;
}

.app-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.app-modal[hidden] {
    display: none !important;
}

.app-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.app-modal__dialog {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    border: 1px solid #e2e8f0;
}

.app-modal__dialog--wide {
    max-width: 640px;
}

.app-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
}

.app-modal__close:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.app-modal__title {
    margin: 0 32px 8px 0;
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
}

.app-modal__subtitle {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: #64748b;
    line-height: 1.4;
}

.app-modal__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #f1f5f9;
}

.app-modal__btn-cancel {
    padding: 10px 18px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.app-modal__btn-cancel:hover {
    background: #f8fafc;
}

button.btn-nuevo {
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.stat-badge {
    background-color: #eff6ff;
    color: #1e40af;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    border: 1px solid #bfdbfe;
}

/* Contenedor ancho para listados con tabla (especificidad > .app-dashboard en dashboard.css) */
.main-content > .app-dashboard.app-dashboard--tabla {
    max-width: none;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
    box-sizing: border-box;
}

.app-table-container--wide,
.main-content .app-table-container--wide {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
}

.app-tabla-root {
    width: 100%;
    min-width: 0;
}

.table-controls--top {
    margin-bottom: 16px;
    gap: 10px;
}

.table-filters {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
}

.table-filters__row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.table-filters__row--selects {
    margin-bottom: 0;
}

.table-filters__search,
.table-filters .search-box {
    flex: 1;
    min-width: 280px;
    max-width: none;
}

.filtro-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.filtro-item span {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}

.filtro-select {
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    min-width: 140px;
}

.btn-filtro-limpiar {
    padding: 10px 16px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.btn-filtro-limpiar:hover {
    background: #f1f5f9;
}

.table-footer-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}

.table-info {
    margin: 0;
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
}

.table-pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.pag-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #334155;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.pag-btn:hover:not(:disabled) {
    background: #eff6ff;
    border-color: #93c5fd;
}

.pag-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pag-btn--active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
    cursor: default;
}

.pag-btn--ellipsis {
    min-width: 28px;
    padding: 0 4px;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: default;
    pointer-events: none;
}

/* Paginación y pie de tabla — responsive */
@media (max-width: 768px) {
    .table-footer-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
    }

    .table-info {
        text-align: center;
        font-size: 13px;
        line-height: 1.45;
        order: 1;
    }

    .table-pagination {
        order: 2;
        justify-content: flex-start;
        width: 100%;
        max-width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scroll-padding: 8px;
        padding: 6px 4px 10px;
        gap: 5px;
        mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    }

    .table-pagination .pag-btn {
        flex: 0 0 auto;
        scroll-snap-align: center;
        min-width: 42px;
        height: 42px;
        font-size: 14px;
        padding: 0 8px;
    }

    .table-pagination .pag-btn--ellipsis {
        min-width: 24px;
        height: 42px;
    }

    .filtro-item--pagina {
        flex: 1 1 100%;
        min-width: 0;
    }

    .filtro-item--pagina .filtro-select {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .table-pagination .pag-btn {
        min-width: 40px;
        height: 40px;
        font-size: 13px;
    }

    .table-info {
        font-size: 12px;
    }
}