/**
 * Estilos personalizados – Sistema de Votos
 */

:root {
    --primary-color: #dc3545;
    --primary-dark: #76131d;
    --primary-light: #f8d7da;
    --secondary-color: #6c757d;
    --light-gray: #f8f9fa;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --dark-gray: #343a40;
    --white: #ffffff;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #17a2b8;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius: 0.5rem;
    --radius-lg: 1rem;
    --transition: 250ms ease-in-out;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--dark-gray);
    background-color: #f5f7fa;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--dark-gray);
}

/* Login */
.login-body {
    background: linear-gradient(135deg, #c41e3a 0%, #9a0a12 50%, #7d0310 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.login-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    min-height: 100vh;
    max-width: 1000px;
    margin: 0 auto;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.2);
}

.login-panel-form {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--white);
}

.login-panel-info {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(160deg, rgba(196, 30, 58, 0.95) 0%, rgba(122, 10, 18, 0.98) 100%);
    color: rgba(255, 255, 255, 0.95);
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 2rem 2.25rem;
    border-radius: var(--radius-lg);
    animation: loginCardIn 0.4s ease-out;
}

@keyframes loginCardIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-card-header {
    margin-bottom: 1.75rem;
}

.login-logo {
    width: 120px;
    height: 120px;
    max-width: 120px;
    max-height: 120px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 1rem;
    border: 3px solid var(--primary-color);
}

.login-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0 0 0.25rem 0;
    letter-spacing: 0.02em;
}

.login-subtitle {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--dark-gray);
    margin: 0 0 0.35rem 0;
}

.login-form .form-label {
    font-weight: 500;
    color: var(--dark-gray);
    margin-bottom: 0.35rem;
}

.input-group-login .input-group-text {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-right: none;
    color: var(--primary-color);
}

.input-group-login .form-control {
    border: 1px solid var(--gray-300);
    border-left: none;
}

.input-group-login:focus-within .input-group-text {
    border-color: var(--primary-color);
    background: var(--primary-light);
    color: var(--primary-color);
}

.input-group-login .form-control:focus {
    border-color: var(--primary-color);
    box-shadow: none;
}

.input-group-login:focus-within .btn-password-toggle {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.input-group-login:focus-within {
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.2);
    border-radius: var(--radius);
}

.btn-password-toggle {
    border-color: var(--gray-300);
    color: var(--secondary-color);
}

.btn-password-toggle:hover {
    border-color: var(--gray-400);
    color: var(--dark-gray);
    background: var(--gray-100);
}

.btn-login {
    background: linear-gradient(180deg, #c41e3a 0%, #9a0a12 100%);
    border: none;
    color: var(--white);
    font-weight: 600;
    border-radius: var(--radius);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.btn-login:hover {
    background: linear-gradient(180deg, #a01830 0%, #7d0310 100%);
    color: var(--white);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(154, 10, 18, 0.4);
}

.btn-login:active {
    transform: translateY(0);
}

.btn-login:disabled {
    opacity: 0.85;
    transform: none;
    cursor: not-allowed;
}

.link-secondary {
    color: var(--secondary-color) !important;
    text-decoration: none;
}

.link-secondary:hover {
    color: var(--primary-color) !important;
    text-decoration: underline;
}

/* Panel derecho: información del sistema */
.login-info-content {
    text-align: center;
    max-width: 320px;
}

.login-info-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--white);
    margin: 0 0 1.25rem 0;
    line-height: 1.3;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.login-info-distrito {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.35rem 0;
    color: rgba(255, 255, 255, 0.95);
}

.login-info-depto {
    font-size: 1rem;
    margin: 0 0 2.5rem 0;
    color: rgba(255, 255, 255, 0.85);
}

.login-info-footer {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.75);
    line-height: 1.5;
}

/* Login responsive: una columna en móvil */
@media (max-width: 767px) {
    .login-wrapper {
        grid-template-columns: 1fr;
        max-width: 100%;
        min-height: auto;
    }

    .login-panel-form {
        order: 1;
        padding: 2rem 1.5rem;
        min-height: auto;
    }

    .login-panel-info {
        order: 2;
        padding: 1.5rem 1.25rem;
        background: linear-gradient(160deg, rgba(196, 30, 58, 0.92) 0%, rgba(122, 10, 18, 0.96) 100%);
    }

    .login-card {
        max-width: 100%;
        padding: 1.5rem 1.25rem;
    }

    .login-info-title {
        font-size: 1.25rem;
    }

    .login-info-distrito,
    .login-info-depto {
        font-size: 0.95rem;
    }

    .login-info-footer {
        font-size: 0.75rem;
    }
}

/* Sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition);
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    background: linear-gradient(180deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: var(--shadow-md);
    transition: all var(--transition);
    z-index: 1000;
    overflow-y: auto;
}

.sidebar.collapsed {
    width: 85px;
}

.sidebar-header {
    padding: 1.5rem;
    color: var(--white);
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.381);
}

.sidebar-header img {
    max-width: 56px;
    max-height: 56px;
    border-radius: 50%;
    margin-bottom: 0.5rem;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 10px 0 rgba(31, 30, 30, 0.637);
}

.sidebar-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--white);
}

.sidebar.collapsed .sidebar-header h4 {
    display: none;
}

.sidebar-menu {
    padding: 1rem 0.75rem;
}

.sidebar-menu .nav-link {
    color: rgba(255, 255, 255, 0.9);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    border-radius: var(--radius);
    margin-bottom: 0.25rem;
}

.sidebar-menu .nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
    border-left-color: rgba(255, 255, 255, 0.5);
}

.sidebar-menu .nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    border-left-color: var(--white);
    color: var(--white);
    font-weight: 600;
}

.sidebar-menu .nav-link i {
    width: 24px;
    margin-right: 0.75rem;
    font-size: 1.2rem;
}

.sidebar.collapsed .sidebar-menu .nav-link span {
    display: none;
}

.sidebar.collapsed .sidebar-menu .nav-link i {
    margin-right: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

/* Layout: footer abajo; contenido del dashboard desplazable */
body.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: hidden;
}

body.app-layout .main-content {
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.app-layout .main-content .topbar {
    flex-shrink: 0;
}

body.app-layout .content-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

body.app-layout .footer-app {
    flex-shrink: 0;
}

/* Desktop: permitir scroll en el body para ver todo el contenido del dashboard (tablas, footer, etc.) */
@media (min-width: 769px) {
    body.app-layout {
        overflow-y: auto;
        overflow-x: hidden;
    }
    body.app-layout .main-content {
        flex: 1 1 auto;
        min-height: auto;
        overflow: visible;
    }
    body.app-layout .content-area {
        overflow: visible;
        flex: none;
    }
}

/* Main */
.main-content {
    margin-left: 280px;
    min-height: 100vh;
    background-color: #f5f7fa;
    transition: margin-left var(--transition);
}

.main-content.expanded {
    margin-left: 85px;
}

.topbar {
    background: var(--white);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar h3 {
    margin: 0;
    color: var(--primary-color);
    font-weight: 600;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 10px 0 rgba(31, 30, 30, 0.637);
}

.content-area {
    padding: 1.5rem;
}

/* Cards */
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform var(--transition);
    border-left: 4px solid;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card.primary { border-left-color: var(--primary-color); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.info { border-left-color: var(--info); }

.stat-card .stat-icon {
    font-size: 2.5rem;
    opacity: 0.25;
    float: right;
}

/* Tables */
.data-table-container {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.table thead th {
    font-weight: 600;
    white-space: nowrap;
}

.table tbody tr:hover {
    background-color: rgba(220, 53, 69, 0.05);
}

/* Reportes: encabezado tabla (gris claro, texto negro legible) */
.table-reportes-header th {
    background-color: #dcdcdc !important;
    color: #000 !important;
    border-color: #c0c0c0;
    font-weight: 600;
}

/* Modals */
.modal-header {
    background: var(--primary-color);
    color: var(--white);
    border-bottom: none;
}

.modal-header .btn-close {
    filter: invert(1);
}

/* Forms */
.form-label {
    font-weight: 500;
    color: var(--dark-gray);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* Vista móvil (cards): oculta por defecto */
.table-mobile-view {
    display: none;
}

.table-mobile-view .text-center.p-3 {
    padding: 1.5rem !important;
    color: var(--secondary-color);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--secondary-color);
}

.empty-state i {
    font-size: 4rem;
    opacity: 0.3;
    margin-bottom: 1rem;
}

/* Scrollbar */
.content-area::-webkit-scrollbar {
    width: 8px;
}

.content-area::-webkit-scrollbar-track {
    background: var(--gray-100);
}

.content-area::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 4px;
}

.content-area::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content,
    .main-content.expanded {
        margin-left: 0;
    }

    .sidebar-overlay {
        display: none;
    }

    .sidebar-overlay.show {
        display: block;
    }

    /*
     * En móvil: página completa desplazable (incl. footer).
     * El footer deja de ser fijo para que el contenido se pueda desplazar y ver todo.
     */
    body.app-layout {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    body.app-layout .main-content {
        flex: 1 1 auto;
        min-height: auto;
        overflow: visible;
    }

    body.app-layout .content-area {
        padding: 1rem;
        overflow: visible;
        min-height: auto;
        flex: none;
        -webkit-overflow-scrolling: touch;
    }

    body.app-layout .footer-app {
        flex-shrink: 0;
    }

    .content-area {
        padding: 1rem;
    }

    .stat-card {
        margin-bottom: 1rem;
    }

    /*
     * Modales en móvil: el diálogo completo se desplaza (header + formulario + botón Guardar).
     * Altura fija + overflow en el diálogo para que el scroll funcione en todos los móviles.
     */
    .modal .modal-dialog,
    .modal .modal-dialog.modal-lg,
    .modal .modal-dialog.modal-sm,
    .modal .modal-dialog.modal-dialog-centered {
        margin: 0.5rem;
        height: 85vh;
        max-height: 85vh;
        overflow-y: scroll !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior-y: contain;
        position: relative;
    }

    @supports (height: 100dvh) {
        .modal .modal-dialog,
        .modal .modal-dialog.modal-lg,
        .modal .modal-dialog.modal-sm,
        .modal .modal-dialog.modal-dialog-centered {
            height: 85dvh;
            max-height: 85dvh;
        }
    }

    .modal .modal-dialog.modal-dialog-centered {
        margin: 0.5rem auto;
    }

    .modal .modal-content {
        max-height: none;
    }

    .modal .modal-body {
        overflow: visible;
    }

    .modal-backdrop {
        z-index: 1040;
    }

    .modal {
        z-index: 1050;
    }

    /* Tabla → Cards en móvil */
    .data-table-container:has(.table-mobile-view) .table-mobile-view {
        display: block;
    }

    .data-table-container:has(.table-mobile-view) .table-responsive {
        display: none !important;
    }
}

/* Cards móvil – estilo reducido */
.mobile-row-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

.mobile-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    cursor: pointer;
    gap: 0.75rem;
    transition: background-color 0.2s;
    position: relative;
    z-index: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mobile-row-header:hover {
    background-color: var(--gray-100);
}

.mobile-row-info {
    flex: 1;
    min-width: 0;
}

.mobile-row-info .row-cedula {
    font-size: 0.8rem;
    color: var(--secondary-color);
    margin-bottom: 0.15rem;
}

.mobile-row-info .row-nombre,
.mobile-row-info .row-apellido {
    font-weight: 600;
    color: var(--dark-gray);
}

.mobile-row-info .row-nombre {
    font-size: 1rem;
}

.mobile-row-info .row-apellido {
    font-size: 0.9rem;
    color: var(--dark-gray);
}

.mobile-row-toggle {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.25s, background-color 0.2s;
    position: relative;
    z-index: 2;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mobile-row-toggle:hover {
    background: var(--gray-100);
}

.mobile-row-toggle i {
    font-size: 1.1rem;
    color: var(--dark-gray);
    transition: transform 0.25s;
}

.mobile-row-header.active .mobile-row-toggle i {
    transform: rotate(180deg);
}

.mobile-row-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.mobile-row-details.active {
    max-height: 1200px;
}

.mobile-row-details > .mobile-row-detail-item:first-child {
    border-top: 1px solid var(--gray-200);
}

.mobile-row-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 0.75rem;
}

.mobile-row-detail-item:last-of-type {
    border-bottom: none;
}

.mobile-row-detail-label {
    flex-shrink: 0;
    font-weight: 500;
    color: var(--secondary-color);
    min-width: 110px;
}

.mobile-row-detail-value {
    text-align: right;
    flex: 1;
    word-break: break-word;
}

.mobile-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-100);
    position: relative;
    z-index: 1;
}

.mobile-row-actions .btn {
    flex: 1;
    min-width: 120px;
    position: relative;
    z-index: 2;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Dark mode: cards móvil (tonos grises originales) */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
    .mobile-row-card {
        background: #2d3748;
        border-color: #4a5568;
    }

    .mobile-row-header {
        color: #e2e8f0;
    }

    .mobile-row-header:hover {
        background-color: rgba(74, 85, 104, 0.4);
    }

    .mobile-row-info .row-cedula {
        color: #a0aec0;
    }

    .mobile-row-info .row-nombre,
    .mobile-row-info .row-apellido {
        color: #e2e8f0;
    }

    .mobile-row-toggle {
        background: #374151;
        border-color: #4a5568;
    }

    .mobile-row-toggle:hover {
        background: #4a5568;
    }

    .mobile-row-toggle i {
        color: #e2e8f0;
    }

    .mobile-row-detail-item {
        border-color: #4a5568;
    }

    .mobile-row-details > .mobile-row-detail-item:first-child {
        border-top-color: #4a5568;
    }

    .mobile-row-detail-label {
        color: #a0aec0;
    }

    .mobile-row-detail-value {
        color: #e2e8f0;
    }

    .mobile-row-actions {
        border-top-color: #4a5568;
        background: rgba(74, 85, 104, 0.3);
    }
}

/* Dark mode – tonos grises originales */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a202c;
        color: #e2e8f0;
    }

    h1, h2, h3, h4, h5, h6 {
        color: #e2e8f0;
    }

    .card,
    .stat-card,
    .data-table-container {
        background-color: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .table {
        color: #e2e8f0;
    }

    .table th {
        background-color: #4a5568;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .table td {
        border-color: #4a5568;
    }

    .table tbody tr:hover {
        background-color: rgba(74, 85, 104, 0.5);
    }

    .sidebar {
        background: linear-gradient(180deg, var(--primary-color) 0%, var(--primary-dark) 100%);
        border-color: rgba(255, 255, 255, 0.15);
    }

    .sidebar-menu .nav-link {
        color: rgba(255, 255, 255, 0.9);
    }

    .sidebar-menu .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff;
    }

    .sidebar-menu .nav-link.active {
        background-color: rgba(255, 255, 255, 0.2);
        color: #fff;
    }

    .main-content {
        background-color: #343f55;
    }

    .topbar {
        background: linear-gradient(180deg, var(--primary-color) 0%, var(--primary-dark) 100%);
        border-color: rgba(255, 255, 255, 0.15);
    }

    .topbar h3 {
        color: #fff;
    }

    .content-area {
        background-color: #343f55;
    }

    .form-control,
    .form-select {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .form-control::placeholder {
        color: #a0aec0;
    }

    .form-label,
    .text-muted {
        color: #a0aec0 !important;
    }

    .modal-content {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .modal-header {
        background: var(--primary-color) !important;
        color: #fff !important;
        border-color: rgba(255, 255, 255, 0.15);
    }

    .empty-state {
        color: #a0aec0;
    }

    .content-area::-webkit-scrollbar-track {
        background: #2d3748;
    }

    .content-area::-webkit-scrollbar-thumb {
        background: #4a5568;
    }

    .content-area::-webkit-scrollbar-thumb:hover {
        background: #718096;
    }
}
