/* Portfolio rebalancing calculator. Page-only styles; shared look comes from ../style.css.
   Classes are prefixed rb- so they never clash with shared layout classes. */

/* Holding colours: one fixed order, validated for colour-blind separation on both surfaces. */
.rb {
  --c1: #b07d1a; --c2: #3f5f8a; --c3: #bd3c1c; --c4: #1f4732;
  --c5: #6e4a6b; --c6: #6d7a2c; --c7: #a35a4a; --c8: #7a5a32;
  --now: rgba(111, 106, 94, 0.42);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .rb {
    --c1: #c9a159; --c2: #8ea2c0; --c3: #d4735b; --c4: #94c4a1;
    --c5: #b897b5; --c6: #b3c06d; --c7: #d99a88; --c8: #c7a275;
    --now: rgba(168, 161, 147, 0.42);
  }
}
:root[data-theme="dark"] .rb {
  --c1: #c9a159; --c2: #8ea2c0; --c3: #d4735b; --c4: #94c4a1;
  --c5: #b897b5; --c6: #b3c06d; --c7: #d99a88; --c8: #c7a275;
  --now: rgba(168, 161, 147, 0.42);
}

/* Head and workspace: graph on the left, inputs on the right; stacked on phones. */
.rb-head { padding-block: 26px 6px; }
.rb-head h1 { font-size: var(--step-3); margin-top: 6px; }
.rb-work { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px 40px; align-items: start; padding-top: 18px; }
.rb-stage { position: sticky; top: 12px; display: grid; min-width: 0; }

.rb-answer { display: grid; gap: 6px; justify-items: start; }
.rb-answer .label { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.rb-headline { font-family: var(--font-display); font-weight: 500; font-size: clamp(1.45rem, 1.05rem + 1.4vw, 2.05rem); line-height: 1.18; letter-spacing: -0.015em; max-width: 30ch; text-wrap: balance; }
.rb-headline b { font-weight: 600; font-variant-numeric: lining-nums tabular-nums; white-space: nowrap; }
.rb-headline .buy { color: var(--gold); }
.rb-headline .sell { color: var(--rust); }
.rb-subline { color: var(--muted); font-size: 0.93rem; max-width: 60ch; }
.rb-subline strong { color: var(--ink); font-weight: 600; }

/* Row chart */
.rb-fig { margin: 0; padding-top: 18px; }
.rb-chart { position: relative; width: 100%; min-height: 120px; }
.rb-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.rb-chart text { font-family: var(--font-body); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.rb-chart .ax { fill: var(--muted); }
.rb-chart .gridline { stroke: var(--grid); stroke-width: 1; }
.rb-chart .baseline { stroke: var(--ink); stroke-width: 1; }
.rb-chart .name { fill: var(--ink); font-size: 13.5px; font-weight: 600; }
.rb-chart .sub { fill: var(--muted); font-size: 11.5px; }
.rb-chart .sub tspan.hi { fill: var(--ink); font-weight: 600; }
.rb-chart .b-now { fill: var(--now); }
.rb-chart .b-buy { fill: var(--gold-area); }
.rb-chart .b-sell { fill: url(#rb-hatch); stroke: var(--rust); stroke-width: 1.2; }
.rb-chart .hatch-line { stroke: var(--rust); stroke-width: 1.4; }
.rb-chart .t-mark { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.rb-chart .b-short { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.rb-chart .t-cap { fill: var(--ink); }
.rb-chart .trade { font-size: 13.5px; font-weight: 700; fill: var(--ink); }
.rb-chart .trade-word { font-weight: 700; }
.rb-chart .trade-word.buy { fill: var(--gold); }
.rb-chart .trade-word.sell { fill: var(--rust); }
.rb-chart .trade.none { fill: var(--muted); font-weight: 600; font-size: 12.5px; }
.rb-chart .chip { stroke: none; }
.rb-chart .row-hit { fill: transparent; cursor: default; }
.rb-chart .row { transition: opacity 0.12s; }
.rb-chart .row.is-dim { opacity: 0.35; }
.rb-chart .row-bg { fill: var(--surface-2); opacity: 0; transition: opacity 0.12s; }
.rb-chart .row.is-hot .row-bg { opacity: 0.6; }

.rb-legend { display: flex; flex-wrap: wrap; gap: 4px 18px; padding-top: 10px; font-size: 0.84rem; color: var(--muted); }
.rb-legend span { display: inline-flex; align-items: center; gap: 7px; }
.k { display: inline-block; width: 14px; height: 10px; border-radius: 2px; }
.k-now { background: var(--now); }
.k-buy { background: var(--gold-area); }
.k-sell { border: 1.2px solid var(--rust); background: repeating-linear-gradient(135deg, var(--rust) 0 1.4px, transparent 1.4px 4px); }
.k-short { border: 1px dashed var(--muted); }
.k-target { width: 2px; height: 14px; border-radius: 1px; background: var(--ink); }

/* Stats */
.rb-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 22px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); }
.rb-stat { padding: 12px 14px 14px 0; display: grid; gap: 2px; align-content: start; min-width: 0; }
.rb-stat + .rb-stat { padding-left: 14px; border-left: 1px solid var(--line); }
.rb-stat .label { font-size: 0.76rem; font-weight: 600; color: var(--muted); }
.rb-stat .v { font-family: var(--font-display); font-weight: 500; font-size: 1.45rem; font-variant-numeric: lining-nums tabular-nums; overflow-wrap: anywhere; line-height: 1.2; }
.rb-stat .v.good { color: var(--gold); }
.rb-stat .v small { display: block; font-family: var(--font-body); font-size: 0.78rem; color: var(--muted); font-weight: 400; line-height: 1.35; margin-top: 2px; }

/* Inputs panel */
.rb-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 16px; display: grid; gap: 4px; min-width: 0; }
.rb-panel-head { display: grid; gap: 10px; padding-bottom: 12px; }
.rb-panel-head h2 { font-size: 1.45rem; }
.rb-panel-head .btn-row { flex-wrap: nowrap; }
.rb-panel-head .inline-field { flex: 1; min-width: 0; }
.rb-panel-head .inline-field select { width: 100%; }
.rb-form { display: grid; border-top: 1px solid var(--ink); }
.rb-group { border: 0; margin: 0; padding: 14px 0; display: grid; gap: 10px; min-width: 0; }
.rb-group + .rb-group { border-top: 1px solid var(--line); }
.rb-group legend { float: left; width: 100%; padding: 0; font-family: var(--font-display); font-size: 1.05rem; }
.rb-group legend + * { clear: both; }
.rb-hold-head, .rb-hold { display: grid; grid-template-columns: 10px minmax(0, 1fr) minmax(0, 6.6rem) 4.1rem 22px; gap: 6px; align-items: center; }
.rb-hold-head span { font-size: 0.74rem; font-weight: 600; color: var(--muted); }
.rb-hold-head { margin-bottom: -4px; }
.rb-holds { display: grid; gap: 8px; }
.rb-hold .dot { width: 10px; height: 10px; border-radius: 50%; }
.rb-hold .h-name { padding-inline: 9px; }
.rb-hold .money input { padding-right: 8px; }
.rb-hold .pct input { padding-right: 22px; }
.rb-hold .pct span { right: 8px; }
.rb-hold .icon-btn { width: 24px; }
.rb-hold-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.rb-tsum { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.rb-tsum b { color: var(--ink); font-weight: 600; }
.rb-tsum.is-bad b { color: var(--rust); }
.rb-tsum .linkish { margin-left: 6px; }
.rb-cash { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center; }
.rb-cash .seg { grid-template-columns: auto auto; }
.rb-cash .seg button { padding: 0 12px; }
.rb-cash input { height: 40px; }
.rb-modes .preset { flex: 1; text-align: center; }
.rb-panel .privacy { margin-top: 4px; }
.rb-hold.is-bad input { border-color: var(--rust); }

/* Mix strips */
.rb-section { padding-top: 64px; }
.rb-section h2 { margin-bottom: 10px; }
.rb-mix-msg { max-width: 70ch; margin-bottom: 18px; }
.rb-strips { display: grid; gap: 16px; border-top: 1px solid var(--ink); padding-top: 18px; }
.rb-strip { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); gap: 4px 14px; align-items: center; }
.rb-strip .s-name { font-weight: 600; font-size: 0.9rem; }
.rb-strip.is-target .s-name { color: var(--muted); }
.rb-bar { display: flex; gap: 2px; height: 30px; }
.rb-seg { height: 100%; min-width: 0; background: var(--c); transition: opacity 0.12s, flex-basis 0.25s; position: relative; }
.rb-seg:first-child { border-radius: 4px 0 0 4px; }
.rb-seg:last-child { border-radius: 0 4px 4px 0; }
.rb-seg:only-child { border-radius: var(--radius); }
.rb-strip.is-target .rb-seg { background: transparent; border: 1.5px solid var(--c); background-image: repeating-linear-gradient(135deg, var(--c) 0 1px, transparent 1px 6px); }
.rb-labels { grid-column: 2; position: relative; height: 16px; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rb-labels span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.rb-strips.has-hot .rb-seg:not(.is-hot) { opacity: 0.25; }
.rb-mix-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 18px; font-size: 0.86rem; }
.rb-mix-legend button { display: inline-flex; align-items: center; gap: 7px; background: none; border: 0; padding: 2px 0; color: var(--ink); cursor: default; }
.rb-mix-legend .dot, .rb-table .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* Table */
.rb-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.95rem; border-top: 1px solid var(--ink); }
.rb-table th, .rb-table td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.rb-table th:first-child, .rb-table td:first-child { text-align: left; }
.rb-table th:last-child, .rb-table td:last-child { padding-right: 0; }
.rb-table thead th { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.rb-table tbody th { font-weight: 600; white-space: normal; text-align: left; }
.rb-table .hn { display: inline-flex; align-items: center; gap: 8px; }
.rb-scroll { overflow-x: auto; }
.rb-table td.buy { color: var(--gold); font-weight: 600; }
.rb-table td.sell { color: var(--rust); font-weight: 600; }
.rb-table td.zero { color: var(--muted); }
.rb-table tfoot td, .rb-table tfoot th { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--ink); }
.rb-note { margin-top: 10px; }

/* Tooltip */
.rb-tip { position: absolute; min-width: 190px; }
.rb-tip .t-row b { font-weight: 600; }

@media (min-width: 900px) {
  .rb .section.prose { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); column-gap: 48px; row-gap: 0; align-items: start; max-width: none; }
  .rb .section.prose > h2 { grid-column: 1; grid-row: 1 / span 30; }
  .rb .section.prose > :not(h2) { grid-column: 2; margin-bottom: 16px; }
  .rb .disclaimer { max-width: none; }
}
@media (max-width: 1200px) and (min-width: 961px) { .rb-work { grid-template-columns: minmax(0, 1fr) 350px; gap: 28px; } }
@media (max-width: 960px) {
  .rb-work { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .rb-stage { display: contents; }
  .rb-answer { order: 1; }
  .rb-fig { order: 2; }
  .rb-panel { order: 3; margin-top: 20px; }
  .rb-stats { order: 4; margin-top: 28px; }
}
@media (max-width: 640px) {
  .rb-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rb-stat:nth-child(3) { border-left: 0; padding-left: 0; }
  .rb-stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 600px) {
  .rb-head { padding-block: 16px 0; }
  .rb-head h1 { font-size: 1.55rem; }
  .rb-head .eyebrow { display: none; }
  .rb-work { padding-top: 12px; }
  .rb-answer .label { display: none; }
  .rb-headline { font-size: 1.3rem; }
  .rb-subline { font-size: 0.85rem; }
  .rb-fig { padding-top: 8px; }
  .rb-panel { padding: 14px 14px 14px; margin-inline: -4px; }
  .rb-hold-head, .rb-hold { grid-template-columns: 8px minmax(0, 1fr) minmax(0, 6.4rem) 4.3rem 22px; gap: 5px; }
  .rb-hold .dot { width: 8px; height: 8px; }
  .rb-strip { grid-template-columns: minmax(0, 1fr); }
  .rb-labels { grid-column: 1; }
  .rb-table { font-size: 0.85rem; }
  .rb-table .wide { display: none; }
  .rb-table th, .rb-table td { padding-right: 8px; }
}

/* Drift chart: each holding's distance from target, now and after */
.rb-drift { position: relative; width: 100%; margin-top: 4px; }
.rb-drift svg { display: block; width: 100%; height: auto; overflow: visible; }
.rb-drift text { font-family: var(--font-body); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.rb-drift .ax { fill: var(--muted); }
.rb-drift .ax-side { fill: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.rb-drift .gridline { stroke: var(--grid); }
.rb-drift .zero { stroke: var(--ink); stroke-width: 1.5; }
.rb-drift .band { fill: var(--gold-soft); opacity: 0.55; }
.rb-drift .name { fill: var(--ink); font-size: 13.5px; font-weight: 600; }
.rb-drift .val { fill: var(--muted); }
.rb-drift .val tspan.hi { fill: var(--ink); font-weight: 600; }
.rb-drift .move { stroke: var(--gold); stroke-width: 2; fill: none; }
.rb-drift .move.sell { stroke: var(--rust); }
.rb-drift .move.same { stroke: var(--muted); stroke-dasharray: 3 3; }
.rb-drift .d-now { fill: var(--paper); stroke: var(--ink); stroke-width: 1.6; }
.rb-drift .d-after { fill: var(--gold); stroke: var(--paper); stroke-width: 2; }
.rb-drift .d-after.sell { fill: var(--rust); }
.rb-drift .d-after.same { fill: var(--ink); }
.rb-drift .row { transition: opacity 0.12s; }
.rb-drift .row.is-dim { opacity: 0.35; }
.rb-drift-legend { display: flex; flex-wrap: wrap; gap: 4px 18px; padding-top: 10px; font-size: 0.84rem; color: var(--muted); }
.rb-drift-legend span { display: inline-flex; align-items: center; gap: 7px; }
.k-dnow { width: 10px; height: 10px; border-radius: 50%; border: 1.6px solid var(--ink); background: var(--paper); }
.k-dafter { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); }
.k-band { width: 14px; height: 10px; background: var(--gold-soft); }

/* Keep the currency picker readable: it used to shrink to an empty box next to Example, Share and Clear.
   The buttons wrap onto a second line when they don't fit beside it. */
.rb-panel-head .btn-row { flex-wrap: wrap; row-gap: 6px; }
.rb-panel-head .inline-field { flex: 1 1 8rem; min-width: 8rem; }
