/* ==========================================================================
   Fase 10 - Flexibilidad operativa y documentación por proyecto
   Proyectos, versiones, editor amplio, compositor de email, plazos,
   carpeta de documentos, sincronización de obra y configuración.
   ========================================================================== */

.mt-05 { margin-top: 0.5rem; }
.text-warning { color: var(--warning); }
.texto-preformateado { white-space: pre-line; }

.btn-group-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* ─── Estados de proyecto ───────────────────────────── */
.status-pill.proyecto-presupuestado { background: #F1F5F9; color: #64748B; }
.status-pill.proyecto-enviado { background: #EFF6FF; color: #3B82F6; }
.status-pill.proyecto-aceptado { background: #ECFDF5; color: #059669; }
.status-pill.proyecto-en_obra { background: #FFF7ED; color: #C2410C; }
.status-pill.proyecto-finalizado { background: #F5F3FF; color: #7C3AED; }
.status-pill.proyecto-rechazado { background: #FEF2F2; color: #EF4444; }
.status-pill.superada { background: #F1F5F9; color: #94A3B8; }
[data-theme="dark"] .status-pill.proyecto-presupuestado,
[data-theme="dark"] .status-pill.superada { background: #1E293B; color: #94A3B8; }
[data-theme="dark"] .status-pill.proyecto-enviado { background: #1E3A5F; color: #60A5FA; }
[data-theme="dark"] .status-pill.proyecto-aceptado { background: #064E3B; color: #34D399; }
[data-theme="dark"] .status-pill.proyecto-en_obra { background: #431407; color: #FDBA74; }
[data-theme="dark"] .status-pill.proyecto-finalizado { background: #2E1065; color: #C4B5FD; }
[data-theme="dark"] .status-pill.proyecto-rechazado { background: #450A0A; color: #FCA5A5; }

/* ─── Badges de versión y firma ─────────────────────── */
.version-badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--bg-muted);
    color: var(--text-secondary);
    white-space: nowrap;
}
.version-badge.vigente { background: var(--success-50); color: var(--success); }
.version-badge.superada { background: var(--bg-subtle); color: var(--text-disabled); text-decoration: line-through; }

.firma-badge { font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.firma-badge.pendiente { color: var(--warning); }
.firma-badge.firmado { color: var(--success); }

.origen-badge {
    margin-left: 0.35rem;
    font-size: 0.7rem;
    padding: 0 0.3rem;
    border-radius: var(--radius-sm);
    background: var(--info-50);
    color: var(--info);
}

.tab-count {
    display: inline-block;
    min-width: 1.2rem;
    padding: 0 0.35rem;
    margin-left: 0.25rem;
    border-radius: 999px;
    font-size: 0.7rem;
    line-height: 1.2rem;
    text-align: center;
    color: #fff;
    background: var(--text-muted);
}
.tab-count.warning { background: var(--warning); }
.tab-count.error { background: var(--danger); }

.proyecto-link { font-size: 0.8rem; white-space: nowrap; }

.fila-superada td { color: var(--text-disabled); }

/* ─── Tipo de línea ─────────────────────────────────── */
.tipo-linea-badge {
    display: inline-block;
    min-width: 2.2rem;
    padding: 0 0.3rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
    background: #E0F2FE;
    color: #0369A1;
}
.tipo-linea-badge.mano_obra { background: #FEF3C7; color: #B45309; }
.tipo-linea-badge.subcontrata_servicio { background: #EDE9FE; color: #6D28D9; }
[data-theme="dark"] .tipo-linea-badge { background: #0C4A6E; color: #7DD3FC; }
[data-theme="dark"] .tipo-linea-badge.mano_obra { background: #78350F; color: #FCD34D; }
[data-theme="dark"] .tipo-linea-badge.subcontrata_servicio { background: #4C1D95; color: #C4B5FD; }

.tipo-linea-select { font-size: 0.8rem; }
.tipo-linea-select.mano_obra { border-left: 3px solid #D97706; }
.tipo-linea-select.material { border-left: 3px solid #0284C7; }
.tipo-linea-select.subcontrata_servicio { border-left: 3px solid #7C3AED; }
.form-select-sm { font-size: 0.8rem; padding-top: 0.2rem; padding-bottom: 0.2rem; }

.desglose-tipos,
.desglose-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    padding: 0.6rem 0.75rem;
    margin: 0.5rem 0;
    border-radius: var(--radius);
    background: var(--bg-subtle);
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.desglose-tipos strong,
.desglose-mini strong { color: var(--text-primary); margin-left: 0.25rem; }

/* ─── Editor de presupuesto ─────────────────────────── */
.versiones-barra {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-top: 0.4rem;
}
.version-chip { text-decoration: none; }
.version-chip.actual .version-badge { outline: 2px solid var(--primary); }

.editor-acciones {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
}

.editor-cabecera { max-width: 640px; }

.aviso-obra,
.aviso-solo-lectura,
.composer-aviso {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.6rem 0.8rem;
    margin: 0.5rem 0 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--info-50);
    color: var(--info);
}
.aviso-solo-lectura { background: var(--bg-subtle); color: var(--text-secondary); }
.composer-aviso { background: var(--warning-50); color: var(--warning); }

.presupuesto-editor.solo-lectura .partidas-editor input,
.presupuesto-editor.solo-lectura .partidas-editor select { background: transparent; }

.bloque-deshabilitado { opacity: 0.85; }

.partidas-editor td { vertical-align: top; }

/* ─── Editor amplio (textarea auto-grow + ⤢) ───────── */
.texto-amplio { position: relative; }
.texto-amplio textarea.auto-grow {
    resize: vertical;
    min-height: 2.25rem;
    overflow-y: auto;
    padding-right: 2rem;
    line-height: 1.4;
}
.texto-amplio-btn {
    position: absolute;
    top: 0.3rem;
    right: 0.35rem;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
}
.texto-amplio-btn:hover,
.texto-amplio-btn:focus-visible { opacity: 1; color: var(--primary); border-color: var(--primary); }

.modal.modal-editor-amplio {
    width: min(96vw, 1200px);
    max-width: 96vw;
    height: 92vh;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
}
.modal.modal-editor-amplio .modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.editor-amplio-area {
    flex: 1;
    min-height: 50vh;
    font-size: 0.95rem;
    line-height: 1.55;
    resize: none;
}

/* ─── Diff de versiones ─────────────────────────────── */
.diff-totales {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}
.diff-variacion { font-weight: 700; }
.diff-leyenda { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; font-size: 0.8rem; }
.diff-leyenda span { padding: 0.1rem 0.5rem; border-radius: 999px; }
.diff-nueva, .diff-table tr.diff-nueva td { background: #ECFDF5; }
.diff-eliminada, .diff-table tr.diff-eliminada td { background: #FEF2F2; }
.diff-table tr.diff-eliminada td { text-decoration: line-through; color: var(--text-secondary); }
.diff-modificada, .diff-table tr.diff-modificada td { background: #FFFBEB; }
[data-theme="dark"] .diff-nueva, [data-theme="dark"] .diff-table tr.diff-nueva td { background: #052E1C; }
[data-theme="dark"] .diff-eliminada, [data-theme="dark"] .diff-table tr.diff-eliminada td { background: #3B0A0A; }
[data-theme="dark"] .diff-modificada, [data-theme="dark"] .diff-table tr.diff-modificada td { background: #3A2A05; }
.diff-cambios { margin-top: 0.25rem; }

.resultado-aceptacion ul { margin: 0.25rem 0 0.75rem 1.25rem; }
.avisos-lista {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: var(--warning-50);
    color: var(--warning);
    font-size: 0.85rem;
}
.avisos-lista ul { margin: 0.25rem 0 0 1rem; }

/* ─── Ficha de proyecto ─────────────────────────────── */
.proyecto-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.proyecto-header h3 { margin: 0.5rem 0 0.25rem; }
.proyecto-header p { margin: 0 0 0.25rem; }
.proyecto-header-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.proyecto-resumen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}
.proyecto-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.proyecto-card .card-header h4 { margin: 0; display: flex; align-items: center; gap: 0.35rem; }
.resumen-importe { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.resumen-cobros {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.resumen-cobros > div,
.resumen-cobros .card-body { display: flex; flex-direction: column; }
.resumen-cobros strong { font-size: 1.15rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item {
    position: relative;
    display: flex;
    gap: 0.75rem;
    padding: 0 0 0.9rem 0;
}
.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 0.85rem;
    top: 1.8rem;
    bottom: 0;
    width: 1px;
    background: var(--border);
}
.timeline-icon {
    flex: 0 0 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-primary-medium);
    color: var(--primary-dark);
}
.timeline-item.error .timeline-icon { background: var(--danger-50); color: var(--danger); }
.timeline-content { font-size: 0.9rem; padding-top: 0.2rem; }

/* ─── Carpeta de documentos ─────────────────────────── */
.carpeta-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}
.carpeta-contador {
    margin-left: auto;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.carpeta-contador.warning { color: var(--warning); font-weight: 600; }
.carpeta-table td { vertical-align: top; }
.carpeta-origen { margin-bottom: 0.75rem; }
.tipo-badge.cat-carta_inicio { background: #EDE9FE; color: #6D28D9; }
.tipo-badge.cat-pagos { background: #ECFDF5; color: #047857; }
.tipo-badge.cat-prl { background: #FEF3C7; color: #B45309; }
.tipo-badge.cat-presupuesto_aceptado,
.tipo-badge.cat-presupuesto_devuelto { background: #E0F2FE; color: #0369A1; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }

/* ─── Plazos de pago ────────────────────────────────── */
.plazos-header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; align-items: center; }
.plazos-header h4 { margin: 0; }
.plazos-table input.form-input,
.plazos-table select.form-select { min-width: 0; }
.plazos-table tr.plazo-cobrado td { background: var(--success-50); }
.plazos-table tr.plazo-vencido td { background: var(--danger-50); }
.plazo-acciones { white-space: nowrap; }
.plazo-acciones .btn { margin-right: 0.25rem; }

/* ─── Compositor de email ───────────────────────────── */
.modal.modal-composer { width: min(96vw, 820px); max-width: 96vw; }
.composer-row {
    display: grid;
    grid-template-columns: 4.5rem 1fr;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.6rem;
}
.composer-label { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }
.chips-input {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
    min-height: 2.4rem;
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
    cursor: text;
}
.chips-input:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 2px var(--glass-primary-medium); }
.chips-input .chips-list { display: contents; }
.chips-input input {
    flex: 1;
    min-width: 12rem;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    padding: 0.2rem;
}
.chips-input input.input-error { color: var(--danger); }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.25rem 0.1rem 0.55rem;
    border-radius: 999px;
    background: var(--glass-primary-medium);
    color: var(--primary-dark);
    font-size: 0.82rem;
}
.chip-remove {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.25rem;
}
.composer-adjuntos { display: flex; flex-direction: column; gap: 0.35rem; }
.composer-adjunto { display: flex; gap: 0.4rem; align-items: center; cursor: pointer; font-size: 0.9rem; }
.composer-adjunto.disabled { color: var(--text-disabled); cursor: not-allowed; }
.composer-otros { margin-top: 0.5rem; }
.composer-otros summary { cursor: pointer; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.composer-error {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius);
    background: var(--danger-50);
    color: var(--danger);
}
.composer-error > div { flex: 1; }

.email-preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.email-preview-head {
    padding: 0.75rem 1rem;
    background: var(--bg-subtle);
    font-size: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.email-preview-body { padding: 1rem; font-family: Arial, Helvetica, sans-serif; }
.email-preview-body p { margin: 0 0 0.75rem; }
.email-preview-adjuntos { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); }

/* ─── Obra: sincronización ──────────────────────────── */
.sync-badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--success-50);
    color: var(--success);
}
.sync-badge.revisar { background: var(--warning-50); color: var(--warning); }
.sync-badge.eliminada { background: var(--bg-muted); color: var(--text-muted); }
tr.partida-eliminada td { color: var(--text-disabled); }
tr.partida-eliminada td.texto-preformateado { text-decoration: line-through; }
tr.partida-revisar td { background: var(--warning-50); }
.partidas-obra-acciones { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.partidas-obra-acciones .filter-select { margin-left: auto; }

/* ─── Configuración ─────────────────────────────────── */
.config-tabs { flex-wrap: wrap; overflow-x: auto; }
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.config-span-2 { grid-column: 1 / -1; }
.logo-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 90px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: #fff;
}
.logo-preview img { max-height: 80px; max-width: 100%; }
.color-input { display: flex; gap: 0.35rem; align-items: center; }
.color-input input[type="color"] { width: 2.4rem; height: 2.2rem; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: none; }
.color-input input[type="text"] { font-family: monospace; }
.branding-muestra {
    --muestra-primario: #2E7D32;
    --muestra-acento: #1B5E20;
    margin: 0.5rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
    color: #212121;
}
.muestra-cabecera {
    padding: 0.5rem 0.75rem;
    border-left: 4px solid var(--muestra-primario);
    color: var(--muestra-primario);
    font-weight: 700;
    background: #f5f5f5;
}
.muestra-cabecera span { font-weight: 400; font-size: 0.8rem; color: var(--muestra-acento); margin-left: 0.4rem; }
.muestra-total {
    padding: 0.5rem 0.75rem;
    text-align: right;
    font-weight: 700;
    color: #fff;
    background: var(--muestra-primario);
}
.variables-ayuda {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-subtle);
}
.variables-ayuda summary { cursor: pointer; font-weight: 600; }
.variables-lista { margin-top: 0.5rem; line-height: 1.9; }
.variables-lista code { padding: 0 0.3rem; border-radius: var(--radius-sm); background: var(--bg-muted); }

.importar-entidades {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.importar-card h4 { margin: 0 0 0.25rem; }
.modal.modal-importacion { width: min(96vw, 1100px); max-width: 96vw; }
.importacion-resumen {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    margin-bottom: 0.75rem;
}
.importacion-tabla { max-height: 55vh; overflow: auto; }
.valores-nuevos {
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.75rem;
    border-radius: var(--radius);
    background: var(--warning-50);
    font-size: 0.875rem;
}
.checkbox-label.inline { display: inline-flex; margin-right: 0.75rem; }
tr.linea-error td { background: var(--danger-50); }
tr.linea-revisar td { background: var(--warning-50); }

/* ─── Estados de carga ──────────────────────────────── */
.btn.is-loading { opacity: 0.8; cursor: progress; }
.btn-spinner {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -0.12rem;
    animation: btn-spin 0.7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ─── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    .proyecto-header-side,
    .editor-acciones { align-items: flex-start; }
    .proyecto-tabs,
    .config-tabs { overflow-x: auto; flex-wrap: nowrap; }
    .proyecto-tabs .tab,
    .config-tabs .tab { white-space: nowrap; padding: 0.6rem 0.9rem; }
    .composer-row { grid-template-columns: 1fr; gap: 0.2rem; }
    .chips-input input { min-width: 8rem; }
    .carpeta-contador { margin-left: 0; width: 100%; }
    .partidas-obra-acciones .filter-select { margin-left: 0; }
    .modal.modal-editor-amplio { height: 100vh; max-height: 100vh; width: 100vw; max-width: 100vw; border-radius: 0; }
    .plazos-table { min-width: 860px; }
    .partidas-editor { min-width: 900px; }
}

/* Editor de presupuesto a ancho completo */
.modal.modal-presupuesto-editor { width: min(96vw, 1280px); max-width: 96vw; }
.partidas-editor th:nth-child(3), .partidas-editor td:nth-child(3) { min-width: 320px; }
.partidas-editor .tipo-linea-select { min-width: 110px; }
