/* ============================================================
   budget.css — Módulo Presupuestos de Paciente
   Toca y Avanza v2
   ============================================================ */

/* ── Lista de presupuestos ──────────────────────────────────── */

#budget-section .budget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-2);
}

#budget-section .budget-header h4 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

#budget-section .budget-empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-base);
}

/* ── Tabla de presupuestos ──────────────────────────────────── */

#budget-section .budget-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

#budget-section .budget-table th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: var(--fw-semibold);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-2);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

#budget-section .budget-table td {
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

#budget-section .budget-table tr:last-child td {
  border-bottom: none;
}

#budget-section .budget-table tr:hover td {
  background: #fafafa;
}

/* ── Badges de estado ───────────────────────────────────────── */

.badge-status {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 9999px;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}

.badge-status-borrador  { background: #f3f4f6; color: var(--text-muted); }
.badge-status-enviado   { background: #dbeafe; color: #1d4ed8; }
.badge-status-aceptado  { background: #dcfce7; color: #15803d; }
.badge-status-rechazado { background: var(--danger-subtle); color: #dc2626; }

/* ── Badges de tipo ─────────────────────────────────────────── */

.badge-type {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 9999px;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}

.badge-type-valoracion  { background: var(--primary-subtle); color: var(--primary); }
.badge-type-tratamiento { background: var(--success-subtle); color: #15803d; }

/* ── Acciones inline ────────────────────────────────────────── */

#budget-section .budget-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

#budget-section .budget-actions .btn-xs {
  padding: 3px var(--space-2);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}

#budget-section .budget-actions .btn-xs-pdf {
  background: var(--primary-subtle);
  color: var(--primary);
  border-color: #c4b5fd;
}
#budget-section .budget-actions .btn-xs-pdf:hover { background: #ddd6fe; }

#budget-section .budget-actions .btn-xs-edit {
  background: var(--info-subtle);
  color: #0369a1;
  border-color: #bae6fd;
}
#budget-section .budget-actions .btn-xs-edit:hover { background: #e0f2fe; }

#budget-section .budget-actions .btn-xs-del {
  background: var(--danger-subtle);
  color: #dc2626;
  border-color: #fecaca;
}
#budget-section .budget-actions .btn-xs-del:hover { background: var(--danger-subtle); filter: brightness(0.96); }

#budget-section .budget-actions .status-select {
  font-size: var(--text-xs);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  color: var(--text);
}

/* ── Modal de presupuesto ───────────────────────────────────── */

#budget-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
}

#budget-modal {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 760px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 0;
  animation: budgetModalIn 0.18s ease;
}

@keyframes budgetModalIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

#budget-modal .bm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--border);
}

#budget-modal .bm-header h3 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--fw-bold);
  color: var(--text);
}

#budget-modal .bm-body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

#budget-modal .bm-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

#budget-modal .bm-row.single {
  grid-template-columns: 1fr;
}

#budget-modal .form-group label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#budget-modal .form-group input,
#budget-modal .form-group select,
#budget-modal .form-group textarea {
  width: 100%;
  padding: var(--space-2) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text);
  background: #fff;
  box-sizing: border-box;
  font-family: inherit;
}

#budget-modal .form-group textarea {
  resize: vertical;
  min-height: 72px;
}

#budget-modal .form-group input:focus,
#budget-modal .form-group select:focus,
#budget-modal .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(109,101,173,0.15);
}

/* ── Secciones colapsables del modal ────────────────────────── */

.bm-collapsible {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.bm-collapsible .bm-collapse-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  cursor: default;
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

.bm-collapsible .bm-collapse-header input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.bm-collapsible .bm-collapse-body {
  padding: var(--space-3);
  display: none;
}

.bm-collapsible .bm-collapse-body.open {
  display: block;
}

/* ── Tabla de líneas de precio ──────────────────────────────── */

.budget-lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.budget-lines-table th {
  background: var(--bg);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 6px var(--space-2);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.budget-lines-table td {
  padding: 5px var(--space-1);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.budget-lines-table td input,
.budget-lines-table td select {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text);
  background: #fff;
  box-sizing: border-box;
  font-family: inherit;
}

.budget-lines-table td input:focus,
.budget-lines-table td select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Columnas base (siempre visibles) */
.budget-lines-table .col-label  { min-width: 120px; }
.budget-lines-table .col-price  { width: 70px; }
.budget-lines-table .col-type   { width: 70px; }
.budget-lines-table .col-del    { width: 30px; text-align: center; }

/* Columnas solo para tratamiento — ocultas por defecto */
.budget-lines-table .col-esp,
.budget-lines-table th.col-esp,
.budget-lines-table .col-ses,
.budget-lines-table th.col-ses { display: none; }

/* Mostrar columnas tratamiento cuando la tabla tiene la clase blt--tratamiento */
.budget-lines-table.blt--tratamiento .col-esp,
.budget-lines-table.blt--tratamiento th.col-esp { display: table-cell; width: 105px; }
.budget-lines-table.blt--tratamiento .col-ses,
.budget-lines-table.blt--tratamiento th.col-ses { display: table-cell; width: 55px; }

.budget-lines-table .btn-del-line {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-base);
  padding: 2px var(--space-1);
  color: #dc2626;
  border-radius: var(--radius-sm);
}
.budget-lines-table .btn-del-line:hover { background: var(--danger-subtle); }

.budget-lines-table input[type="checkbox"] {
  width: 15px !important;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── Footer del modal ───────────────────────────────────────── */

#budget-modal .bm-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
}

/* ── Bloques de Opción (Opción A, B, C…) ─────────────────────
   Cada presupuesto puede ofrecer N combinaciones de servicios
   mutuamente excluyentes. Cada combinación es un .bm-option con
   su título, su marca "Recomendada", sus líneas y un subtotal
   calculado en vivo en JS. */

#bm-options-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.bm-option {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Una opción marcada como recomendada — borde y leve halo morado.
   :has() es soportado en navegadores modernos (Chrome 105+, Safari 15.4+, Firefox 121+). */
.bm-option:has(.bm-option-rec-cb:checked) {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(109, 101, 173, 0.10);
}

.bm-option-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.bm-option-letter {
  flex-shrink: 0;
  display: inline-block;
  padding: 3px var(--space-2);
  background: var(--primary-subtle);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.bm-option:has(.bm-option-rec-cb:checked) .bm-option-letter {
  background: var(--primary);
  color: #fff;
}

.bm-option-title {
  flex: 1;
  padding: 5px var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text);
  background: #fff;
  box-sizing: border-box;
  font-family: inherit;
  min-width: 0; /* permite flex shrink dentro del header */
}

.bm-option-title:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(109, 101, 173, 0.15);
}

.bm-option-rec {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.bm-option-rec input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}

.bm-option:has(.bm-option-rec-cb:checked) .bm-option-rec {
  color: var(--primary);
}

.bm-option-del {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-base);
  padding: 4px 6px;
  color: #dc2626;
  border-radius: var(--radius-sm);
  line-height: 1;
}

.bm-option-del:hover {
  background: var(--danger-subtle);
}

/* La tabla de líneas dentro de una opción comparte estilos con .budget-lines-table.
   Solo ajustamos el padding lateral para que respire dentro del bloque. */
.bm-option .budget-lines-table {
  margin: 0;
}

.bm-option .budget-lines-table th,
.bm-option .budget-lines-table td {
  padding-left: var(--space-3);
}

.bm-option .budget-lines-table th:last-child,
.bm-option .budget-lines-table td:last-child {
  padding-right: var(--space-3);
}

.bm-option-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: #fafbfc;
  border-top: 1px solid var(--border);
}

.bm-option-subtotal {
  font-size: var(--text-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.bm-option-subtotal strong {
  color: var(--primary);
  font-weight: var(--fw-bold);
  font-size: var(--text-base);
}

.bm-option:has(.bm-option-rec-cb:checked) .bm-option-footer {
  background: var(--primary-subtle);
}

.bm-add-option {
  margin-top: var(--space-2);
  width: 100%;
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.bm-add-option:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-subtle);
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 540px) {
  #budget-modal .bm-row {
    grid-template-columns: 1fr;
  }

  #budget-section .budget-table th:nth-child(4),
  #budget-section .budget-table td:nth-child(4) {
    display: none;
  }

  /* En móvil, el header de la opción pasa a 2 líneas para no apretarse */
  .bm-option-header {
    flex-wrap: wrap;
  }
  .bm-option-title {
    flex-basis: 100%;
    order: 3;
  }
}
