/* ── Shared form inputs (benchmark + holdings table) ─────────── */

.holdings-table input,
.holdings-table select {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12.5px;
  min-width: 5rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}

.holdings-table input[type="date"] { text-align: left; }
.holdings-table input[type="date"]::-webkit-date-and-time-value { text-align: left; }

.holdings-table select option { background-color: var(--input-bg); color: var(--ink); }
.holdings-table input::placeholder { color: var(--placeholder); }

/* ── Holdings table ───────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.holdings-table thead tr {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.holdings-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  text-align: left;
  padding: 8px 8px;
  font-weight: 500;
  border-bottom: 1px solid var(--panel-border);
  z-index: 1;
}

.holdings-table tbody td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--row-line);
}

/* ── Holding row inputs: plain text by default, editable on click ── */

.holdings-table tbody tr.holding-row td:not(.holding-row__actions):hover input:not(:focus),
.holdings-table tbody tr.holding-row td:not(.holding-row__actions):hover select:not(:focus) {
  border-color: var(--panel-border);
  background: var(--input-bg);
}

.holdings-table tbody tr.holding-row td input:focus,
.holdings-table tbody tr.holding-row td select:focus {
  border-color: var(--wood);
  background: var(--input-bg);
  outline: none;
}

/* ── Pledge toggle button (inside holding row) ─────────────────── */

.holding-row__actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.pledge-toggle {
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
  font-family: var(--font-sans);
  border: 1px solid var(--panel-border);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.pledge-toggle:hover { border-color: var(--wood); }

.pledge-toggle--active {
  color: var(--kraft-text);
  border-color: var(--wood);
  background: var(--hover-bg);
}

/* ── Pledge sub-row ─────────────────────────────────────────────── */

.pledge-sub-row { display: none; }
.pledge-sub-row.pledge-sub-row--open { display: table-row; }

.pledge-sub-row__cell {
  padding: 0 12px 10px !important;
  border-bottom: 1px solid var(--row-line) !important;
  background: var(--row-hover2);
}

.pledge-sub-row__inner {
  background: var(--input-bg);
  border: 1px solid var(--divider-strong);
  border-left: 3px solid var(--wood);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-sans);
}

.pledge-sub-row__title {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.pledge-summary-row {
  padding: 0.4rem 0;
  border-top: 1px dashed var(--dash-border);
  font-size: 12.5px;
  font-family: var(--font-mono);
  color: var(--body-text);
}

.pledge-summary-row:first-child { border-top: none; padding-top: 0; }

/* A pledge line: details on the left, its 還款 button on the right. */
div.pledge-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.pledge-repay-btn {
  flex: none;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
}

.pledge-summary-row.pledge-danger  { border-left: 3px solid var(--up); padding-left: 0.6rem; }
.pledge-summary-row.pledge-caution { border-left: 3px solid var(--caution-border); padding-left: 0.6rem; }

.pledge-sub-row__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.pledge-add-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
}

/* ── Transactions table ───────────────────────────────────────── */

.txn-cell--right { text-align: right; }

.txn-table tbody tr:hover { background: var(--row-hover); }
.txn-table tbody td { font-family: var(--font-mono); color: var(--ink); }

.txn-type-badge {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.txn-type-badge--buy      { color: var(--kraft-text); background: var(--kraft-bg); border-color: var(--kraft-border); }
.txn-type-badge--sell     { color: #fff; background: var(--up); border-color: var(--up); }
.txn-type-badge--dividend { color: #fff; background: var(--down); border-color: var(--down); }
.txn-type-badge--pledge   { color: var(--caution); background: transparent; border-color: var(--caution-border); }
.txn-type-badge--stockdiv { color: var(--down); background: transparent; border-color: var(--down); }
.txn-type-badge--repay    { color: var(--caution); background: var(--kraft-bg); border-color: var(--caution-border); border-style: dashed; }

/* A pre-split trade: the statement's own share count, marked with the factor
   the portfolio restates it by (see data/corporate_actions.js). */
.txn-split-adjusted {
  border-bottom: 1px dashed var(--dash-border);
  cursor: help;
}
.txn-split-adjusted sup {
  font-size: 0.7em;
  margin-left: 0.15em;
  color: var(--muted);
}

/* ETFs page: day-over-day change type. Red = bought, green = sold (Taiwan convention). */
.etf-badge {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.etf-badge--new  { color: #fff; background: var(--up); border-color: var(--up); }
.etf-badge--add  { color: var(--up); border-color: var(--up); }
.etf-badge--trim { color: var(--down); border-color: var(--down); }
.etf-badge--exit { color: #fff; background: var(--down); border-color: var(--down); }
.etf-badge--same { color: var(--muted); }

/* Eight numeric columns don't collapse into cards like the holdings table
   does — on a narrow screen the table keeps its header and scrolls sideways. */
.etf-table-wrap { overflow-x: auto; }
.etf-table td, .etf-table th { white-space: nowrap; }

/* Diverging bar: grows right of the midline for buying, left for selling. */
.flow-bar-cell { width: 28%; min-width: 120px; }
.flow-bar {
  position: relative;
  display: block;
  height: 10px;
  background: linear-gradient(var(--dash-border), var(--dash-border)) center / 1px 100% no-repeat;
}
.flow-bar__fill { position: absolute; top: 0; bottom: 0; }
.flow-bar__fill--up   { background: var(--up); }
.flow-bar__fill--down { background: var(--down); }

.txn-amount--buy      { color: var(--ink); }
.txn-amount--sell     { color: var(--up); }
.txn-amount--dividend { color: var(--down); }
.txn-amount--pledge   { color: var(--caution); }
.txn-amount--repay    { color: var(--ink); }

.txn-row-actions {
  display: flex;
  gap: 0.3rem;
  justify-content: flex-end;
}

.txn-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
}

/* ── Transactions: month groups ───────────────────────────────── */
.txn-table tbody tr.txn-month td {
  padding: 0;
  border-bottom: 1px solid var(--row-line);
  background: var(--panel-accent);
}
.txn-table tbody tr.txn-month:hover { background: none; }

.txn-month__toggle {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.txn-month__caret {
  display: inline-block;
  color: var(--muted);
  transition: transform 0.15s;
}
.txn-month--open .txn-month__caret { transform: rotate(90deg); }
.txn-month__label { font-family: var(--font-pixel); font-size: 14px; }
.txn-month__meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }

/* ── Bar lists (ETF sector flow, Sectors page) ────────────────────
   One line per item — name, bar, headline figure — with the rest in a tip,
   instead of a wide table of numbers. */
.flow-list,
.rank-list {
  display: flex;
  flex-direction: column;
  margin-top: 6px;
}

.flow-row,
.rank-row {
  display: grid;
  grid-template-columns: minmax(5.5em, 9em) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 7px 4px;
  border-bottom: 1px dashed var(--row-line);
  cursor: help;
}
.flow-row:last-child,
.rank-row:last-child { border-bottom: none; }
.flow-row:hover,
.rank-row:hover,
.flow-row:focus-visible,
.rank-row:focus-visible { background: var(--row-hover); outline: none; }

.flow-row__name,
.rank-row__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--ink);
}

.flow-row__value,
.rank-row__value {
  min-width: 5.5em;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: nowrap;
}

.weight-bar {
  display: block;
  height: 10px;
  background: var(--progress-track);
  border-radius: 2px;
}
.weight-bar__fill {
  display: block;
  height: 100%;
  background: var(--wood);
  border-radius: 2px;
}

/* Sectors page: bar = share of the day's turnover, tick = recent average. */
.rank-row__bar {
  position: relative;
  display: block;
  height: 12px;
  background: var(--progress-track);
  border-radius: 2px;
}
.rank-row__fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--muted);
  border-radius: 2px;
}
.rank-row--inflow  .rank-row__fill { background: var(--up); }
.rank-row--outflow .rank-row__fill { background: var(--down); }
.rank-row--quiet   .rank-row__fill { background: var(--panel-border-strong); }
.rank-row__avg {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
}
.rank-row__value small { font-size: 11px; margin-left: 2px; }

.rank-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 11.5px;
  color: var(--muted);
}
.rank-legend span { display: inline-flex; align-items: center; gap: 5px; }
.rank-dot { width: 9px; height: 9px; border-radius: 2px; background: var(--muted); }
.rank-dot--inflow  { background: var(--up); }
.rank-dot--outflow { background: var(--down); }
.rank-dot--quiet   { background: var(--panel-border-strong); }
.rank-legend__tick { width: 2px; height: 12px; background: var(--ink); }

.rank-more { display: block; margin: 8px auto 0; font-size: 0.8rem; }

/* Sectors page: list/bubble switch, and the bubble chart
   (ui/charts/sector-bubbles.js). */
.rank-list[hidden],
.rank-legend [hidden],
.sector-bubbles[hidden],
.rank-more[hidden] { display: none; }
.sector-head { gap: 8px 12px; flex-wrap: wrap; }
.rank-legend__bubble {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
}

.sector-bubbles {
  width: 100%;
  margin: 8px 0 10px;
}
.sector-bubbles svg { display: block; max-width: 100%; height: auto; }

.bubble-quad__label {
  font-size: 11px;
  fill: var(--muted);
  opacity: 0.8;
}
.bubble-axis { stroke: var(--row-line); }
.bubble-tick,
.bubble-axis__title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  fill: var(--muted);
}
.bubble-axis__title { font-family: inherit; font-size: 11px; }

.sector-bubble {
  fill: color-mix(in srgb, var(--muted) 18%, transparent);
  stroke: color-mix(in srgb, var(--muted) 50%, transparent);
  stroke-width: 1;
  cursor: help;
  transition: fill 0.15s;
}
.sector-bubble--inflow  { fill: color-mix(in srgb, var(--up) 45%, transparent); stroke: var(--up); }
.sector-bubble--outflow { fill: color-mix(in srgb, var(--down) 45%, transparent); stroke: var(--down); }
.sector-bubble--quiet   { fill: color-mix(in srgb, var(--panel-border-strong) 30%, transparent); stroke: color-mix(in srgb, var(--panel-border-strong) 70%, transparent); }
.sector-bubble:hover,
.sector-bubble:focus-visible { stroke: var(--ink); stroke-width: 2; outline: none; }
.sector-bubble.is-pinned { stroke: var(--ink); stroke-width: 2.5; }

.bubble-labels,
.bubble-trail { pointer-events: none; }
/* While a trail shows, everything but its sector fades back. */
.sector-bubble,
.bubble-label,
.bubble-leader { transition: opacity 0.15s; }
.is-focused .sector-bubble:not(.is-active) { opacity: 0.12; }
.is-focused .bubble-label:not(.is-active),
.is-focused .bubble-leader:not(.is-active) { opacity: 0.15; }
.bubble-leader { stroke: var(--muted); stroke-width: 0.8; opacity: 0.7; }

/* Details of the hovered/tapped bubble, under the chart so they never cover its trail. */
.bubble-detail {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  min-height: 2.6em;
  margin: 6px 0 0;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--row-hover);
  font-size: 12.5px;
  color: var(--ink);
}
.bubble-detail--idle { color: var(--muted); background: transparent; }
.bubble-detail__name { font-size: 13.5px; }
.bubble-detail__name.rank-row--inflow  { color: var(--up); }
.bubble-detail__name.rank-row--outflow { color: var(--down); }
.bubble-label {
  font-size: 11px;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.bubble-trail__line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  opacity: 0.7;
}
.bubble-trail__dot { fill: var(--ink); opacity: 0.7; }
.bubble-trail__date {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 3px;
  stroke-linejoin: round;
}
