* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --success-color: #16a34a;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.actions-bar {
    margin-bottom: 2rem;
}

.actions-bar-top {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.municipios-count {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.total-count {
    text-align: center;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

.btn span {
    font-size: 1.25rem;
    font-weight: bold;
}

.expedientes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.expediente-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.2s;
    cursor: pointer;
    border: 1px solid var(--border-color);
    position: relative;
}

.expediente-card.visita-realizada {
    background: #f0fdf4;
    border-color: #86efac;
}

.expediente-card.incidencia {
    background: #fee2e2;
    border-color: #ef4444;
    border-width: 2px;
}

.expediente-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.expediente-card.incidencia:hover {
    box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.2), 0 4px 6px -2px rgba(239, 68, 68, 0.1);
}

.expediente-card.visita-realizada:hover {
    box-shadow: 0 10px 15px -3px rgba(34, 197, 94, 0.1), 0 4px 6px -2px rgba(34, 197, 94, 0.05);
}

.expediente-card .numero-orden {
    position: absolute;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 1;
}

.expediente-card .numero-expediente {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: 1.5rem;
}

.expediente-card .ubicacion {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.link-button {
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: color 0.2s;
}

.link-button:hover {
    color: var(--primary-color);
}

.municipio-line {
    font-size: 1rem;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.catastro-line {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-weight: 400;
}

.catastro-link {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s;
}

.catastro-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.expediente-card .observaciones {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Ajuste para 6 botones en el footer (2 filas de 3) */
.card-footer {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.icon-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.icon-btn .icon,
.icon-btn i {
    font-size: 1.2rem;
}

.icon-btn i {
    display: inline-flex;
    align-items: center;
}

.icon-btn.danger {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: #fff;
}

.icon-btn.danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.icon-btn.warning {
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.2);
}

.icon-btn.warning:hover {
    background: rgba(239, 68, 68, 0.2);
}

.icon-btn.success {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.icon-btn.success:hover {
    background: rgba(34, 197, 94, 0.2);
}

.icon-btn.archived {
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
    border-color: rgba(37, 99, 235, 0.2);
}

.icon-btn.archived:hover {
    background: rgba(37, 99, 235, 0.2);
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-state.hidden {
    display: none;
}

.empty-state .hint {
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 0.75rem;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-large {
    max-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
}

.btn-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 0.75rem;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 2rem;
    background-color: var(--bg-color);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background-color: rgba(37, 99, 235, 0.05);
}

.drop-zone-content svg {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.drop-zone-content p {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.drop-zone-content .hint {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: normal;
}

.archivos-section {
    margin-top: 2rem;
}

.archivos-section h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.archivos-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.archivos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.archivos-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
}

.archivos-toolbar .select-all {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

#btnDescargarArchivos:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.archivo-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    position: relative;
    transition: all 0.2s;
}

.archivo-checkbox {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.archivo-item:hover {
    box-shadow: var(--shadow);
}

.archivo-icon-link {
    display: block;
    text-decoration: none;
    margin: 0 auto 0.5rem;
    width: fit-content;
    transition: transform 0.2s;
}

.archivo-icon-link:hover {
    transform: scale(1.1);
}

.archivo-item .archivo-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border-radius: 0.5rem;
    font-size: 1.5rem;
    cursor: pointer;
}

.archivo-item .archivo-icon i {
    font-size: 1.5rem;
    color: white;
}

.incidencia-nota {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.incidencia-nota label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #b91c1c;
    display: block;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.incidencia-nota textarea {
    width: 100%;
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 0.5rem;
    padding: 0.5rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 0.5rem;
}

.incidencia-nota textarea:focus {
    outline: none;
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.btn-nota {
    background: #ef4444;
    color: white;
    border: none;
    padding: 0.35rem 0.75rem;
    border-radius: 0.4rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-nota:hover {
    background: #dc2626;
}

.btn-nota-cancelar {
    background: #64748b;
    color: white;
    border: none;
    padding: 0.35rem 0.75rem;
    border-radius: 0.4rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-nota-cancelar:hover {
    background: #475569;
}

.archivo-item .archivo-nombre {
    font-size: 0.875rem;
    color: var(--text-primary);
    text-align: center;
    word-break: break-word;
    margin-bottom: 0.5rem;
}

.archivo-item .archivo-acciones {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.archivo-item .btn-eliminar-archivo {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}


.detalle-info {
    margin-bottom: 2rem;
}

.detalle-info .info-item {
    margin-bottom: 1rem;
}

.detalle-info .info-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.detalle-info .info-value {
    color: var(--text-primary);
    font-size: 1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

/* Loading */
.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.loading.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Carrusel de imágenes */
.modal-carrusel {
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
    height: auto;
    display: flex;
    flex-direction: column;
}

.carrusel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 0.75rem 0.75rem 0 0;
}

.carrusel-contador {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.carrusel-body {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 400px;
    max-height: calc(95vh - 150px);
    background: #000;
    overflow: hidden;
}

.carrusel-imagen-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.carrusel-imagen-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 0.5rem;
}

.carrusel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-primary);
    transition: all 0.2s;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.carrusel-btn:hover:not(:disabled) {
    background: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.carrusel-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.carrusel-btn-prev {
    left: 1rem;
}

.carrusel-btn-next {
    right: 1rem;
}

.carrusel-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 0 0 0.75rem 0.75rem;
    text-align: center;
}

.carrusel-nombre {
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
}

/* Miniatura de imagen en archivos */
.archivo-imagen-miniatura {
    width: 100%;
    height: 150px;
    margin: 0 auto 0.5rem;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 2px solid var(--border-color);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
}

.archivo-imagen-miniatura:hover {
    border-color: var(--primary-color);
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.archivo-imagen-miniatura img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .expedientes-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        max-width: 100%;
    }

    .archivos-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .carrusel-body {
        min-height: 300px;
        max-height: calc(95vh - 120px);
    }

    .carrusel-btn {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.25rem;
    }

    .carrusel-btn-prev {
        left: 0.5rem;
    }

    .carrusel-btn-next {
        right: 0.5rem;
    }
}