/* ===== Portfolio Builder Page ===== */

/* --- Main container --- */
.pb-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

/* Override global section padding inside builder */
.pb-content section {
  padding: 0.75rem 0;
}

/* --- Intro text --- */
.pb-intro {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 0.5rem;
}

/* --- Year selector --- */
.pb-years {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.pb-year-btn {
  padding: 5px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.pb-year-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.pb-year-btn.pb-year-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

[data-theme="dark"] .pb-year-btn.pb-year-active {
  color: #0D1117;
}

/* --- Period label --- */
.pb-period {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* --- Sliders container --- */
.pb-sliders {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* --- Single slider row --- */
.pb-slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.pb-slider-label {
  width: 120px;
  flex-shrink: 0;
  font-weight: 500;
  font-size: 0.88rem;
  color: var(--text);
  letter-spacing: 0.01em;
}

.pb-slider-etf {
  display: block;
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.7;
  margin-top: 0.05rem;
}

/* --- Overlap group badges --- */
:root {
  --pb-group1: #4A90D9;
  --pb-group2: #5BA05B;
  --pb-group3: #D4892A;
}

.pb-group-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  width: 13px;
  height: 13px;
  text-align: center;
  line-height: 13px;
  border-radius: 50%;
  color: #fff;
  margin-left: 4px;
  vertical-align: super;
  cursor: help;
}

.pb-group-1 { background: var(--pb-group1); }
.pb-group-2 { background: var(--pb-group2); }
.pb-group-3 { background: var(--pb-group3); }

/* --- Overlap legend below sliders --- */
.pb-group-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  margin-top: 0.6rem;
  padding: 0.5rem 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.pb-group-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.pb-group-legend .pb-group-badge {
  font-size: 0.55rem;
  width: 11px;
  height: 11px;
  line-height: 11px;
  vertical-align: baseline;
  position: relative;
  top: -1px;
}

/* --- Range slider base --- */
.pb-slider {
  flex: 1;
  min-width: 0;
  height: 6px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  touch-action: pan-y;
  padding: 10px 0;
  margin: -10px 0;
}

/* --- Range slider: WebKit --- */
.pb-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
}

.pb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 12px;
  border-radius: 3px;
  background: var(--accent);
  border: none;
  margin-top: -3px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}

.pb-slider:hover::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--accent-light);
}

/* --- Range slider: Firefox --- */
.pb-slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  border: none;
}

.pb-slider::-moz-range-thumb {
  width: 20px;
  height: 12px;
  border-radius: 3px;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.pb-slider:hover::-moz-range-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--accent-light);
}

/* --- Disabled slider (BTC at 10 years) --- */
.pb-slider:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pb-slider-input:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Slider value input --- */
.pb-slider-value {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.pb-slider-input {
  width: 46px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: right;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--transition);
  -moz-appearance: textfield;
}

.pb-slider-input::-webkit-outer-spin-button,
.pb-slider-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pb-slider-input:focus {
  outline: none;
  border-color: var(--accent);
}

.pb-pct {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* --- Weight sum row --- */
.pb-sum-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0 0.25rem;
  font-size: 1rem;
}

.pb-sum-label {
  font-weight: 500;
  color: var(--text-muted);
}

.pb-sum-value {
  font-weight: 700;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

/* --- Warning text --- */
.pb-sum-warning {
  text-align: center;
  font-size: 0.78rem;
  color: var(--red);
  margin-bottom: 0.5rem;
}

/* --- BTC warning --- */
.pb-btc-warning {
  text-align: center;
  font-size: 0.78rem;
  color: var(--regime-herbst, #b59410);
  margin-top: 0.5rem;
}

/* --- RobustScore UI --- */

.pb-score-intro {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

/* Placeholder (grayed-out teaser bar) */
.pb-score-placeholder {
  margin-bottom: 0.5rem;
}

.pb-score-muted {
  opacity: 0.4;
}

.pb-score-bar.pb-score-bar-disabled {
  background: linear-gradient(to right, #bbb, #d5d5d5 50%, #bbb);
  opacity: 0.35;
}

/* Action row: button + rules */
.pb-score-action {
  margin-bottom: 0.25rem;
}

.pb-score-btn {
  display: inline-block;
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.pb-score-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Active result */
.pb-score-result {
  margin-bottom: 0.5rem;
}

.pb-score-label {
  font-size: 0.88rem;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.pb-score-bar {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(to right, #C0392B, #E67E22 30%, #F1C40F 50%, #82C91E 70%, #1A7A4C);
  overflow: visible;
}

.pb-score-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 20px;
  background: var(--text);
  border-radius: 2px;
  transform: translateX(-2px);
  box-shadow: 0 0 0 2px var(--bg);
}

.pb-score-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.pb-score-pct {
  font-weight: 600;
  color: var(--text);
}

/* Details: 3Y / 5Y / Max breakdown */
.pb-score-details {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.6rem;
}

.pb-score-detail {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.78rem;
}

.pb-score-detail-label {
  font-weight: 600;
  color: var(--text-muted);
}

.pb-score-detail-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.pb-score-detail-qual {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.pb-score-error {
  font-size: 0.82rem;
  color: var(--regime-herbst, #b59410);
  padding: 0.4rem 0;
}

.pb-score-rules {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* --- Metrics explanation --- */
.pb-explain {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 0.75rem;
}

.pb-tip {
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-muted);
  background: var(--bg-alt);
  border-left: 3px solid var(--green);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

/* --- Metrics cards --- */
.pb-metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.pb-metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.pb-metric-card:hover {
  border-color: rgba(30,58,95,0.2);
  box-shadow: var(--shadow);
}

[data-theme="dark"] .pb-metric-card:hover {
  border-color: rgba(107,163,214,0.2);
}

.pb-metric-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.pb-metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.pb-val-green { color: var(--green); }
.pb-val-red   { color: var(--red); }

/* --- Comparison table --- */
.pb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.pb-table th,
.pb-table td {
  padding: 0.75rem 1rem;
  text-align: left;
}

.pb-table th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.pb-table td {
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.pb-table tbody tr:last-child td {
  border-bottom: none;
}

.pb-table tbody tr {
  transition: background var(--transition);
}

.pb-table tbody tr:hover {
  background: var(--accent-light);
}

.pb-table-name {
  font-weight: 600;
}

/* --- Chart container --- */
.pb-chart-wrap {
  width: 100%;
  aspect-ratio: 2 / 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 2rem;
}

.pb-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* --- Disclaimer --- */
.pb-disclaimer {
  margin-top: 1rem;
  padding: 1.25rem 1.5rem;
  background: var(--bg-alt);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.7;
}

/* --- Section titles --- */
.pb-content .section-title {
  font-size: clamp(1.05rem, 2vw, 1.2rem);
  margin-bottom: 0.75rem;
}

/* --- Responsive: 768px --- */
@media (max-width: 768px) {
  .pb-metrics {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --- Responsive: 640px --- */
@media (max-width: 640px) {
  .pb-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Grid layout: label+value top row, slider full-width below */
  .pb-slider-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.4rem 0.5rem;
    padding: 0.6rem 0;
  }

  .pb-slider-label {
    grid-column: 1;
    grid-row: 1;
    width: auto;
  }

  .pb-slider-value {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .pb-slider {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    margin-bottom: 6px;
  }

  /* Sticky sum bar at bottom of viewport */
  .pb-sum-wrap {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    z-index: 10;
    margin: 0 -1.5rem;
    padding: 0.5rem 1.5rem;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  }

  [data-theme="dark"] .pb-sum-wrap {
    box-shadow: 0 -2px 8px rgba(0,0,0,0.3);
  }

  .pb-sum-row {
    margin: 0;
  }

  .pb-table th,
  .pb-table td {
    padding: 0.5rem 0.5rem;
    font-size: 0.78rem;
  }

  .pb-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* --- Responsive: 480px --- */
@media (max-width: 480px) {
  .pb-metrics {
    grid-template-columns: 1fr;
  }

  .pb-chart-wrap {
    aspect-ratio: 3 / 2;
    padding: 0.75rem;
  }

  /* Larger touch targets */
  .pb-slider::-webkit-slider-thumb {
    width: 24px;
    height: 14px;
    margin-top: -4px;
  }

  .pb-slider::-moz-range-thumb {
    width: 24px;
    height: 14px;
  }
}

/* --- Print-only elements (hidden on screen) --- */
.pb-print-summary,
.pb-print-footer,
.pb-print-score {
  display: none;
}

/* --- Print button --- */
.pb-print-btn {
  display: inline-block;
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.pb-print-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* --- Print styles --- */
@media print {
  /* Hide non-essential elements */
  .navbar, .hero-dashboard, footer, .footer,
  .pb-print-section, .pb-sliders, .pb-sum-wrap,
  .pb-btc-warning, .pb-years, .pb-tip, .pb-explain,
  .pb-score-intro, .pb-score-placeholder, .pb-score-result, .pb-score-action, .pb-score-section,
  .theme-toggle, .lang-dropdown,
  section:has(#pb-comparison) {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
    margin: 0;
    padding: 0;
  }

  /* Collapse empty sections */
  .pb-content {
    padding: 0;
    max-width: 100%;
  }

  .pb-content section {
    padding: 0.25rem 0;
    margin: 0;
  }

  .pb-content section:empty,
  .pb-content section:has(> .pb-tip),
  .pb-content section:has(> .pb-explain) {
    display: none !important;
  }

  main.content {
    padding: 0;
    margin: 0;
  }

  .pb-intro {
    color: #333;
    font-size: 0.8rem;
  }

  .pb-print-summary {
    display: block;
    font-size: 0.8rem;
    color: #000;
    margin-bottom: 0.25rem;
    line-height: 1.5;
  }

  /* Show period prominently */
  .pb-period {
    font-size: 0.85rem;
    font-weight: 600;
    color: #000;
    margin-bottom: 0.25rem;
  }

  /* Show allocation as text list */
  .pb-content::after {
    display: none;
  }

  /* Metrics cards — auto-sized, not stretchy */
  .pb-metrics {
    display: grid;
    grid-template-columns: repeat(5, auto);
    gap: 0.35rem;
    margin-top: 0.5rem;
    width: fit-content;
  }

  /* Ensure chart section is visible */
  section:has(.pb-chart-wrap) {
    display: block !important;
  }

  .pb-chart-wrap,
  .pb-chart-wrap canvas {
    display: block !important;
    visibility: visible !important;
  }

  .pb-metric-card {
    border: 1px solid #ccc;
    padding: 0.3rem 0.4rem;
  }

  .pb-metric-label {
    font-size: 0.5rem;
    margin-bottom: 0.05rem;
    white-space: nowrap;
  }

  .pb-metric-value {
    font-size: 0.7rem;
  }

  .pb-metric-value { color: #000; }
  .pb-val-green { color: #1A7A4C; }
  .pb-val-red { color: #C0392B; }

  /* Chart — smaller, keep original proportions */
  .pb-chart-wrap {
    border: 1px solid #ccc;
    break-inside: avoid;
    padding: 0.5rem;
    margin-bottom: 0;
    max-width: 58%;
  }

  /* Table */
  .pb-table { border: 1px solid #ccc; }
  .pb-table th { background: #f5f5f5; }
  .pb-table tbody tr:hover { background: none; }

  /* Section titles */
  .pb-content .section-title {
    color: #000;
    break-after: avoid;
  }

  /* Print score (only if activated) */
  .pb-print-score {
    display: none;
  }
  .pb-print-score.pb-print-score-active {
    display: block;
    max-width: 58%;
    padding: 0;
    margin-bottom: 1.2rem;
    break-inside: avoid;
  }
  .pb-print-score .pb-score-label {
    font-size: 0.8rem;
    color: #000;
    margin-bottom: 0.3rem;
  }
  .pb-print-score .pb-score-bar {
    display: none;
  }
  .pb-print-score .pb-score-legend {
    display: none;
  }
  .pb-print-score .pb-score-details {
    margin-top: 0.3rem;
  }
  .pb-print-score .pb-score-detail {
    font-size: 0.7rem;
  }
  .pb-print-score .pb-score-pct {
    font-size: 0.65rem;
  }

  /* Custom print footer */
  .pb-print-footer {
    display: block;
    text-align: center;
    font-size: 0.7rem;
    color: #999;
    margin-top: 0.5rem;
  }
}
