:root {
  color-scheme: dark;
  --bg: #070910;
  --panel: #101520;
  --panel-2: #151c29;
  --line: rgba(255, 255, 255, .1);
  --text: #eef4ff;
  --muted: #8f9bb4;
  --gold: #f6c944;
  --cyan: #4cc9f0;
  --green: #47d18c;
  --red: #ff6978;
  --orange: #ffad5c;
  --violet: #b38cff;
  --radius: 8px;
  font-family: Inter, "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(76, 201, 240, .08), transparent 28rem),
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 1px, transparent 1px 82px),
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 82px),
    var(--bg);
  color: var(--text);
}

.portfolio-loading #summary-grid,
.portfolio-loading #treemap,
.portfolio-loading .allocation-wrap,
.portfolio-loading #holdings-grid,
.portfolio-loading #options-card {
  visibility: hidden;
}

button { font: inherit; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 48px;
}

.topbar,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 28px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 21, 32, .72);
  overflow-x: auto;
}

.nav-link {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.nav-link.active {
  color: var(--bg);
  background: var(--gold);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--cyan);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(32px, 5vw, 62px);
  line-height: .95;
  letter-spacing: 0;
}

h2 {
  font-size: 24px;
  letter-spacing: 0;
}

.toolbar {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .04);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.portfolio-tab,
.icon-action {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.portfolio-tab {
  padding: 0 14px;
  font-weight: 800;
}

.portfolio-tab.active {
  color: var(--bg);
  background: var(--gold);
}

.label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.icon-action {
  padding: 0 16px;
  color: var(--text);
  border: 1px solid rgba(246, 201, 68, .42);
  background: rgba(246, 201, 68, .1);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 26px;
}

.summary-card,
.sector-card,
.options-card,
.treemap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 21, 32, .88);
}

.summary-card {
  padding: 16px;
  min-height: 108px;
}

.summary-card .value {
  margin-top: 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 28px;
  font-weight: 800;
}

.summary-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.cash-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.cash-editor > span {
  color: var(--green);
}

.cash-editor input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-bottom: 1px solid rgba(255,255,255,.22);
  outline: 0;
  color: var(--text);
  background: transparent;
  font-family: "JetBrains Mono", monospace;
  font-size: 22px;
  font-weight: 800;
}

.cash-editor input:focus {
  border-color: var(--green);
}

.cash-editor button {
  height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(71, 209, 140, .4);
  border-radius: 6px;
  color: var(--green);
  background: rgba(71, 209, 140, .08);
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 800;
}

.section-head {
  margin: 30px 0 12px;
}

.section-head p,
.section-head span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.treemap {
  position: relative;
  height: 500px;
  overflow: hidden;
  padding: 6px;
}

.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 7px;
  color: #071019;
  background: var(--tile-color);
  transition: filter .18s ease, transform .18s ease;
}

.tile::before {
  display: none;
}

.tile b,
.tile span {
  position: relative;
  z-index: 1;
}

.tile b {
  font-family: "JetBrains Mono", monospace;
  font-size: 19px;
}

.tile span {
  color: inherit;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 800;
}

.tile.small b {
  font-size: 14px;
}

.tile.small span {
  font-size: 9px;
}

.tile:hover {
  z-index: 2;
  filter: brightness(1.08);
  transform: scale(.995);
}

.allocation-title {
  margin-top: 28px;
}

.allocation-wrap {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 21, 32, .88);
}

.allocation-bar {
  display: flex;
  width: 100%;
  height: 38px;
  overflow: hidden;
  border-radius: 7px;
  background: rgba(255,255,255,.06);
}

.allocation-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 3px;
  overflow: hidden;
  color: #071019;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.allocation-segment.compact span {
  display: none;
}

.allocation-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--swatch);
}

.holdings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.sector-card {
  overflow: hidden;
}

.sector-head,
.holding-row,
.option-row,
.option-head {
  display: grid;
  align-items: center;
  gap: 12px;
}

.sector-head {
  grid-template-columns: 74px minmax(80px, 1fr) 62px 56px 76px 76px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.sector-head strong {
  grid-column: 1 / 3;
  font-size: 17px;
}

.sector-head span {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.sector-head .sector-weight,
.sector-head .column-label {
  text-align: right;
}

.sector-head .column-label {
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.holding-row {
  grid-template-columns: 74px minmax(80px, 1fr) 62px 56px 76px 76px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.055);
}

.holding-row:last-child { border-bottom: 0; }

.ticker {
  color: var(--gold);
  font-family: "JetBrains Mono", monospace;
  font-weight: 800;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
}

.bar i {
  display: block;
  width: var(--w);
  height: 100%;
  border-radius: inherit;
  background: var(--c);
}

.mono {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  text-align: right;
}

.manual-price {
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  text-align: right;
  cursor: pointer;
}

.manual-price:hover {
  color: var(--cyan);
  text-decoration: underline;
}

.muted { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }

.options-title span {
  color: var(--gold);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: .18em;
}

.transaction-section,
.option-transaction-section {
  margin-top: 30px;
}

.transaction-section[hidden],
.option-transaction-section[hidden] {
  display: none;
}

.transaction-title {
  margin-top: 0;
}

.trade-form {
  display: grid;
  grid-template-columns: 1fr 1.2fr .8fr .8fr 1fr 1.1fr auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 21, 32, .88);
}

.option-trade-form {
  grid-template-columns: 1fr .8fr 1fr 1.2fr .7fr 1fr auto;
}

.trade-form label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.trade-form label span {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.trade-form input,
.trade-form select {
  width: 100%;
  height: 40px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  color: var(--text);
  background: #0c111b;
  font-family: "JetBrains Mono", monospace;
}

.trade-form [hidden] {
  display: none;
}

.trade-form input:focus,
.trade-form select:focus {
  border-color: var(--cyan);
}

.record-trade {
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  color: var(--bg);
  background: var(--gold);
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.trade-ledger {
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 21, 32, .88);
}

.trade-head,
.trade-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr .8fr .8fr 1fr 1.1fr 1.1fr 38px;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
}

#option-trade-ledger .trade-head,
#option-trade-ledger .trade-row {
  grid-template-columns: 1fr .8fr 1fr 1.2fr .7fr 1fr 38px;
}

.trade-head {
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: .12em;
}

.trade-row {
  border-bottom: 1px solid rgba(255,255,255,.055);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.trade-row:last-child {
  border-bottom: 0;
}

#trade-ledger .trade-head span:nth-child(4),
#trade-ledger .trade-head span:nth-child(5),
#trade-ledger .trade-head span:nth-child(6),
#trade-ledger .trade-row > span:nth-child(4),
#trade-ledger .trade-row > span:nth-child(5),
#trade-ledger .trade-row > span:nth-child(6),
#option-trade-ledger .trade-head span:nth-child(3),
#option-trade-ledger .trade-head span:nth-child(5),
#option-trade-ledger .trade-head span:nth-child(6),
#option-trade-ledger .trade-row > span:nth-child(3),
#option-trade-ledger .trade-row > span:nth-child(5),
#option-trade-ledger .trade-row > span:nth-child(6) {
  text-align: right;
}

.trade-side {
  font-weight: 800;
}

.delete-trade {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 18px;
}

.empty-ledger {
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.options-card {
  overflow: hidden;
}

.option-head,
.option-row {
  grid-template-columns: 1fr 1.1fr 1fr 1.2fr .7fr 1fr 1fr;
  padding: 12px 16px;
}

.option-head {
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.option-row {
  border-bottom: 1px solid rgba(255,255,255,.055);
}

.option-row:last-child { border-bottom: 0; }

.option-head span:nth-child(n+3),
.option-row > span:nth-child(n+3) {
  text-align: right;
}

.badge {
  display: inline-flex;
  width: fit-content;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(246, 201, 68, .35);
  color: var(--gold);
  background: rgba(246, 201, 68, .08);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 800;
}

.badge.buy {
  border-color: rgba(76, 201, 240, .35);
  color: var(--cyan);
  background: rgba(76, 201, 240, .08);
}

.pin-mask {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  z-index: 1000;
  background: rgba(4, 7, 13, .94);
  backdrop-filter: blur(22px);
}

.pin-mask.show {
  display: grid;
}

.pin-panel {
  position: relative;
  width: min(390px, 100%);
  padding: 24px 24px 26px;
  border: 1px solid rgba(246, 201, 68, .28);
  border-radius: var(--radius);
  background: #111722;
  box-shadow: 0 24px 80px rgba(0,0,0,.72);
  isolation: isolate;
  text-align: center;
}

.pin-panel .eyebrow {
  margin-top: 0;
}

.close-pin {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 24px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 24px 0 12px;
}

.pin-dots span {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(255,255,255,.36);
  border-radius: 50%;
}

.pin-dots span.filled {
  border-color: var(--gold);
  background: var(--gold);
}

.pin-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.keypad button {
  width: 72px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: rgba(255,255,255,.06);
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 21px;
  font-weight: 800;
}

.keypad-spacer {
  width: 72px;
  height: 58px;
}

.keypad button:active {
  transform: translateY(1px);
  background: rgba(246, 201, 68, .16);
}

@media (max-width: 820px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .icon-action {
    width: 100%;
  }

  .portfolio-tab {
    flex: 1;
  }

  .summary-grid,
  .holdings-grid {
    grid-template-columns: 1fr;
  }

  .treemap { height: 390px; }

  .holding-row {
    grid-template-columns: 74px minmax(80px, 1fr) 62px 56px 76px 76px;
  }

  .sector-card {
    overflow-x: auto;
  }

  .sector-head,
  .holding-row {
    min-width: 520px;
  }

  .options-card {
    overflow-x: auto;
  }

  .trade-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-trade {
    grid-column: 1 / -1;
  }

  .trade-ledger {
    overflow-x: auto;
  }

  .trade-head,
  .trade-row {
    min-width: 780px;
  }

  #option-trade-ledger .trade-head,
  #option-trade-ledger .trade-row {
    min-width: 620px;
  }

  .option-head,
  .option-row {
    min-width: 680px;
  }
}

@media (max-width: 520px) {
  .trade-form {
    grid-template-columns: 1fr;
  }

  .record-trade {
    grid-column: auto;
  }
}
