/* ── Crédit immobilier ─────────────────────────────────────────────────────── */

.mortgage-page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

/* Header */
.mortgage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.mortgage-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary, #2c3e50);
  margin: 0;
}

.mortgage-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Sections */
.mortgage-section {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.mortgage-section-smoothing {
  border: 2px solid #6c5ce7;
}

.mortgage-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mortgage-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 1rem 0;
}

/* Info grid (acquisition) */
.mortgage-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.mortgage-info-card {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mortgage-info-card.mortgage-info-total {
  background: #2c3e50;
  color: #fff;
}

.mortgage-info-card.mortgage-info-total .mortgage-info-label,
.mortgage-info-card.mortgage-info-total .mortgage-info-value {
  color: #fff;
}

.mortgage-info-label {
  font-size: 0.75rem;
  color: #636e72;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.mortgage-info-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2c3e50;
}

.mortgage-fee-comment {
  cursor: help;
  color: #6c5ce7;
  font-size: 0.85rem;
}

/* Loan cards */
.mortgage-loan-card {
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.mortgage-loan-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.mortgage-loan-name {
  font-size: 1rem;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 0.25rem 0;
}

.mortgage-loan-meta {
  font-size: 0.8rem;
  color: #636e72;
  display: block;
}

.mortgage-loan-smoothed {
  font-size: 0.8rem;
  color: #6c5ce7;
  font-weight: 600;
  display: block;
  margin-top: 0.25rem;
}

.mortgage-loan-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.mortgage-loan-totals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Total items */
.mortgage-total-item {
  background: #f0f4f8;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
}

.mortgage-total-item.mortgage-total-grand {
  background: #2c3e50;
}

.mortgage-total-item.mortgage-total-grand .mortgage-total-label,
.mortgage-total-item.mortgage-total-grand .mortgage-total-value {
  color: #fff;
}

.mortgage-total-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #636e72;
}

.mortgage-total-value {
  font-size: 1rem;
  font-weight: 700;
  color: #2c3e50;
}

/* Global recap */
.mortgage-global-recap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

/* Smoothing */
.mortgage-smoothing-info {
  color: #2c3e50;
  margin-bottom: 0.75rem;
}

.mortgage-smoothing-details {
  margin: 0 0 1rem 1rem;
  color: #2c3e50;
  line-height: 1.8;
}

/* Current month */
.mortgage-current-month {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mortgage-current-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  background: #f8f9fa;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.mortgage-current-loan {
  font-weight: 700;
  color: #2c3e50;
  min-width: 120px;
}

/* Empty state */
.mortgage-empty {
  color: #636e72;
  font-style: italic;
  padding: 0.5rem 0;
}

/* Avertissement tranches */
.mortgage-installment-warning {
  margin-top: 0.6rem;
  padding: 0.55rem 0.8rem;
  background: #fff3cd;
  border-left: 3px solid #e67e22;
  border-radius: 6px;
  color: #7d4e00;
  font-size: 0.85rem;
}

/* Actions */
.mortgage-actions {
  margin-top: 1rem;
}

/* ── Formulaire ────────────────────────────────────────────────────────────── */

.mortgage-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 520px;
}

.mortgage-form-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.mortgage-form-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c3e50;
}

.mortgage-form-row input,
.mortgage-form-row select,
.mortgage-form-row textarea {
  padding: 0.6rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: #2c3e50;
}

.mortgage-form-row small {
  font-size: 0.75rem;
  color: #636e72;
}

.mortgage-optional {
  font-size: 0.7rem;
  background: #dfe6e9;
  border-radius: 4px;
  padding: 1px 6px;
  font-weight: 400;
}

.mortgage-form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.mortgage-error {
  color: #d63031;
  font-size: 0.8rem;
}

/* Add fee form */
.mortgage-add-fee {
  margin-top: 1rem;
}

.mortgage-add-fee summary {
  cursor: pointer;
  display: inline-block;
  margin-bottom: 0.75rem;
}

.mortgage-form-inline {
  max-width: 400px;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  margin-top: 0.5rem;
}

/* Fees list */
.mortgage-fees-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mortgage-fee-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: #f8f9fa;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  gap: 1rem;
  flex-wrap: wrap;
}

.mortgage-fee-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mortgage-fee-name {
  font-weight: 600;
  color: #2c3e50;
}

.mortgage-fee-amount {
  font-size: 0.9rem;
  color: #2c3e50;
}

.mortgage-fee-desc {
  font-size: 0.8rem;
  color: #636e72;
}

/* ── Tableau d'amortissement ──────────────────────────────────────────────── */

.mortgage-schedule-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.mortgage-year-filters {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.mortgage-year-btn {
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  background: #f0f4f8;
  color: #2c3e50;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s;
}

.mortgage-year-btn:hover,
.mortgage-year-btn.active {
  background: #2c3e50;
  color: #fff;
}

.mortgage-pdf-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Table */
.mortgage-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.mortgage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  background: #fff;
  white-space: nowrap;
}

.mortgage-table th {
  background: #2c3e50;
  color: #fff;
  padding: 0.5rem 0.6rem;
  text-align: right;
  font-weight: 600;
  font-size: 0.75rem;
}

.mortgage-table th:first-child {
  text-align: left;
}

.mortgage-table .mortgage-subheader th {
  background: #34495e;
  font-size: 0.7rem;
  font-weight: 500;
}

.mortgage-loan-header-cell {
  text-align: center !important;
  border-left: 2px solid #1a252f;
}

.mortgage-combined-header {
  text-align: center !important;
  background: #1a252f !important;
  border-left: 2px solid #fff;
}

.mortgage-installment-header {
  text-align: center !important;
  background: #1a6b3a !important;
  color: #fff !important;
  border-left: 2px solid #fff;
  white-space: nowrap;
}

.mortgage-installment-col {
  background: #f0faf4;
  border-left: 2px solid #27ae60;
  color: #1a6b3a;
  text-align: right;
  white-space: nowrap;
}

.mortgage-table td {
  padding: 0.4rem 0.6rem;
  text-align: right;
  border-bottom: 1px solid #f0f4f8;
  color: #2c3e50;
}

.mortgage-table td:first-child {
  text-align: left;
}

.mortgage-table tr:nth-child(even) td {
  background: #f8fafc;
}

.sticky-col {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}

.mortgage-table tr:nth-child(even) .sticky-col {
  background: #f8fafc;
}

.mortgage-month-cell {
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}

.mortgage-highlight-col {
  background: #eef2ff !important;
  font-weight: 600;
}

.mortgage-na {
  text-align: center !important;
  color: #b2bec3;
}

/* Lignes de frais (dossier / garantie) */
.mortgage-fee-row td {
  background: #fdf6e3 !important;
  font-size: 0.8rem;
  border-top: none !important;
  border-bottom: 1px dashed #e0d5b0 !important;
}

.mortgage-fee-row .sticky-col {
  background: #fdf6e3 !important;
}

.mortgage-fee-label {
  color: #7c6b2e;
  font-style: italic;
  padding-left: 1.2rem !important;
}

.mortgage-fee-loan-tag {
  font-size: 0.7rem;
  background: #e0d5b0;
  color: #5a4e1e;
  border-radius: 3px;
  padding: 0 0.3rem;
  margin-left: 0.25rem;
  font-style: normal;
}

.mortgage-fee-amount-cell {
  color: #7c6b2e;
}

/* Totals footer */
.mortgage-totals-row td {
  background: #dfe6e9 !important;
  font-size: 0.78rem;
  padding: 0.5rem 0.6rem;
  border-top: 2px solid #2c3e50;
}

.mortgage-totals-row .sticky-col {
  background: #dfe6e9 !important;
}

/* Payments cell */
.mortgage-payments-cell {
  max-width: 160px;
  white-space: normal !important;
  vertical-align: middle;
}

.mortgage-payment-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  margin: 1px;
  white-space: nowrap;
}

.mortgage-payer-adrien {
  background: #d4efdf;
  color: #1e8449;
}

.mortgage-payer-flavie {
  background: #d2b4de;
  color: #6c3483;
}

.mortgage-payer-couple {
  background: #d6eaf8;
  color: #1a5276;
}

.mortgage-payment-del {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  line-height: 1;
  opacity: 0.6;
}

.mortgage-payment-del:hover {
  opacity: 1;
}

/* Pay form */
.mortgage-action-cell {
  white-space: normal !important;
  min-width: 100px;
}

.mortgage-pay-details summary {
  cursor: pointer;
  list-style: none;
}

.mortgage-pay-details summary::-webkit-details-marker {
  display: none;
}

.mortgage-pay-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem;
  background: #f8f9fa;
  border-radius: 8px;
  margin-top: 0.4rem;
  min-width: 180px;
  position: relative;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.mortgage-pay-form select,
.mortgage-pay-form input {
  padding: 0.35rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.8rem;
  min-height: 36px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  min-height: 44px;
}

.btn:hover { opacity: 0.85; }

.btn-primary { background: #2c3e50; color: #fff; }
.btn-secondary { background: #f0f4f8; color: #2c3e50; border: 1px solid #ddd; }
.btn-danger { background: #d63031; color: #fff; }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  min-height: 36px;
}

.btn-xs {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  min-height: 30px;
  border-radius: 6px;
}

/* ── Mensualités prévisionnelles ─────────────────────────────────────────── */

.mortgage-installments {
  margin-top: 1rem;
  border-top: 1px solid #eee;
  padding-top: 0.75rem;
}

.mortgage-installments > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.mortgage-installments > summary::-webkit-details-marker { display: none; }

.mortgage-installments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-radius: 6px;
}
.mortgage-installments[open] .mortgage-installments-header {
  margin-bottom: 0.75rem;
}

.mortgage-installments-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.mortgage-installments-title::before {
  content: "▶";
  font-size: 0.6rem;
  color: #888;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.mortgage-installments[open] .mortgage-installments-title::before {
  transform: rotate(90deg);
}

.mortgage-installments-count {
  font-size: 0.75rem;
  font-weight: 400;
  color: #888;
}

.mortgage-installments-badge-warn {
  font-size: 0.85rem;
}

.mortgage-installments-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.mortgage-installments-table th {
  text-align: left;
  font-weight: 600;
  color: #636e72;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #eee;
}

.mortgage-installments-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid #f4f4f4;
  vertical-align: middle;
}

.mortgage-installments-table tr:last-child td {
  border-bottom: none;
}

.mortgage-installment-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  .mortgage-installments-table thead {
    display: none;
  }
  .mortgage-installments-table,
  .mortgage-installments-table tbody,
  .mortgage-installments-table tr,
  .mortgage-installments-table td {
    display: block;
    width: 100%;
  }
  .mortgage-installments-table tr {
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    padding: 0.4rem 0.6rem;
  }
  .mortgage-installments-table td {
    border: none;
    padding: 0.2rem 0;
    text-align: left;
  }
  .mortgage-installments-table td[data-label]::before {
    content: attr(data-label) " ";
    font-weight: 600;
    color: #636e72;
    font-size: 0.75rem;
  }
  .mortgage-installment-actions {
    margin-top: 0.4rem;
  }
}

.mortgage-na {
  color: #b2bec3;
}

.mortgage-computed {
  font-size: 0.72rem;
  color: #74b9ff;
  font-weight: 400;
}

.mortgage-section-subtitle {
  font-size: 0.85rem;
  color: #636e72;
  margin: 0 0 1rem 0;
}

.mortgage-error-block {
  background: #fff5f5;
  border: 1px solid #fab8b8;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: #d63031;
  font-size: 0.85rem;
}

.mortgage-fieldset {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mortgage-fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: #636e72;
  padding: 0 0.4rem;
}

.mortgage-installment-hint {
  font-size: 0.78rem;
  color: #636e72;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  line-height: 1.6;
  margin: 0;
}

.mortgage-form-period {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.mortgage-form-period-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.mortgage-form-period-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c3e50;
}

.mortgage-period-selects {
  display: flex;
  gap: 0.5rem;
}

.mortgage-period-selects select {
  padding: 0.6rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: #2c3e50;
}

.mortgage-period-arrow {
  font-size: 1.2rem;
  color: #636e72;
  padding-bottom: 0.6rem;
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .mortgage-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .mortgage-info-grid {
    grid-template-columns: 1fr 1fr;
  }

  .mortgage-loan-header {
    flex-direction: column;
  }

  .mortgage-loan-totals {
    grid-template-columns: 1fr 1fr;
  }

  .mortgage-global-recap {
    grid-template-columns: 1fr 1fr;
  }

  .mortgage-schedule-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .mortgage-table {
    font-size: 0.72rem;
  }

  .mortgage-table th,
  .mortgage-table td {
    padding: 0.3rem 0.4rem;
  }

  .mortgage-form {
    max-width: 100%;
  }
}

/* ── Apports & Quotités ──────────────────────────────────────────────────── */

.mortgage-contrib-form-wrap > summary {
  cursor: pointer;
  list-style: none;
}
.mortgage-contrib-form-wrap > summary::-webkit-details-marker { display: none; }

.mortgage-contrib-forms {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
}

.mortgage-contrib-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.8rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e8ecf0;
}

.mortgage-contrib-name {
  font-weight: 600;
  min-width: 80px;
  font-size: 0.9rem;
}

.mortgage-contrib-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.75rem;
  color: #636e72;
}

.mortgage-contrib-input {
  border: 1.5px solid #ddd;
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
  width: 110px;
}

/* Tableau récapitulatif */
.mortgage-contrib-recap {
  margin-top: 1rem;
}

.mortgage-contrib-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.mortgage-contrib-table th {
  padding: 0.4rem 0.6rem;
  text-align: left;
  color: #636e72;
  font-weight: 600;
  border-bottom: 2px solid #eee;
}

.mortgage-contrib-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid #f0f4f8;
}

.mortgage-contrib-table .text-right {
  text-align: right;
}

.mortgage-contrib-total-row td {
  border-top: 2px solid #2c3e50;
  border-bottom: 2px solid #2c3e50;
  background: #f0f4f8;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.mortgage-contrib-apport-row td {
  color: #27ae60;
}

.mortgage-contrib-net-row td {
  background: #eaf4fb;
  border-top: 1px solid #aed6f1;
  font-size: 0.95rem;
}

.mortgage-contrib-subtitle {
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 1rem 0 0.5rem;
}

.mortgage-contrib-reste {
  color: #c0392b;
}

.mortgage-contrib-ok {
  color: #27ae60;
}

.mortgage-contrib-done {
  background: #f0faf4;
}

@media (max-width: 600px) {
  .mortgage-contrib-table thead { display: none; }
  .mortgage-contrib-table,
  .mortgage-contrib-table tbody,
  .mortgage-contrib-table tr,
  .mortgage-contrib-table td { display: block; width: 100%; }
  .mortgage-contrib-table tr {
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.75rem;
  }
  .mortgage-contrib-table td {
    border: none;
    padding: 0.15rem 0;
    text-align: left !important;
  }
  .mortgage-contrib-table td[data-label]::before {
    content: attr(data-label) " : ";
    font-weight: 600;
    color: #636e72;
    font-size: 0.75rem;
  }
  .mortgage-contrib-form {
    flex-direction: column;
    align-items: flex-start;
  }
  .mortgage-contrib-input { width: 100%; }
}

