/* Portfolio history chart. */

.history-panel {
  position: relative;
  min-width: 0;
  padding: 1.35rem 1.5rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}
/* Same top light as the hero: the two panels read as one family. */
.history-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  pointer-events: none;
}
.history-panel[hidden] { display: none; }
.history-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.history-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.history-value {
  margin: 0.3rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3.5vw, 2.1rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
  line-height: 1.15;
}
.history-reading { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; margin: 0.35rem 0 0; color: var(--muted); font-size: 0.76rem; }
/* The period's change as a quiet pill; the sign carries the direction. */
.history-reading #history-change {
  padding: 0.08rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.72rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.history-reading #history-change:empty { display: none; }
.history-reading #history-change.gain { background: var(--gain-bg); }
.history-reading #history-change.loss { background: var(--loss-bg); }
.history-plot-wrap { position: relative; min-width: 0; margin-top: 0.55rem; }
.history-plot { display: block; width: 100%; height: auto; min-height: 10rem; overflow: visible; touch-action: pan-y; outline: none; }
.history-plot:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
.history-load-panel { position: relative; z-index: 2; margin: 0.35rem 0; }
.history-load-heading { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.history-load-status {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  color: var(--text);
  font-size: 0.72rem;
}
.history-load-status:empty { display: none; }
.history-load-info-button {
  flex: 0 0 auto;
  width: 1.35rem;
  height: 1.35rem;
  min-width: 1.35rem;
  min-height: 1.35rem;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}
.history-load-info-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.history-load-info-button[hidden] { display: none; }
.history-load-details {
  margin-top: 0.4rem;
  padding: 0.6rem 0.75rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.7rem;
}
.history-load-details[hidden] { display: none; }
.history-load-summary { margin: 0; white-space: pre-line; line-height: 1.5; }
.history-load-progress { display: block; width: 100%; height: 0.35rem; margin-top: 0.4rem; accent-color: var(--accent); }
.history-load-progress[hidden] { display: none; }
.history-load-duration { margin: 0.3rem 0 0; font-variant-numeric: tabular-nums; }
.history-grid { stroke: rgba(255, 255, 255, 0.045); stroke-width: 1; vector-effect: non-scaling-stroke; }
.history-axis-label { fill: var(--muted-2); font: 500 10.5px var(--font-ui); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.history-line { fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.history-line.is-positive { stroke: var(--green); }
.history-line.is-negative { stroke: var(--red); }
/* Area under the line: the line's color fading out toward the axis. */
.history-area { stroke: none; pointer-events: none; }
.history-area-stop-top { stop-opacity: 0.26; }
.history-area-stop-bottom { stop-opacity: 0; }
.history-area-fill.is-positive stop { stop-color: var(--green); }
.history-area-fill.is-negative stop { stop-color: var(--red); }
.history-end-dot { stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; }
.history-end-dot.is-positive { fill: var(--green); }
.history-end-dot.is-negative { fill: var(--red); }
.history-end-halo { opacity: 0.18; }
.history-end-halo.is-positive { fill: var(--green); }
.history-end-halo.is-negative { fill: var(--red); }
.history-single-point { fill: var(--bg); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.history-crosshair { stroke: rgba(255, 255, 255, 0.3); stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.history-marker { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.history-marker.is-positive { stroke: var(--green); }
.history-marker.is-negative { stroke: var(--red); }
.history-empty { min-height: 1.2em; margin: -0.6rem 0 0.35rem; color: var(--muted); font-size: 0.78rem; text-align: center; }
.history-navigator-wrap { position: relative; margin: 0.1rem 0 0.8rem; }
.history-navigator { display: block; width: 100%; height: 2.4rem; overflow: visible; border-radius: 8px; }
.history-navigator-line { fill: none; stroke: var(--muted); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.history-navigator-area { fill: rgba(255, 255, 255, 0.05); stroke: none; }
.history-navigator-shade { fill: var(--surface); opacity: 0.62; }
.history-navigator-point { fill: var(--accent); }
.history-navigator-selection { fill: rgba(255, 255, 255, 0.05); stroke: rgba(255, 255, 255, 0.16); stroke-width: 1; vector-effect: non-scaling-stroke; }
.history-navigator-handle { stroke: rgba(255, 255, 255, 0.5); stroke-width: 1; vector-effect: non-scaling-stroke; }
.history-range-track { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.history-range-thumb {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 24px;
  min-width: 10px;
  min-height: 24px;
  max-width: 10px;
  max-height: 24px;
  margin: 0;
  padding: 0;
  line-height: 1;
  font-size: 0;
  appearance: none;
  background: var(--accent);
  border: 3px solid var(--surface);
  outline: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  touch-action: none;
  cursor: ew-resize;
  transition: transform 0.15s var(--ease);
}
.history-range-thumb:active { transform: translate(-50%, -50%); }
.history-range-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.history-range-thumb:disabled { cursor: default; opacity: 0.55; }
.history-range-start { z-index: 2; }
.history-range-end { z-index: 1; }
.history-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.65rem; }
.history-periods {
  display: flex;
  max-width: 100%;
  gap: 0.1rem;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.history-periods::-webkit-scrollbar { display: none; }
.history-periods button {
  flex: 0 0 auto;
  min-height: 1.9rem;
  padding: 0.25rem 0.75rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
}
.history-periods button:hover { color: var(--text); background: transparent; border-color: transparent; }
.history-periods button.is-active,
.history-periods button[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.history-periods button:focus-visible,
.history-custom-picker > summary:focus-visible,
.history-custom input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.history-custom-picker { position: relative; z-index: 3; }
.history-custom-picker > summary {
  display: inline-flex;
  min-height: 2.35rem;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.history-custom-picker > summary::-webkit-details-marker { display: none; }
.history-custom-picker > summary::marker { content: ""; }
.history-custom-picker > summary:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }
.history-custom-picker > summary svg { width: 0.9rem; height: 0.9rem; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.history-custom-picker > summary .history-custom-chevron { width: 0.6rem; height: 0.4rem; margin-left: 0.2rem; transition: transform 0.16s ease; }
.history-custom-picker[open] > summary .history-custom-chevron { transform: rotate(180deg); }
.history-custom {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  width: min(20rem, calc(100vw - 2rem));
  margin: 0;
  /* Scrollbar inset (same technique as dialog, see dialogs.css): the
     transparent border keeps a scrollbar inside the rounded corners. */
  padding: calc(0.45rem - 5px) calc(0.65rem - 4px) calc(0.65rem - 5px);
  background: var(--surface-2);
  border: solid transparent;
  border-width: 5px 4px;
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--border), 0 12px 32px rgba(0,0,0,0.38);
  overflow: auto;
}
.history-custom-picker.opens-up .history-custom { top: auto; bottom: calc(100% + 0.45rem); }
/* Beside the periods (right end of the row) the popover would spill past
   the viewport: positionDatePicker anchors it to the button's right edge. */
.history-custom-picker.aligns-end .history-custom { left: auto; right: 0; }
.history-custom legend { padding: 0 0.25rem; color: var(--muted); font-size: 0.66rem; }
.history-custom label { display: grid; gap: 0.55rem; min-width: 0; color: var(--muted); font-size: 0.65rem; }
.history-custom input { width: 100%; min-width: 0; min-height: 2.3rem; padding: 0.3rem 0.4rem; color: var(--text); background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px; color-scheme: dark; }
.history-note { min-height: 1em; margin: 0.5rem 0 0; color: var(--muted); font-size: 0.68rem; }
.history-retry { margin-top: 0.5rem; padding: 0.35rem 0.55rem; color: var(--text); border-color: var(--border-strong); }
.history-retry[hidden] { display: none; }
/* Wide screens: the period selector rides up beside the reading, top
   right of the panel, like a chart toolbar. Narrower screens keep it
   under the plot, where a thumb reaches it. */
@media (min-width: 1180px) {
  .history-head { min-height: 4.6rem; padding-right: 33rem; }
  .history-controls {
    position: absolute;
    top: 1.35rem;
    right: 1.5rem;
    z-index: 3;
    flex-wrap: nowrap;
    justify-content: flex-end;
  }
  .history-navigator-wrap { margin-bottom: 0.4rem; }
}

/* ————— Key figures as the chart's footer —————
   Value, Unrealized, Realized and Return close the history panel: one
   surface, the figures in a tray under a hairline. #overview stays its own
   section (it shows alone when the chart is hidden); these rules only join
   the two while both are on screen. */
#networth-history:not([hidden]):has(+ #overview:not([hidden])) {
  border-bottom: none;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  padding-bottom: 0.35rem;
}
#networth-history:not([hidden]) + #overview:not([hidden]) { margin-top: -1.25rem; }
#networth-history:not([hidden]) + #overview .cards {
  position: relative;
  border-top: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  background: var(--surface);
}
#networth-history:not([hidden]) + #overview .cards::before {
  content: "";
  position: absolute;
  top: 0;
  left: 1.5rem;
  right: 1.5rem;
  height: 1px;
  background: var(--border);
}
#overview .card {
  gap: 0.35rem;
  padding: 1.05rem 1.5rem 1.15rem;
  border-left: none;
  /* Inset dividers: short hairlines between the figures, not full-height
     rules, so the tray reads as one calm row. */
  background: linear-gradient(var(--border), var(--border)) left center / 1px 46% no-repeat;
}
#overview .card:first-child { background: none; }
#overview .card-label { color: var(--muted-2); font-size: 0.64rem; letter-spacing: 0.14em; }
#overview .card-value { font-size: 1.22rem; }

@media (max-width: 720px) {
  #networth-history:not([hidden]) + #overview:not([hidden]) { margin-top: -1.1rem; }
  #networth-history:not([hidden]) + #overview .cards::before { left: 0.75rem; right: 0.75rem; }
  /* 2 × 2 on phones: a short divider between the columns, a hairline
     between the rows (inset like the tray's top line). */
  #overview .card { padding: 0.8rem 0.85rem 0.85rem; }
  #overview .card:nth-child(n + 3) { border-top: none; }
  #overview .card:nth-child(3) {
    background: linear-gradient(var(--border), var(--border)) left 0.85rem top 0 / calc(100% - 0.85rem) 1px no-repeat;
  }
  #overview .card:nth-child(4) {
    background:
      linear-gradient(var(--border), var(--border)) left 0 top 0 / calc(100% - 0.85rem) 1px no-repeat,
      linear-gradient(var(--border), var(--border)) left center / 1px 46% no-repeat;
  }
  #overview .card-value { font-size: 1.05rem; }
}

@media (max-width: 560px) {
  .history-panel { padding: 0.9rem 0.75rem 0.7rem; }
  .history-kicker { white-space: nowrap; }
  .history-plot { min-height: 8.5rem; }
  .history-axis-label { font-size: 10px; }
  .history-custom-picker { max-width: 100%; }
  .history-periods { gap: 0.12rem; justify-content: space-between; }
  .history-periods button { min-height: 2.15rem; padding: 0.3rem 0.38rem; font-size: 0.68rem; }
}


/* Multi-source transfer editor */
.src-row { display:block; min-width:0; padding:10px; margin:8px 0; border:1px solid var(--line,#333); border-radius:10px; background:var(--panel,transparent); }
.src-grid {
  display:grid;
  grid-template-columns:minmax(0,1fr) minmax(0,1fr);
  grid-template-rows:auto auto auto auto;
  gap:10px;
  align-items:end;
  min-width:0;
}
.src-grid > label:first-child { grid-column:1 / -1; grid-row:1; }
.src-grid > label:nth-child(2) { grid-column:1; grid-row:2; }
.src-grid > label:nth-child(3) { grid-column:1 / -1; grid-row:3; }
.src-grid label {
  display:grid;
  gap:10px;
  min-width:0;
  margin:0;
  font-size:.82rem;
  line-height:1.2;
}
.src-grid input:not([type="checkbox"]),.src-grid select {
  width:100%;
  min-width:0;
  height:2.5rem;
  min-height:2.5rem;
  margin:0;
}
.src-actions {
  grid-column:2;
  grid-row:2;
  display:flex;
  align-self:end;
  align-items:stretch;
  gap:8px;
  min-width:0;
  margin:0;
}
.src-actions button {
  display:flex;
  align-items:center;
  justify-content:center;
  flex:1 1 0;
  width:auto;
  min-width:0;
  min-height:2.5rem;
  height:2.5rem;
  margin:0;
  padding:.55rem .7rem;
  font-size:.9rem;
  font-weight:500;
  line-height:1.2;
  white-space:nowrap;
}
.src-actions .src-max {
  background:var(--accent-soft);
  border-color:transparent;
  color:var(--text);
  font-weight:500;
}
.src-actions .src-max:hover {
  background:var(--accent-soft);
  border-color:transparent;
  color:var(--text);
}
.src-actions .src-remove {
  background:var(--red-bg);
  border-color:transparent;
  color:var(--red);
}
.src-actions button[hidden] { display:none; }
.src-actions .src-remove:hover {
  background:var(--red-bg);
  border-color:transparent;
  color:var(--red);
}
.src-auto-wrap {
  display:flex!important;
  grid-column:1/-1;
  grid-row:4;
  align-items:center;
  gap:7px!important;
  margin:.25rem 0 0!important;
}
.src-auto-wrap input { width:auto; min-height:0; height:auto; }
#t-source-add,#t-source-split { margin:6px 8px 0 0; }
@media (max-width:700px) {
  .src-actions button { padding:.55rem .55rem; }
}
@media (max-width:720px) {
  .src-grid input:not([type="checkbox"]),.src-grid select { height:3rem; min-height:3rem; }
  .src-actions button { min-height:3rem; height:3rem; }
}
