:root {
    --primary-color: #C41E3A;
    --primary-light: #e8b4bc;
    --bogota-red-light: rgba(196, 30, 58, 0.1);
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    --secondary-color: #6c757d;
}

body {
    background-color: #f8f9fa;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.navbar-brand { font-weight: 700; color: var(--primary-color) !important; }
.navbar { background: white; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }

@media (max-width: 575.98px) {
    .navbar { padding: 0.5rem 0.75rem; }
    .navbar-brand { font-size: 1rem; }
    .navbar-brand i { font-size: 1.1rem; }
}

.main-card { background: white; border-radius: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); overflow: hidden; }
.main-card-header { background: linear-gradient(135deg, var(--primary-color) 0%, #a01830 100%); color: white; padding: 1.5rem; }
.main-card-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 0.75rem; }
.main-card-body { padding: 1.5rem; }

.certificados-layout { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 992px) { .certificados-layout { grid-template-columns: 380px 1fr; min-height: calc(100vh - 200px); } }
.search-column { min-width: 0; }
.pdf-column { min-width: 0; }

.search-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; border-bottom: 2px solid #e9ecef; padding-bottom: 0; }
.search-tab { padding: 0.6rem 1rem; border: none; background: transparent; color: var(--secondary-color); font-weight: 600; font-size: 0.9rem; cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.3s ease; margin-bottom: -2px; }
.search-tab:hover { color: var(--primary-color); }
.search-tab.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.search-tab i { margin-right: 0.5rem; }
.search-panel { display: none; }
.search-panel.active { display: block; }

.form-section { background: #f8f9fa; border-radius: 12px; padding: 1.25rem; margin-bottom: 1rem; }
.input-group-custom { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.input-wrapper { flex: 1; min-width: 150px; }
.input-wrapper label { font-weight: 600; font-size: 0.9rem; color: #212529; margin-bottom: 0.5rem; display: block; }
.form-input { height: 48px; font-size: 1rem; border: 2px solid #dee2e6; border-radius: 10px; transition: all 0.3s ease; }
.form-input:focus { border-color: var(--primary-color); box-shadow: 0 0 0 4px var(--bogota-red-light); }
.chip-input { font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.direccion-input { font-weight: 500; }

.btn-action { height: 48px; min-width: 140px; background: linear-gradient(135deg, var(--primary-color) 0%, #a01830 100%); border: none; border-radius: 10px; color: white; font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; justify-content: center; gap: 0.5rem; transition: all 0.3s ease; }
.btn-action:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(196, 30, 58, 0.3); }
.btn-action:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-action .spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.results-section { display: none; margin-top: 1rem; }
.results-section.visible { display: block; }
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.results-title { font-size: 1rem; font-weight: 600; color: #212529; display: flex; align-items: center; gap: 0.5rem; }
.results-count { background: var(--bogota-red-light); color: var(--primary-color); padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.8rem; font-weight: 600; }
.predios-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: calc(100vh - 520px); overflow-y: auto; }
@media (min-width: 992px) { .predios-list { max-height: calc(100vh - 480px); } }
.predio-card { display: flex; align-items: center; gap: 0.75rem; background: white; border: 1px solid #e9ecef; border-radius: 10px; padding: 0.75rem; transition: all 0.2s ease; cursor: default; }
.predio-card:hover { border-color: var(--success-color); box-shadow: 0 2px 8px rgba(40, 167, 69, 0.1); }
.predio-card.selected { border-color: var(--success-color); background: #f0fff4; box-shadow: 0 2px 8px rgba(40, 167, 69, 0.15); }
.predio-card-info { flex: 1; min-width: 0; }
.predio-card-chip { font-weight: 700; font-family: monospace; color: var(--primary-color); font-size: 0.82rem; margin-bottom: 0.15rem; word-break: break-all; }
.predio-card-direccion { color: #495057; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-select { flex-shrink: 0; background: var(--success-color); border: none; color: white; padding: 0.5rem 0.85rem; border-radius: 8px; font-weight: 600; font-size: 0.8rem; display: flex; align-items: center; gap: 0.35rem; transition: all 0.2s ease; }
.btn-select:hover:not(:disabled) { background: #218838; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(40, 167, 69, 0.25); }
.btn-select:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

.error-state { display: none; background: #fff5f5; border: 1px solid #fed7d7; border-radius: 10px; padding: 1rem; margin-top: 0.75rem; }
.error-state.visible { display: block; }
.error-state h4 { color: var(--danger-color); font-size: 0.9rem; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.error-state p { color: #718096; margin: 0; font-size: 0.85rem; }

.info-box { background: #e7f5ff; border: 1px solid #b3d7ff; border-radius: 10px; padding: 0.85rem 1rem; margin-top: 1rem; display: flex; align-items: flex-start; gap: 0.6rem; }
.info-box i { color: var(--info-color); font-size: 1.1rem; margin-top: 0.1rem; }
.info-box-content { flex: 1; }
.info-box-title { font-weight: 600; font-size: 0.85rem; color: #212529; margin-bottom: 0.2rem; }
.info-box-text { font-size: 0.8rem; color: #495057; margin: 0; }

.pdf-section { display: none; height: 100%; }
.pdf-section.visible { display: flex; flex-direction: column; }
.pdf-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.75rem; }
.pdf-title { font-size: 1rem; font-weight: 600; color: #212529; display: flex; align-items: center; gap: 0.5rem; }
.pdf-title i { color: var(--danger-color); }
.chip-badge { background: var(--bogota-red-light); color: var(--primary-color); padding: 0.4rem 0.8rem; border-radius: 20px; font-weight: 600; font-size: 0.8rem; }
.pdf-container { background: #e9ecef; border-radius: 12px; overflow: hidden; position: relative; flex: 1; min-height: 500px; }
@media (min-width: 992px) { .pdf-container { min-height: 0; } }
.pdf-iframe { width: 100%; height: 100%; min-height: 500px; border: none; display: block; }
@media (min-width: 992px) { .pdf-iframe { position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: auto; } }
.pdf-loading { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; z-index: 10; }
.pdf-loading.hidden { display: none; }
.pdf-loading .spinner-large { width: 48px; height: 48px; border: 4px solid var(--primary-light); border-top-color: var(--primary-color); border-radius: 50%; animation: spin 1s linear infinite; }
.pdf-loading p { color: var(--secondary-color); font-weight: 500; margin: 0; }
.btn-download { background: var(--success-color); border: none; color: white; padding: 0.6rem 1.25rem; border-radius: 8px; font-weight: 600; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.5rem; transition: all 0.3s ease; text-decoration: none; }
.btn-download:hover { background: #218838; color: white; transform: translateY(-2px); box-shadow: 0 6px 15px rgba(40, 167, 69, 0.3); }

.pdf-empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 500px; background: #f8f9fa; border-radius: 12px; border: 2px dashed #dee2e6; text-align: center; padding: 2rem; }
.pdf-empty-state i { font-size: 4rem; color: #dee2e6; margin-bottom: 1rem; }
.pdf-empty-state h4 { color: #6c757d; font-size: 1.1rem; margin-bottom: 0.5rem; }
.pdf-empty-state p { color: #adb5bd; font-size: 0.9rem; margin: 0; }

.direccion-mode-toggle { display: flex; gap: 0; margin-bottom: 1rem; background: #e9ecef; border-radius: 8px; padding: 3px; }
.mode-btn { flex: 1; padding: 0.5rem 0.75rem; border: none; background: transparent; color: var(--secondary-color); font-weight: 600; font-size: 0.8rem; cursor: pointer; transition: all 0.25s ease; display: flex; align-items: center; justify-content: center; gap: 0.35rem; border-radius: 6px; }
.mode-btn.active { background: white; color: var(--primary-color); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.mode-btn:hover:not(.active) { color: #495057; }

.direccion-controls { background: white; border-radius: 12px; padding: 1rem; border: 1.5px solid #e2e8f0; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.ctrl-row { display: flex; gap: 6px; align-items: flex-end; }
.ctrl-row + .ctrl-row { margin-top: 10px; padding-top: 10px; border-top: 1.5px solid #f1f3f5; }
.ctrl-field { display: flex; flex-direction: column; gap: 3px; }
.ctrl-field label { font-size: 0.65rem; font-weight: 700; color: #adb5bd; text-transform: uppercase; letter-spacing: 0.8px; padding-left: 2px; }
.ctrl-input { height: 40px !important; font-size: 0.9rem !important; padding: 0 6px !important; border-radius: 8px !important; border: 1.5px solid #e2e8f0 !important; font-weight: 600; text-align: center; background: #fafbfc !important; transition: all 0.2s ease !important; color: #212529 !important; }
.ctrl-input:hover { border-color: #ced4da !important; background: white !important; }
.ctrl-input:focus { border-color: var(--primary-color) !important; box-shadow: 0 0 0 3px var(--bogota-red-light) !important; background: white !important; }
.ctrl-input::placeholder { color: #ced4da !important; font-weight: 400 !important; }
.ctrl-tipo-via .ctrl-input { width: 60px; }
.ctrl-num-via .ctrl-input { width: 54px; }
.ctrl-prefijo .ctrl-input { width: 40px; }
.ctrl-bis .ctrl-input { width: 54px; }
.ctrl-letra-compl .ctrl-input { width: 40px; }
.ctrl-cuadrante-via .ctrl-input { width: 64px; }
.ctrl-separator { display: flex; align-items: center; font-size: 0.8rem; font-weight: 800; color: var(--primary-color); padding-bottom: 1px; user-select: none; }
.ctrl-separator.no-label { font-size: 0.7rem; color: #adb5bd; letter-spacing: 0.5px; }
.ctrl-num-gen .ctrl-input { width: 54px; }
.ctrl-letra-gen .ctrl-input { width: 40px; }
.ctrl-placa .ctrl-input { width: 54px; }
.ctrl-cuadrante-placa .ctrl-input { width: 64px; }

.direccion-preview { margin-top: 0.85rem; padding: 0.65rem 0.85rem; background: linear-gradient(135deg, #f8faff 0%, #eef4ff 100%); border-radius: 10px; border: 1.5px solid #d0e0f5; display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.preview-label { font-weight: 600; color: #6c757d; font-size: 0.78rem; }
.preview-text { font-weight: 700; color: #212529; font-family: 'SF Mono', 'Cascadia Code', monospace; letter-spacing: 0.3px; }
.ctrl-btn-buscar { margin-top: 0.85rem; height: 44px; width: 100%; min-width: unset; }

@media (max-width: 480px) {
    .ctrl-row { gap: 4px; flex-wrap: wrap; }
    .ctrl-tipo-via .ctrl-input { width: 52px; }
    .ctrl-num-via .ctrl-input { width: 46px; }
    .ctrl-cuadrante-via .ctrl-input { width: 56px; }
    .ctrl-cuadrante-placa .ctrl-input { width: 56px; }
    .ctrl-input { height: 38px !important; font-size: 0.82rem !important; }
    .ctrl-separator { font-size: 0.7rem; }
}

@media (max-width: 991px) {
    .main-card-body { padding: 1rem; }
    .input-group-custom { flex-direction: column; }
    .btn-action { width: 100%; }
    .pdf-iframe { height: 500px; }
    .pdf-header { flex-direction: column; align-items: flex-start; }
    .search-tabs { flex-wrap: wrap; }
    .search-tab { padding: 0.5rem 0.8rem; font-size: 0.85rem; }
}

@media (hover: none) and (pointer: coarse) {
    .btn-action:hover:not(:disabled), .btn-select:hover:not(:disabled), .btn-download:hover { transform: none !important; }
}