:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-hover: #4338ca;
  --green: #059669;
  --green-soft: #ecfdf5;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app { max-width: 1200px; margin: 0 auto; padding: 20px 24px 48px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  border-radius: 14px;
  font-size: 24px;
}
.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.8rem; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.status-pill.ok { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.status-pill.err { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

.user-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}

.auth-gate {
  display: flex;
  justify-content: center;
  padding: 48px 16px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 28px 24px;
}
.auth-card h2 { font-size: 1.2rem; margin-bottom: 6px; }
.auth-card .hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 20px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .field { display: flex; flex-direction: column; gap: 6px; }
.auth-form .field span { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.9rem;
}
.auth-switch { text-align: center; font-size: 0.85rem; color: var(--muted); margin-top: 16px; }
.auth-switch a { color: var(--accent); font-weight: 600; text-decoration: none; }
.auth-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  font-size: 0.85rem;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  width: 100%;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.tab {
  flex: 1;
  padding: 14px 16px;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--surface); }

.tab-panel { padding: 24px 28px 28px; }
.tab-panel[hidden] { display: none; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px 20px;
  margin-bottom: 20px;
}
.field.span-2 { grid-column: 1 / -1; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

input, select {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
input:disabled, select:disabled { opacity: 0.6; cursor: not-allowed; }

.periods-block {
  margin: 20px 0;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.periods-block:first-of-type { border-top: none; padding-top: 0; }
.periods-block h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}
.period-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px 16px;
}
@media (max-width: 480px) {
  .field-grid { grid-template-columns: 1fr; }
  .period-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   FORMULA BUILDER — fórmula modular con componentes arrastrables
   ============================================================ */
.formula-builder { margin-top: 4px; max-width: 100%; overflow-x: auto; }

.formula-track {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  min-width: 0;
  box-sizing: border-box;
}

.formula-slot {
  flex: 0 0 140px;
  display: flex;
  flex-direction: column;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  background: var(--surface2);
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
  box-sizing: border-box;
}
.formula-slot.drag-over { border-color: var(--accent); background: var(--accent-soft); }

.formula-slot-head { padding: 8px 10px 4px; }
.formula-slot-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}
.formula-slot-hint { display: block; font-size: 0.65rem; color: var(--muted); margin-top: 1px; }

.formula-slot-drop {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 8px 8px;
  min-height: 56px;
}

.formula-step {
  flex: 0 0 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  position: relative;
}
.formula-step::before {
  content: "→";
  position: absolute;
  top: -16px;
  font-size: 0.9rem;
  color: var(--border);
}
.formula-step small { font-weight: 500; font-size: 0.62rem; margin-top: 2px; }

.formula-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: box-shadow 0.15s, opacity 0.15s, border-color 0.15s;
}
.formula-chip:active { cursor: grabbing; }
.formula-chip.dragging { opacity: 0.4; }
.formula-chip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.formula-chip-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.formula-chip-drag { color: var(--muted); font-size: 0.85rem; line-height: 1; }
.formula-chip-name { font-size: 0.72rem; font-weight: 600; color: var(--text); }

.formula-chip-value { display: flex; align-items: center; gap: 6px; }
.formula-chip-value input {
  width: 100%;
  padding: 5px 6px;
  font-size: 0.8rem;
}
.formula-chip-value .unit { font-size: 0.65rem; color: var(--muted); white-space: nowrap; }

@media (max-width: 700px) {
  .formula-slot { flex: 0 0 110px; }
  .formula-step { flex: 0 0 40px; font-size: 0.55rem; }
}
#manual-advanced-formula-content .periods-block {
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
#manual-advanced-formula-content .formula-builder {
  max-width: 100%;
  box-sizing: border-box;
}
#manual-advanced-formula-content .formula-track {
  max-width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface2); }
.btn-block { width: 100%; margin-top: 8px; }

.table-wrap { margin: 16px 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.table-head { padding: 12px 14px; background: var(--surface2); border-bottom: 1px solid var(--border); }
.table-head h3 { font-size: 0.85rem; }
.hint { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.product-select { max-width: 460px; margin-bottom: 12px; }
.product-variant {
  margin: -4px 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent, #4f7cff) 12%, transparent);
  color: var(--fg, inherit);
  border: 1px solid color-mix(in srgb, var(--accent, #4f7cff) 30%, transparent);
}

.close-legs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.close-leg {
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2, #f4f4f5);
  color: var(--text, #18181b);
}
.table-scroll { max-height: 280px; overflow: auto; }

.data-table, .invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.data-table th, .data-table td,
.invoice-table th, .invoice-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th, .invoice-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface2);
  position: sticky;
  top: 0;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--accent-soft); }
.data-table tbody tr.selected { background: #ddd6fe; }
.data-table td.num, .invoice-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-table.compact { font-size: 0.78rem; }

.invoice-panel { min-height: 0; }

.results-heading {
  padding: 16px 28px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.results-heading h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}
.results-heading p {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.empty-state {
  padding: 48px 32px 56px;
  text-align: center;
  color: var(--muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.6; }
.empty-state h2 { color: var(--text); font-size: 1.2rem; margin-bottom: 8px; }
.empty-state p { max-width: 520px; margin: 0 auto; font-size: 0.9rem; line-height: 1.55; }

.invoice { padding: 0; }

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 20px 24px;
  padding: 28px 28px 20px;
  background: linear-gradient(135deg, #312e81 0%, #4f46e5 55%, #6366f1 100%);
  color: #fff;
}
.invoice-type {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  margin-bottom: 4px;
}
.invoice-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.invoice-meta { font-size: 0.85rem; opacity: 0.9; margin-top: 6px; }

.invoice-total-box {
  text-align: right;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
  padding: 16px 20px;
  border-radius: 12px;
  min-width: 160px;
}
.invoice-total-box .label { display: block; font-size: 0.7rem; text-transform: uppercase; opacity: 0.8; }
.invoice-total-box .amount { display: block; font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.invoice-total-box .sub { font-size: 0.8rem; opacity: 0.85; }

.invoice-body {
  padding: 24px 28px;
  overflow-x: auto;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 8px;
}

.info-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.info-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.info-label { display: block; font-size: 0.65rem; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.info-value { display: block; font-size: 0.9rem; font-weight: 600; margin-top: 4px; }
.mono { font-family: var(--mono); font-size: 0.8rem; }

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 24px 0 12px;
}
.section-title:first-of-type { margin-top: 0; }

.chart-row {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.total-row td { background: var(--accent-soft); border-top: 2px solid var(--accent); }

.invoice-footer {
  display: flex;
  gap: 10px;
  padding: 16px 28px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  color: #fff;
  font-weight: 600;
}
.overlay[hidden] { display: none; }

/* Modal de gestión de cuentas (admin) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 110;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 1.15rem; }
.admin-users { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.admin-user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
}
.admin-user-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.admin-user-info strong { font-size: 0.9rem; }
.admin-user-info .hint { font-size: 0.78rem; color: var(--muted); }

.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 101;
  max-width: 90vw;
}
.toast[hidden] { display: none; }
.toast.err { background: #991b1b; }

/* ============================================================
   PRINT INVOICE — oculto en pantalla, visible solo al imprimir
   ============================================================ */
#invoice-print { display: none; }

@media print {
  @page { size: A4 portrait; margin: 12mm 14mm 18mm 14mm; }
  * { box-sizing: border-box; }
  body { background: #fff; margin: 0; }
  .app, .overlay, .toast { display: none !important; }
  #invoice-print {
    display: block !important;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8.5pt;
    color: #111;
    line-height: 1.45;
  }

  /* ---- Cabecera ---- */
  .fp-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 4mm;
    border-bottom: 2pt solid #1a3a5c;
    margin-bottom: 3.5mm;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .fp-logo { font-size: 13pt; font-weight: 700; color: #1a3a5c; }
  .fp-issuer-sub { font-size: 7.5pt; color: #555; margin-top: 1px; }
  .fp-title-block { text-align: right; }
  .fp-doc-type {
    font-size: 11pt; font-weight: 700; color: #1a3a5c;
    letter-spacing: 0.04em; margin-bottom: 3px;
  }
  .fp-meta { font-size: 7.5pt; border-collapse: collapse; margin-left: auto; }
  .fp-meta th { text-align: right; padding-right: 5px; color: #555; font-weight: 600; white-space: nowrap; }
  .fp-meta td { text-align: left; font-weight: 500; }

  /* ---- Datos suministro ---- */
  .fp-supply-section {
    background: #edf2f7;
    border: 1px solid #c8d4e0;
    padding: 2.5mm 3.5mm;
    margin-bottom: 3.5mm;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .fp-supply-row { display: flex; gap: 6mm; margin-bottom: 2mm; }
  .fp-supply-row:last-child { margin-bottom: 0; }
  .fp-supply-field { flex: 1; min-width: 0; }
  .fp-supply-field > span {
    display: block; font-size: 6pt; text-transform: uppercase;
    letter-spacing: 0.05em; color: #555; margin-bottom: 1px;
  }
  .fp-supply-field > strong {
    display: block; font-size: 8.5pt;
    font-family: "Courier New", monospace; color: #1a3a5c;
  }

  /* ---- Bloques ---- */
  .fp-block { margin-bottom: 3.5mm; break-inside: avoid; }
  .fp-block-title {
    font-size: 6.5pt; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.07em; color: #fff; background: #1a3a5c;
    padding: 1.5mm 2.5mm; margin: 0;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  /* ---- Tablas ---- */
  .fp-table { width: 100%; border-collapse: collapse; font-size: 8pt; }
  .fp-table th {
    background: #e2e8f0; padding: 1.2mm 2mm;
    text-align: left; font-size: 7pt; font-weight: 700;
    border-bottom: 1px solid #b0bed0; white-space: nowrap;
    print-color-adjust: exact; -webkit-print-color-adjust: exact;
  }
  .fp-table td { padding: 1.2mm 2mm; border-bottom: 1px solid #e5e5e5; }
  .fp-table tbody tr:nth-child(even) td {
    background: #f7f9fb;
    print-color-adjust: exact; -webkit-print-color-adjust: exact;
  }
  .fp-table tfoot td {
    border-top: 1.5px solid #1a3a5c; border-bottom: none;
    padding-top: 1.5mm; font-size: 8.5pt;
  }
  .fp-table .r { text-align: right; font-variant-numeric: tabular-nums; }

  /* ---- Tabla de cargos ---- */
  .fp-charges-table td { border-bottom: none; padding: 0.9mm 2mm; }
  .fp-charges-table tbody tr:nth-child(even) td { background: transparent; }
  .fp-charges-table tr.ch-sep td { border-top: 1px solid #bbb; }
  .fp-charges-table tr.ch-subtotal td {
    border-top: 1px solid #bbb; font-weight: 700; font-size: 8.5pt;
    color: #1a3a5c; padding-top: 1.5mm;
  }
  .fp-charges-table tr.ch-iva td { padding-top: 0.5mm; }
  .fp-charges-table tr.ch-total td {
    border-top: 2pt solid #1a3a5c; font-weight: 700; font-size: 10pt;
    background: #e8f0fb; padding-top: 1.5mm;
    print-color-adjust: exact; -webkit-print-color-adjust: exact;
  }

  /* ---- Layout inferior ---- */
  .fp-bottom-grid { display: flex; gap: 5mm; align-items: flex-start; break-inside: avoid; }
  .fp-breakdown { flex: 1.1; }
  .fp-right-col { flex: 1; display: flex; flex-direction: column; gap: 3mm; }

  /* ---- Caja total ---- */
  .fp-total-box {
    background: #1a3a5c; color: #fff;
    padding: 3.5mm 4mm; text-align: right;
    print-color-adjust: exact; -webkit-print-color-adjust: exact;
  }
  .fp-total-label { font-size: 6.5pt; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
  .fp-total-amount { font-size: 19pt; font-weight: 700; line-height: 1.2; }
  .fp-total-sub { font-size: 7pt; opacity: 0.8; margin-top: 1px; }

  /* ---- Pie ---- */
  .fp-footer {
    border-top: 1px solid #ccc; padding-top: 2.5mm; margin-top: 4mm;
    font-size: 6.5pt; color: #666; text-align: center;
  }
}
/* Peritaje de factura */
#peritaje-result { margin-top: 18px; }
.peritaje-verdict { padding: 14px 16px; border-radius: 10px; border-left: 4px solid #999; background: #f7f7f9; margin-bottom: 12px; }
.peritaje-verdict.verdict-ok { border-color: #059669; background: #ecfdf5; }
.peritaje-verdict.verdict-sobrecoste { border-color: #dc2626; background: #fef2f2; }
.peritaje-verdict.verdict-infravalorado { border-color: #d97706; background: #fffbeb; }
.peritaje-verdict.verdict-incompleto { border-color: #6b7280; background: #f3f4f6; }
.peritaje-verdict p { margin: 6px 0 0; font-size: 0.9rem; }
.peritaje-verdict .surcharge { color: #dc2626; }
tr.peritaje-ok td { color: inherit; }
tr.peritaje-warn td { background: #fef2f2; }
tr.peritaje-muted td { color: #9ca3af; }
.peritaje-comparativa { margin: 12px 0; padding: 12px 14px; border: 1px solid #e5e7eb; border-radius: 10px; background: #fbfbfd; }
.peritaje-pct { font-size: 1.9rem; font-weight: 700; line-height: 1.1; margin-bottom: 8px; color: #374151; }
.peritaje-pct.verdict-ok { color: #059669; }
.peritaje-pct.verdict-sobrecoste { color: #dc2626; }
.peritaje-pct.verdict-infravalorado { color: #d97706; }
.peritaje-pct.verdict-incompleto { color: #6b7280; }
#btn-peritaje-pdf { margin-top: 6px; }
.fixed-prices { border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px 14px; margin: 4px 0 12px; }
.fixed-prices legend { font-weight: 600; padding: 0 6px; font-size: 0.9rem; }
.fixed-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 8px; }
@media (min-width: 720px) { .fixed-grid { grid-template-columns: 1fr 1fr; } }
.fixed-head { display: block; font-size: 0.8rem; color: #616e7c; margin-bottom: 4px; }
.fixed-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.fixed-cell { display: flex; flex-direction: column; font-size: 0.7rem; }
.fixed-cell span { color: #9ca3af; text-align: center; }
.fixed-cell input { width: 100%; padding: 3px 4px; font-size: 0.75rem; }
.hint.warn { color: #b45309; }

/* Formulario unificado: toggles de fuentes de datos */
.source-toggles { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.checkbox-field { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 0.85rem; line-height: 1.35; }
.checkbox-field input[type="checkbox"] { margin-top: 2px; flex: 0 0 auto; width: 16px; height: 16px; cursor: pointer; }
.checkbox-field span { color: #374151; }

/* ===================== Peritaje de factura ===================== */
.peritaje-card {
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.peritaje-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.peritaje-kicker {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.peritaje-title { font-size: 1.2rem; font-weight: 700; margin-top: 2px; }
.peritaje-summary { font-size: 0.85rem; color: var(--muted); margin-top: 6px; max-width: 60ch; }
.peritaje-badge {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.peritaje-badge.ok { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.peritaje-badge.err { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.peritaje-badge.warn { background: #fffbeb; color: #b45309; border-color: #fde68a; }

.peritaje-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  padding: 20px 24px;
}
.peritaje-total-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface2);
}
.peritaje-total-box .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 600;
}
.peritaje-total-box .amount { display: block; font-size: 1.4rem; font-weight: 700; margin-top: 4px; }
.peritaje-total-box .amount.neg { color: #dc2626; }
.peritaje-total-box .amount.pos { color: var(--green); }
.peritaje-total-box .amount.warn { color: #b45309; }
.peritaje-total-box .sub { font-size: 0.7rem; color: var(--muted); }

.peritaje-table { margin: 0 24px 8px; width: calc(100% - 48px); }
.peritaje-table .reg-tag {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.68rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
}
.peritaje-row-diferencia { background: #fef2f2; }
.verdict-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.verdict-pill.ok { background: var(--green-soft); color: var(--green); }
.verdict-pill.err { background: #fef2f2; color: #dc2626; }
.verdict-pill.na { background: #f1f5f9; color: var(--muted); }

.peritaje-warnings {
  margin: 0 24px 16px;
  padding: 12px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
}
.peritaje-warnings p { font-size: 0.8rem; color: #92400e; }
.peritaje-warnings p + p { margin-top: 4px; }
