/* folio's one stylesheet (FOL-15, Choice 1): no framework, no build step. Colours exist only as the
   design tokens below; --up and --down are used only by the .up and .down rules (green and red only
   for gains and losses). Dark is designed first and is the default; light follows the device unless
   a user setting pins a theme (data-theme on <html>). One breakpoint, at 900 CSS px: below it the
   bottom tab bar and the two-line holdings rows; from it the side menu and the full table. */

:root {
  --bg: #0b0d10;
  --surface: #15181d;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #272b33;
  --accent: #5b9bff;
  --up: #2ecc71;
  --down: #ff5c5c;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f6f7f8;
    --surface: #ffffff;
    --text: #15181d;
    --muted: #5f6670;
    --border: #d9dde3;
    --accent: #1a5fd0;
    --up: #13803f;
    --down: #c62828;
  }
}

[data-theme="light"] {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --text: #15181d;
  --muted: #5f6670;
  --border: #d9dde3;
  --accent: #1a5fd0;
  --up: #13803f;
  --down: #c62828;
}

[data-theme="dark"] {
  --bg: #0b0d10;
  --surface: #15181d;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #272b33;
  --accent: #5b9bff;
  --up: #2ecc71;
  --down: #ff5c5c;
}

/* --- Base ------------------------------------------------------------------------------------ */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

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

main {
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
  max-width: 1100px;
}

main h1 {
  font-size: 1.4rem;
  margin: 0.5rem 0 0.75rem;
}

main h2 {
  font-size: 1.1rem;
  margin: 1.5rem 0 0.5rem;
}

main h3,
main h4 {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

main p {
  margin: 0.5rem 0;
}

main table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0 1rem;
  font-variant-numeric: tabular-nums;
}

main th,
main td {
  text-align: left;
  vertical-align: top;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

main th {
  color: var(--muted);
  font-weight: 600;
}

main form {
  margin: 0.5rem 0;
}

main fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0.75rem 0;
}

main input,
main select,
main button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  max-width: 100%;
}

main input[type="checkbox"],
main input[type="radio"] {
  padding: 0;
}

main button {
  cursor: pointer;
  border-color: var(--accent);
}

main label {
  margin-right: 0.5rem;
}

main code {
  font-variant-numeric: tabular-nums;
}

main [role="alert"] {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}

/* --- The top bar, the switcher and the tabs ---------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

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

.switcher {
  position: relative;
}

.switcher summary {
  cursor: pointer;
  color: var(--text);
  list-style: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.switcher summary::-webkit-details-marker {
  display: none;
}

.switcher ul {
  position: absolute;
  z-index: 10;
  margin: 6px 0 0;
  padding: 6px 0;
  list-style: none;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.switcher li a {
  display: block;
  padding: 8px 14px;
  color: var(--text);
  text-decoration: none;
}

.switcher li a[aria-current] {
  font-weight: 700;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tabs a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  position: relative;
}

.tabs a[aria-current] {
  color: var(--text);
}

.tabs svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabs a[aria-current] svg {
  stroke: var(--text);
}

.badge {
  position: absolute;
  top: -2px;
  left: calc(50% + 6px);
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 0.7rem;
  line-height: 18px;
  text-align: center;
  background: var(--accent);
  color: var(--bg);
}

/* --- The portfolio screen ---------------------------------------------------------------------- */

.name {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.total {
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0.25rem 0;
  font-variant-numeric: tabular-nums;
}

.total.stale,
tr.stale .price {
  color: var(--muted);
}

.stale-note,
.not-valued,
.change-note,
.excluded,
.small-hidden {
  color: var(--muted);
  font-size: 0.9rem;
}

.change {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.change .pct {
  margin-left: 8px;
}

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

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

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

.chart {
  margin: 12px 0 4px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart .line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.chart .line.up {
  stroke: var(--up);
}

.chart .line.down {
  stroke: var(--down);
}

.chart .gap {
  fill: var(--border);
  opacity: 0.45;
}

.chart .now {
  fill: var(--text);
}

.chart figcaption {
  color: var(--muted);
  font-size: 0.85rem;
}

.chart figcaption ul {
  margin: 4px 0;
  padding-left: 18px;
}

.periods {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin: 8px 0 16px;
}

.periods a {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.periods a[aria-current] {
  background: var(--surface);
  color: var(--text);
}

.sort {
  margin: 8px 0;
}

.sort summary {
  cursor: pointer;
  color: var(--muted);
}

.sort ul {
  list-style: none;
  padding: 0;
  margin: 4px 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.holdings {
  font-variant-numeric: tabular-nums;
}

.holdings th a {
  color: var(--muted);
  text-decoration: none;
}

.holdings .logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 8px;
}

.holdings .initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
}

.holdings .symbol {
  font-weight: 700;
}

.holdings .value,
.holdings .gain,
.holdings .pct {
  text-align: right;
}

/* Below 900 px: the bottom bar, two-line rows, no header row and no weight. */
.holdings thead {
  display: none;
}

.holdings tbody tr {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  grid-template-areas:
    "coin coin . value value"
    "qty price . gain pct";
  column-gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.holdings tbody td {
  border: 0;
  padding: 0;
}

.holdings .coin {
  grid-area: coin;
}

.holdings .qty {
  grid-area: qty;
  color: var(--muted);
  font-size: 0.85rem;
}

.holdings .price {
  grid-area: price;
  color: var(--muted);
  font-size: 0.85rem;
}

.holdings .value {
  grid-area: value;
  font-weight: 600;
}

.holdings .gain {
  grid-area: gain;
  font-size: 0.85rem;
}

.holdings .pct {
  grid-area: pct;
  font-size: 0.85rem;
}

.weight {
  display: none;
}

/* --- Wide screens ----------------------------------------------------------------------------- */

@media (min-width: 900px) {
  main {
    margin-left: 200px;
    padding: 24px 32px 48px;
  }

  .topbar {
    padding-left: 216px;
  }

  .tabs {
    top: 0;
    right: auto;
    width: 200px;
    flex-direction: column;
    justify-content: flex-start;
    gap: 4px;
    padding: 72px 12px 12px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }

  .tabs a {
    flex: none;
    flex-direction: row;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.95rem;
  }

  .tabs a[aria-current] {
    background: var(--bg);
  }

  .badge {
    position: static;
  }

  .sort {
    display: none;
  }

  .holdings thead {
    display: table-header-group;
  }

  .holdings tbody tr {
    display: table-row;
    padding: 0;
  }

  .holdings tbody td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }

  .holdings .qty,
  .holdings .price,
  .holdings .weight {
    text-align: right;
  }

  .holdings .qty,
  .holdings .price {
    color: inherit;
  }

  .holdings .qty,
  .holdings .price,
  .holdings .gain,
  .holdings .pct {
    font-size: inherit;
  }

  .weight {
    display: table-cell;
  }
}
