/* The portfolio, in the apps' look: numbers first, green for gains and red for losses (always
   with a sign or ▲/▼, so colour is never the only cue), white cards on a pale green-grey ground. */
:root {
  --ground: #f3f6f4;
  --card: #ffffff;
  --ink: #10201a;
  --muted: #55655e;
  --line: #edf1ef;
  --gain: #0b7a55;
  --gain-wash: #e2f3ea;
  --loss: #b83a26;
  --loss-wash: #fbe7e2;
  --accent: #0b7a55;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1412;
    --card: #18201d;
    --ink: #eef3f0;
    --muted: #a3b2ab;
    --line: #26302c;
    --gain: #3cc48f;
    --gain-wash: #173528;
    --loss: #f07a64;
    --loss-wash: #3a1d17;
    --accent: #0b7a55;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--ground);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.sheet-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.tone-gain { color: var(--gain); }
.tone-loss { color: var(--loss); }
.tone-flat { color: var(--ink); }
.tone-muted { color: var(--muted); }

/* Header and footer */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 800;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--ink);
}

.nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

.nav a,
.nav button {
  text-decoration: none;
  color: var(--muted);
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
}

.nav a.active {
  color: var(--ink);
  font-weight: 600;
}

.footer {
  padding: 12px 24px;
  font-size: 0.875rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-links {
  display: flex;
  gap: 28px;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

/* Page */

.main {
  flex: 1;
  padding: 28px 16px 48px;
}

.page {
  max-width: 680px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 2px 0 0;
  font-size: 2rem;
}

.add-button {
  padding: 11px 18px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.card {
  background: var(--card);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 1px 1px rgba(16, 32, 26, 0.05);
}

.section-title {
  font-size: 1.2rem;
  margin: 26px 0 10px;
}

.primary,
.ghost {
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 600;
  cursor: pointer;
}

.primary {
  border: none;
  background: var(--accent);
  color: #fff;
}

.primary.dark {
  background: var(--ink);
  color: var(--card);
}

.primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.ghost {
  border: 1px solid var(--line);
  background: var(--card);
}

.wide {
  width: 100%;
  margin-top: 14px;
}

.error,
.error-text {
  color: var(--loss);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 8px 0 0;
}

/* Hero */

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.info {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.hero-figure {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.hero-total {
  font-size: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pill {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px;
  border-radius: 9px;
  background: var(--line);
}

.pill.tone-gain { background: var(--gain-wash); }
.pill.tone-loss { background: var(--loss-wash); }

.chart {
  display: block;
  width: 100%;
  height: 96px;
  margin-top: 10px;
}

.chart-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: currentColor;
  opacity: 0.12;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
}

.tiles div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tiles span {
  font-size: 0.8rem;
}

.tiles strong {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.figures {
  display: flex;
  gap: 18px;
  margin-top: 10px;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.other-currency {
  margin-top: 6px;
  font-size: 0.85rem;
}

.empty h2 {
  margin: 0 0 6px;
}

/* Position rows */

.list {
  padding: 4px 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 0;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.row:last-child {
  border-bottom: none;
}

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 700;
}

.tint-0 { background: #e6eefb; color: #1d4fa8; }
.tint-1 { background: #e8f5dd; color: #3d6b12; }
.tint-2 { background: #eeeef1; color: #3a3a44; }
.tint-3 { background: #fbebdd; color: #8a4a12; }
.tint-4 { background: #f3e6fa; color: #6b2e8c; }
.tint-5 { background: #e0f3f3; color: #10666a; }

@media (prefers-color-scheme: dark) {
  .tint-0 { background: #1d4fa8; color: #e6eefb; }
  .tint-1 { background: #3d6b12; color: #e8f5dd; }
  .tint-2 { background: #3a3a44; color: #eeeef1; }
  .tint-3 { background: #8a4a12; color: #fbebdd; }
  .tint-4 { background: #6b2e8c; color: #f3e6fa; }
  .tint-5 { background: #10666a; color: #e0f3f3; }
}

.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-symbol {
  font-weight: 600;
}

.row-sub {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-figures {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.row-profit {
  font-weight: 600;
}

.row-pct {
  font-size: 0.85rem;
}

/* Sheets */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  background: rgba(16, 32, 26, 0.4);
  overflow-y: auto;
}

.sheet-card {
  width: 100%;
  max-width: 560px;
  background: var(--ground);
  border-radius: 22px;
  padding: 22px;
}

.sheet-card h2 {
  margin: 0 0 14px;
}

.sheet-card h3 {
  font-size: 1.1rem;
  margin: 20px 0 8px;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.field input,
.field textarea,
.share-more select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 1rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.suggestions {
  margin-top: 6px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.suggestion {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.suggestion .small {
  display: block;
}

.suggestion:hover,
.suggestion:focus {
  background: var(--line);
}

.selected {
  margin-top: 8px;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
  padding: 3px;
  border-radius: 10px;
  background: var(--line);
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: block;
  padding: 7px;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
}

.segmented input:checked + span {
  background: var(--card);
  box-shadow: 0 1px 2px rgba(16, 32, 26, 0.12);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
}

.share {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.share legend {
  padding: 0 4px;
  font-weight: 600;
}

.share-list {
  display: grid;
  gap: 8px;
}

.share-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.share-list input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
}

/* One trade */

.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-head .badge {
  width: 50px;
  height: 50px;
  border-radius: 15px;
  font-size: 1rem;
}

.detail-name {
  flex: 1;
  min-width: 0;
}

.detail-name h2 {
  margin: 0;
  font-size: 1.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-profit {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
}

.detail-profit b {
  font-size: 1.5rem;
}

.inset {
  padding: 14px 16px;
}

.line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.opened {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}

.note {
  font-style: italic;
  margin: 0 0 8px;
}

.sale {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.share-more {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.share-more select {
  flex: 1;
  min-width: 0;
}

.links {
  padding: 4px 16px;
}

.links a {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.links a:last-child {
  border-bottom: none;
}

.how {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0;
}

.how dt {
  font-weight: 600;
}

.how dd {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 560px) {
  .header {
    padding: 14px 16px;
  }

  .nav {
    gap: 12px;
    font-size: 0.95rem;
  }

  .hero-total {
    font-size: 2rem;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .sheet {
    padding: 16px 8px;
  }

  .footer {
    flex-direction: column;
    gap: 8px;
  }

  .footer-links {
    gap: 16px;
  }
}

/* Trades are made at the live price: shown, not typed. */
.field input.live-price {
  background: var(--line);
  color: var(--ink);
  font-weight: 600;
  cursor: default;
}

.price-status {
  min-height: 1.2em;
}

.price-unavailable {
  color: var(--loss);
}

.link-button {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.tiles-title {
  margin-top: 14px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tiles-title + .tiles {
  margin-top: 4px;
}

.figures {
  flex-wrap: wrap;
  gap: 6px 8px;
}

.short-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--line);
  color: var(--muted);
  vertical-align: middle;
}

.links a > span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chart-zero {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.4;
}

/* Stop loss and take profit */
.level-outcome {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.card .level-outcome {
  text-align: right;
}

/* Coloured like the profit it would make, over the hint's grey. */
.level-outcome.tone-gain { color: var(--gain); }
.level-outcome.tone-loss { color: var(--loss); }

/* Portfolio controls and trade cues match the group table. */
.portfolio-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin: 22px 0 8px; flex-wrap: wrap; }
.portfolio-toolbar label { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.portfolio-sort-control { position: relative; }
.portfolio-sort-control::after { content: ""; position: absolute; right: 17px; top: 17px; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none; }
#portfolio-sort { appearance: none; min-height: 44px; padding: 10px 42px 10px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-weight: 600; cursor: pointer; max-width: 100%; }
#portfolio-sort:hover { border-color: var(--muted); }
#portfolio-sort:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.row.position-open { background: #eff6ff; }
.row.position-closed { background: #f3f4f6; }
.row.position-open:hover { background: #dbeafe; }
.row.position-closed:hover { background: #e5e7eb; }
.row.position-open, .row.position-closed { padding: 14px 12px; border-radius: 10px; margin: 4px 0; }
.position-badge { display: inline-block; align-self: flex-start; width: fit-content; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.position-badge.position-open { color: #1e40af; background: #dbeafe; }
.position-badge.position-closed { color: #374151; background: #e5e7eb; }
.portfolio-result { display: inline-grid; text-align: right; gap: 2px; padding: 5px 8px; border-radius: 6px; }
.portfolio-result small { font-size: 11px; font-weight: 600; }
.portfolio-result.result-profit { color: #166534; background: #dcfce7; }
.portfolio-result.result-loss { color: #991b1b; background: #fee2e2; }
.portfolio-result.result-neutral { color: #374151; background: #e5e7eb; }
@media (prefers-color-scheme: dark) {
  .row.position-open { background: #15283d; }
  .row.position-closed { background: #242b30; }
  .row.position-open:hover { background: #1e3550; }
  .row.position-closed:hover { background: #303940; }
  .position-badge.position-open { background: #203e60; color: #bfdbfe; }
  .position-badge.position-closed, .portfolio-result.result-neutral { background: #374151; color: #e5e7eb; }
  .portfolio-result.result-profit { background: var(--gain-wash); color: var(--gain); }
  .portfolio-result.result-loss { background: var(--loss-wash); color: var(--loss); }
}
@media (max-width: 420px) {
  .portfolio-toolbar { justify-content: space-between; }
  .row.position-open, .row.position-closed { padding: 12px 8px; gap: 8px; }
}
