/* Bridge to Retirement - Scoped styles (v1.1.6)
   - All selectors scoped under .btr-container to avoid theme collisions
   - Compact remove buttons, responsive grid, dark-mode friendly, print-friendly
*/

.btr-container * { box-sizing: border-box; font: inherit; }

/* Container */
.btr-container {
  --btr-primary: #7c3aed;         /* purple border/buttons */
  --btr-primary-50: #f5f3ff;
  --btr-primary-200: #ddd6fe;
  --btr-success: #065f46;
  --btr-withdraw: #b45309;
  --btr-pot: #1e40af;
  --btr-border: #e5e7eb;
  --btr-input: #cbd5e1;
  --btr-bg: #ffffff;
  --btr-panel: #fafafa;
  color: #111827;
  background: var(--btr-bg);
  max-width: 1100px;
  margin: 24px auto;
  padding: 20px;
  border: 2px solid var(--btr-primary);
  border-radius: 16px;
}

/* Panels */
.btr-container .btr-panel {
  margin: 16px 0;
  padding: 16px;
  border: 1px solid var(--btr-border);
  border-radius: 12px;
  background: var(--btr-panel);
}
.btr-container h3 {
  margin: 0 0 10px;
  font-weight: 800;
  font-size: 1.05rem;
}
.btr-container .btr-help {
  margin-bottom: 8px;
  font-size: .9rem;
  color: #374151;
}

/* Grid */
.btr-container .btr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

/* Inputs */
.btr-container .btr-input label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: #111827;
}
.btr-container .btr-input input,
.btr-container .btr-input select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--btr-input);
  border-radius: 8px;
  background: #fff;
  color: #111827;
}

/* Inline controls (for +/- state pension age) */
.btr-container .btr-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Download CSV – front and centre */
.btr-container .btr-csv-cta {
  margin-top: 24px;
  padding: 28px 24px;
  border-top: 3px solid #2563eb;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.08) 0%, rgba(37, 99, 235, 0.02) 100%);
  border-radius: 16px;
  text-align: center;
}
.btr-container .btr-btn--csv-primary {
  background: #2563eb;
  border: 3px solid #2563eb;
  color: #fff;
  padding: 18px 36px;
  font-size: 18px;
  font-weight: 800;
  min-height: 56px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}
.btr-container .btr-btn--csv-primary:hover {
  background: #1e40af;
  border-color: #1e40af;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4);
}

/* Buttons */
.btr-container .btr-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.btr-container .btr-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--btr-primary);
  background: var(--btr-primary);
  color: #fff;
  cursor: pointer;
}
.btr-container .btr-btn.secondary {
  background: #fff;
  color: var(--btr-primary);
}
.btr-container .btr-btn.remove {
  background: #ef4444;
  border-color: #ef4444;
}
.btr-container .btr-btn.btr-btn--sm {
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.1;
  border-radius: 8px;
}

/* Tables */
.btr-container .btr-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 10px;
  background: #fff;
  border: 1px solid var(--btr-border);
  border-radius: 10px;
  overflow: hidden;
}
.btr-container .btr-table th,
.btr-container .btr-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--btr-border);
  text-align: right;
  white-space: nowrap;
}
.btr-container .btr-table th:first-child,
.btr-container .btr-table td:first-child {
  text-align: left;
}
.btr-container .btr-table thead th {
  background: var(--btr-primary-50);
  color: #111827;
  font-weight: 800;
}
.btr-container .btr-totals-row td {
  font-weight: 800;
  background: var(--btr-primary-50);
}
.btr-container .btr-col-withdrawals { color: var(--btr-withdraw); }
.btr-container .btr-col-cash { color: var(--btr-success); }
.btr-container .btr-col-pot { color: var(--btr-pot); }

/* Badges */
.btr-container .btr-badges { margin-top: 10px; }
.btr-container .btr-badge {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid var(--btr-primary);
  border-radius: 999px;
  background: var(--btr-primary-50);
  color: #111827;
}
.btr-container .btr-badge.is-note {
  background: #e0e7ff;
  border-color: #93c5fd;
}

/* Highlight failing year row */
.btr-container tr[style*="background: #fee2e2"],
.btr-container .btr-row-fail {
  background: #fee2e2 !important;
}

/* Dark mode (opt-in via prefers-color-scheme) */
@media (prefers-color-scheme: dark) {
  .btr-container {
    --btr-bg: #0b0f16;
    --btr-panel: #0f1622;
    --btr-border: #1f2937;
    --btr-input: #334155;
    color: #e5e7eb;
    border-color: #8b5cf6;
  }
  .btr-container .btr-table { background: #0f1622; }
  .btr-container .btr-table thead th { background: #1f2540; color: #e5e7eb; }
  .btr-container .btr-totals-row td { background: #1f2540; }
  .btr-container .btr-badge { background: #1f2540; color: #e5e7eb; border-color: #8b5cf6; }
  .btr-container .btr-input input,
  .btr-container .btr-input select { background: #0b0f16; color: #e5e7eb; }
  .btr-container .btr-btn.secondary { background: transparent; color: #c4b5fd; border-color: #8b5cf6; }
}

/* Print (clean tables, hide panels chrome) */
@media print {
  .btr-container {
    border: none; padding: 0; margin: 0;
    max-width: 100%;
  }
  .btr-container .btr-panel { border: none; background: transparent; padding: 0; margin: 0 0 12px; }
  .btr-container .btr-buttons { display: none !important; }
  .btr-container .btr-help { display: none !important; }
  .btr-container .btr-badge { border: 1px solid #000; background: #fff; color: #000; }
  .btr-container .btr-table { border: 1px solid #000; }
  .btr-container .btr-table th,
  .btr-container .btr-table td { border-bottom: 1px solid #000; color: #000; }
}

/* --- Button sizing + row alignment fixes --- */
.btr-container .btr-row-actions {
  display: flex;
  justify-content: flex-end;
  align-items: end;
}

.btr-container .btr-btn {      /* base consistency */
  font-size: 14px;
  line-height: 1.2;
  padding: 8px 12px;
}

.btr-container .btr-btn--compact {  /* use same compact across Assets & Income */
  font-size: 13px;
  line-height: 1.15;
  padding: 6px 10px;
  border-radius: 8px;
}

/* Make sure remove buttons never stretch weirdly */
.btr-container .btr-btn.remove {
  white-space: nowrap;
}

/* Prevent any overlap with the Cash Savings row */
.btr-container .btr-pots {
  margin-top: 6px;
}

/* Grid: keep inputs aligned, even with long labels */
.btr-container .btr-input label {
  min-height: 1.2em;             /* consistent single-line height */
}
.btr-container .btr-input.btr-nowrap label {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* On wider screens, ensure the action cell (remove) hugs the right edge cleanly */
@media (min-width: 980px) {
  .btr-container .btr-grid {
    align-items: end;             /* inputs & buttons bottom-aligned in a row */
  }
}

/* Bridge to Retirement – colour overrides */

/* Tokens */
.btr-container {
  --btr-border: #083141;   /* calculator border */
  --btr-add:    #59747C;   /* "Add" buttons */
  --btr-thead:  #EBF2F4;   /* table headings */
}

/* Calculator/card border */
.btr-container {
  border: 2px solid var(--btr-border);
}

/* Add buttons */
.btr-btn.add {
  background: var(--btr-add);
  color: #fff;
  border-color: var(--btr-add);
}
.btr-btn.add:hover,
.btr-btn.add:focus {
  filter: brightness(0.95);
}

/* Table headings */
.btr-table thead th {
  background: var(--btr-thead);
  color: #083141; /* readable on the light heading */
  border-bottom: 1px solid #d9e4e8;
}

/* Optional: badges & notes can echo the border tone slightly */
.btr-badge.is-note {
  background: #EBF2F4;
  border-color: #a9c0c7;
  color: #083141;
}
/* --- Mobile responsiveness for Bridge to Retirement --- */

/* Allow the result badges to wrap on small screens */
.btr-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
}
.btr-badge {
  white-space: normal;         /* let long text wrap */
  max-width: 100%;
  line-height: 1.25;
}

/* Horizontal scrolling table wrapper for phones */
.btr-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px -8px 0;         /* slight edge-to-edge feel on mobile */
  padding: 0 8px;
}
.btr-table {
  min-width: 720px;           /* triggers scroll on narrow screens */
}

/* Slightly tighter table cell padding on mobile */
@media (max-width: 640px) {
  .btr-table th,
  .btr-table td {
    padding: 8px 10px;
    font-size: 14px;
  }
}

/* Inputs stack cleanly on mobile */
@media (max-width: 640px) {
  .btr-grid {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .btr-input label {
    font-size: 14px;
  }

  .btr-btn {
    padding: 8px 10px;
    font-size: 14px;
  }

  .btr-row-actions {
    justify-content: flex-start;
  }
}

/* Make the “note” badge (Opening balances) stretch full width on small screens */
@media (max-width: 640px) {
  .btr-badge.is-note {
    width: 100%;
  }
}
