:root {
  color-scheme: light;
  --bg: #fff;
  --paper: #f7f8fa;
  --ink: #2f343f;
  --text: #2f343f;
  --muted: #7d8490;
  --line: #e2e5ec;
  --line-strong: #c9ced8;
  --accent: #faaf3a;
  --accent-soft: #fff7e8;
  --danger: #b42318;
  --warning: #9a6700;
  --good: #067647;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 500 14px/1.55 AvenirNext, "Avenir Next", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
p, h1, h2 { margin: 0; }
.container { width: min(1340px, calc(100% - 40px)); margin: 0 auto; padding: 28px 0 46px; }

.site-header {
  min-height: 96px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 28px;
  padding: 18px clamp(20px, 5vw, 68px);
  background: #fff;
  border-bottom: 1px solid rgba(226, 229, 236, .75);
}
.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .22em;
  text-transform: uppercase;
}
h1, h2 {
  font-family: "Noe Display", Georgia, "Times New Roman", serif;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
}
h1 { font-size: clamp(30px, 5vw, 54px); margin-top: 8px; }
h2 { font-size: 34px; margin-top: 8px; }
.header-meta { color: var(--muted); text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: .13em; }
.header-meta strong { display: block; color: var(--ink); font-size: 12px; letter-spacing: 0; text-transform: none; margin-top: 3px; }

.summary-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
  margin-bottom: 24px;
}
.portfolio-switcher {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(220px, 320px) repeat(3, auto);
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
}
.portfolio-switcher .action { min-width: 72px; }
.custom-position {
  display: grid;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 12px;
  margin-bottom: 12px;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, .45fr) minmax(110px, .35fr) auto;
}
.add-mode-toggle {
  display: flex;
  gap: 14px;
  align-items: center;
}
.add-mode {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .16em;
  padding: 0;
  text-transform: uppercase;
}
.add-mode.active {
  color: var(--ink);
  font-weight: 900;
}
.add-mode:not(.active):hover { color: var(--accent); }
.metric { background: #fff; padding: 18px 20px; min-width: 0; }
.metric span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.metric strong { display: block; color: var(--ink); font-size: 26px; line-height: 1.15; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric em { display: block; color: var(--muted); font-style: normal; margin-top: 4px; }

.tabs {
  display: flex;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.tab {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  padding: 12px 0;
  text-transform: uppercase;
}
.tab.active, .tab:hover { color: var(--accent); border-bottom-color: var(--accent); }
.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) repeat(5, minmax(120px, .7fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}
label span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  margin-bottom: 5px;
}
input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  padding: 7px 9px;
}
input:disabled, select:disabled {
  background: #edf0f4;
  color: var(--muted);
  cursor: not-allowed;
}
input:focus, select:focus { outline: 2px solid rgba(250, 175, 58, .25); border-color: var(--accent); }
.table-note { color: var(--muted); font-size: 12px; margin: 8px 0 12px; }

.table-frame {
  border: 1px solid var(--line);
  overflow: auto;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; min-width: 1240px; }
.universe-grid { min-width: 1240px; }
.portfolio-grid { min-width: 1180px; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 11px; text-align: left; vertical-align: middle; }
th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--paper);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
td { color: #3f4652; white-space: nowrap; }
tr:hover td { background: #fffaf0; }
.main-cell { min-width: 270px; white-space: normal; position: relative; }
.main-cell strong { display: block; color: var(--ink); font-weight: 800; line-height: 1.25; }
.main-cell span, .subline { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.fallback-note { color: var(--warning); }
.portfolio-grid .main-cell {
  min-width: 280px;
  width: 280px;
  max-width: 280px;
}
.portfolio-main-cell { cursor: pointer; }
.portfolio-main-cell .position-subtitle,
.portfolio-main-cell .fallback-note {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.portfolio-main-cell:not(.expanded) .fallback-note {
  display: none;
}
.portfolio-main-cell.expanded .position-subtitle,
.portfolio-main-cell.expanded .fallback-note {
  display: block;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  word-break: break-word;
}
.main-cell[data-tooltip]:hover:after {
  content: attr(data-tooltip);
  position: absolute;
  left: 10px;
  top: calc(100% - 2px);
  z-index: 50;
  min-width: 190px;
  max-width: 280px;
  border: 1px solid rgba(154, 103, 0, .35);
  border-radius: 4px;
  background: #fffaeb;
  box-shadow: 0 10px 24px rgba(47, 52, 63, .16);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  padding: 8px 10px;
  white-space: normal;
}
.main-cell strong .yield-warning {
  color: var(--accent);
  display: inline-block;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
  margin-left: 7px;
  text-shadow: 0 0 0 var(--accent);
  vertical-align: 1px;
}
.pill {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--paper);
  padding: 3px 6px;
  font-size: 11px;
}
.sort-button {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  letter-spacing: inherit;
  padding: 0;
  text-align: left;
  text-transform: inherit;
  white-space: nowrap;
}
.sort-button:hover { color: var(--accent); }
.amount-input, .portfolio-amount { width: 92px; }
.leverage-input, .portfolio-leverage { width: 58px; }
.custom-name-edit { width: 250px; }
.custom-apy-edit { width: 88px; }
.apy-edit-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.apy-edit-wrap span {
  color: var(--muted);
  font-weight: 800;
}
.custom-title { cursor: text; }
.portfolio-grid th:last-child,
.portfolio-grid td:last-child {
  min-width: 54px;
  width: 54px;
  padding-right: 16px;
}
.portfolio-grid .portfolio-amount { width: 92px; }
.portfolio-grid .portfolio-leverage { width: 68px; }
.universe-grid th:nth-last-child(2),
.universe-grid td:nth-last-child(2) {
  width: 64px;
  min-width: 64px;
  padding-left: 6px;
  padding-right: 6px;
}
.portfolio-grid td[title] { cursor: help; }
.action, .icon-button {
  appearance: none;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  min-height: 32px;
  min-width: 42px;
  padding: 5px 10px;
}
.action:hover, .icon-button:hover { border-color: var(--accent); color: var(--accent); }
.action.selected { color: var(--good); border-color: rgba(6, 118, 71, .35); background: #ecfdf3; }
.danger-action:hover { border-color: var(--danger); color: var(--danger); }
.icon-button { font-size: 20px; line-height: 1; width: 34px; padding: 0; }
.portfolio-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.warning, .error {
  border: 1px solid rgba(154, 103, 0, .35);
  background: #fffaeb;
  color: var(--warning);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.error { border-color: rgba(180, 35, 24, .35); background: #fef3f2; color: var(--danger); }
tr.stale td { background: #fffbf0; }
.spark-wrap {
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--paper);
  color: var(--accent);
  height: 110px;
  padding: 10px;
}
#sparkline { width: 100%; height: 90px; display: block; }
#sparkline text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.empty { padding: 36px; color: var(--muted); text-align: center; }
.freshness {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}
.freshness div { border-top: 1px solid var(--line); padding-top: 10px; min-width: 0; }
.freshness strong { display: block; color: var(--ink); margin-bottom: 2px; }
.freshness span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 900px) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .header-meta { text-align: left; }
  .summary-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar, .portfolio-switcher, .custom-position { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-wrap { grid-column: 1 / -1; }
  .freshness { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .container { width: min(100% - 24px, 1340px); }
  .summary-band, .toolbar, .portfolio-switcher, .custom-position { grid-template-columns: 1fr; }
  .metric strong { font-size: 22px; }
}

/* ---------- Read-only published mode (body.readonly) ---------- */
/* Hides every editing / universe affordance and neutralises the inline inputs
   so the published page is a clean, view-only portfolio. No effect without the
   class, so the local app is unchanged. */
body.readonly .tabs,
body.readonly #universe-view,
body.readonly .portfolio-switcher,
body.readonly .add-position,
body.readonly #stale-warning { display: none !important; }

/* Drop the trailing "remove" column from the portfolio table */
body.readonly .portfolio-grid th:last-child,
body.readonly .portfolio-grid td:last-child { display: none; }

/* Show the amount / leverage / custom-APY inputs as static text */
body.readonly .portfolio-amount,
body.readonly .portfolio-leverage,
body.readonly .custom-apy-edit {
  pointer-events: none;
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 0;
  width: auto;
  color: inherit;
  font: inherit;
  -moz-appearance: textfield;
  appearance: textfield;
}
body.readonly .portfolio-amount::-webkit-outer-spin-button,
body.readonly .portfolio-amount::-webkit-inner-spin-button,
body.readonly .portfolio-leverage::-webkit-outer-spin-button,
body.readonly .portfolio-leverage::-webkit-inner-spin-button,
body.readonly .custom-apy-edit::-webkit-outer-spin-button,
body.readonly .custom-apy-edit::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
body.readonly .apy-edit-wrap { pointer-events: none; }

/* Fit the whole portfolio table (through the last column) inside the browser.
   Drop the large fixed min-widths so the table tracks the container width, and
   tighten the widest columns. The frame keeps overflow:auto as a safety net for
   very narrow screens. */
body.readonly .table-frame { overflow-x: auto; }
body.readonly .portfolio-grid { min-width: 0; width: 100%; }
body.readonly .portfolio-grid th,
body.readonly .portfolio-grid td { padding: 8px 7px; }
body.readonly .portfolio-grid .main-cell,
body.readonly .portfolio-grid .portfolio-main-cell {
  min-width: 165px;
  width: 185px;
  max-width: 185px;
}
/* Cap the secondary sub-lines so the Spot column can't balloon the table wide. */
body.readonly .portfolio-grid .subline,
body.readonly .portfolio-grid .position-subtitle {
  display: block;
  max-width: 128px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
