/* Stilul aplicației web. Întâi pentru telefon, apoi pentru ecrane late.
   Fără stiluri scrise în pagină: politica de securitate a paginii (CSP) le blochează. */

:root {
  color-scheme: light dark;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1c2026;
  --muted: #5a6370;
  --line: #dde1e6;
  --up: #17773a;
  --down: #b42318;
  --warn-bg: #fff3d1;
  --warn-text: #5c4300;
  --link: #0a58a8;
  /* Culorile curbelor din grafic: strategia și QQQ. Se deosebesc și pentru cine nu vede bine culorile. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --card: #191e24;
    --text: #e5e8ec;
    --muted: #9aa3ad;
    --line: #2b323a;
    --up: #4ec26f;
    --down: #ff7b72;
    --warn-bg: #3b2f0f;
    --warn-text: #f2d47e;
    --link: #73b6ff;
    --series-1: #3987e5;
    --series-2: #d95926;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--link);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.topbar ul {
  display: flex;
  gap: 0 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.topbar li a {
  display: inline-block;
  padding: 0.25rem 0;
}

.topbar a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.topbar p {
  margin: 0;
}

/* „Ieși” stă la dreapta barei și arată ca o legătură. */
.topbar form {
  margin: 0 0 0 auto;
}

.topbar button {
  padding: 0.25rem 0;
  background: none;
  color: var(--link);
  text-decoration: underline;
}

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1rem 0.75rem 3rem;
}

.card {
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
}

/* Pagina de intrare: o singură casetă, îngustă, la mijloc. */
.narrow {
  max-width: 26rem;
  margin: 2rem auto;
}

h1,
h2 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
}

h3 {
  margin: 1rem 0 0.25rem;
  font-size: 1rem;
}

p {
  margin: 0.5rem 0;
}

small,
.muted,
.note {
  color: var(--muted);
}

.muted {
  font-size: 0.9rem;
}

code {
  padding: 0.1rem 0.3rem;
  background: var(--bg);
  border-radius: 0.25rem;
  font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.plus {
  color: var(--up);
}

.minus {
  color: var(--down);
}

.warning {
  padding: 0.5rem 0.75rem;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 0.5rem;
}

/* Formularele. Literele de 16px, ca în pagină, opresc telefonul să mărească pagina când scrii parola. */
label {
  display: block;
  font-weight: 600;
}

input,
button {
  font: inherit;
}

input {
  display: block;
  width: 100%;
  margin: 0.25rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--muted);
  border-radius: 0.5rem;
}

button {
  padding: 0.5rem 1.25rem;
  background: var(--link);
  color: var(--card);
  border: 0;
  border-radius: 0.5rem;
  cursor: pointer;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

th.num,
td.num {
  text-align: right;
}

dl {
  margin: 0.75rem 0 0;
}

dl > div {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 1rem;
  padding: 0.35rem 0;
  border-top: 1px solid var(--line);
}

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

dd {
  margin: 0 0 0 auto;
  text-align: right;
}

.sums dd,
.comparison dd {
  font-weight: 600;
}

.tickets {
  margin: 0.25rem 0;
  padding-left: 1.25rem;
}

.tickets li {
  margin: 0.35rem 0;
}

/* Cifrele backtestului: numele rândului e text obișnuit, nu un titlu de coloană. */
.figures tbody th {
  color: var(--text);
  font-size: 1rem;
  font-weight: 400;
}

/* Graficul backtestului. Clasa spune curba, iar --series îi dă culoarea, și în legendă, și în grafic. */
.strategy {
  --series: var(--series-1);
}

.benchmark {
  --series: var(--series-2);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin: 0.5rem 0;
  padding: 0;
  list-style: none;
}

.swatch {
  display: inline-block;
  width: 1rem;
  height: 0.25rem;
  margin-right: 0.4rem;
  vertical-align: middle;
  background: var(--series);
  border-radius: 0.125rem;
}

/* Loc pentru etichete: valorile la stânga, anii dedesubt. */
.plot {
  padding: 0.75rem 0.75rem 1.75rem 3.75rem;
}

.chart {
  display: block;
  width: 100%;
  height: 14rem;
}

/* Etichetele, punctele de la capăt și o curbă lipită de margine ies puțin din grafic. */
.chart,
.chart svg {
  overflow: visible;
}

.chart text {
  fill: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.y-axis text {
  text-anchor: end;
}

.x-axis text {
  text-anchor: middle;
}

.grid line {
  stroke: var(--line);
  stroke-width: 1px;
  shape-rendering: crispEdges;
}

/* Curbele stau într-un SVG întins pe tot graficul. Fără non-scaling-stroke, linia s-ar întinde și ea. */
.chart polyline {
  fill: none;
  stroke: var(--series);
  stroke-width: 2px;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.end {
  fill: var(--series);
  stroke: var(--card);
  stroke-width: 2px;
}

/* Sub mouse, o fâșie arată linia zilei, iar browserul arată ziua și valorile din <title>. */
.hover rect {
  fill: transparent;
}

.hover line {
  visibility: hidden;
  stroke: var(--muted);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

.hover g:hover line {
  visibility: visible;
}

details {
  margin-top: 0.75rem;
}

summary {
  color: var(--link);
  cursor: pointer;
}

@media (min-width: 40rem) {
  .chart {
    height: 20rem;
  }
}

/* Pe telefon, fiecare poziție e un bloc, cu numele coloanei lângă valoare. */
@media (max-width: 40rem) {
  /* Când sunt mulți ani, se vede doar un an din doi, ca etichetele să nu se suprapună. */
  .chart .minor {
    display: none;
  }

  /* „Ieși” rămâne sus, lângă pagini, iar nota trece pe rândul de dedesubt. */
  .topbar p {
    order: 1;
  }

  /* Tabelele backtestului: trei coloane, două cu sume în dolari, nu încap pe un telefon îngust. Prima celulă a
     rândului stă deasupra, iar cele două valori dedesubt, sub titlurile lor. */
  .stack-on-phone,
  .stack-on-phone thead,
  .stack-on-phone tbody {
    display: block;
  }

  .stack-on-phone tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--line);
  }

  .stack-on-phone th,
  .stack-on-phone td {
    border: 0;
  }

  .stack-on-phone thead tr > :first-child {
    display: none;
  }

  .stack-on-phone tbody tr > :first-child {
    grid-column: 1 / -1;
    padding-bottom: 0;
  }

  .stack-on-phone tbody tr > :not(:first-child) {
    padding-top: 0.15rem;
  }

  .positions thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .positions,
  .positions tbody,
  .positions tr {
    display: block;
  }

  .positions tr {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--line);
  }

  .positions td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.15rem 0;
    border: 0;
    text-align: right;
  }

  .positions td::before {
    content: attr(data-label);
    color: var(--muted);
    text-align: left;
  }
}
