:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --border: #e3e7ec;
  --grid: #eef1f4;
  --accent: #2f6fdf;
  --accent-soft: rgba(47, 111, 223, 0.08);
  --up: #1a8a4a;
  --up-soft: #e3f5ea;
  --down: #c8382e;
  --down-soft: #fbe7e5;
  --neutral-soft: #eceff3;
  --series-2: #d9822b;
  --series-3: #7b5cc4;
  --warn-soft: #fff4e0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1b2028;
    --text: #e6e9ee;
    --muted: #9099a6;
    --border: #2a313b;
    --grid: #232a33;
    --accent: #6b9cf5;
    --accent-soft: rgba(107, 156, 245, 0.12);
    --up: #4cc27f;
    --up-soft: #173525;
    --down: #ef6b61;
    --down-soft: #3a1d1b;
    --neutral-soft: #262c35;
    --series-2: #f0a050;
    --series-3: #a58cf0;
    --warn-soft: #3a2f1a;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: baseline;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 20px; color: var(--text); }
.rule { color: var(--muted); font-size: 13px; }

main { max-width: 1600px; margin: 0 auto; padding: 24px 16px 48px; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; background: var(--neutral-soft); }
.msg.success { background: var(--up-soft); }
.msg.error, .msg.warning { background: var(--down-soft); }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile.buy { border-color: var(--up); background: var(--up-soft); }
.tile-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-num.small { font-size: 18px; }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-label b { margin-left: 4px; }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.add-form, .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }

input[type=text], textarea {
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}
input[type=text] { width: 180px; text-transform: uppercase; }
textarea { width: 100%; resize: vertical; margin-bottom: 10px; }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: var(--card); color: var(--accent); }
button.danger { background: var(--card); color: var(--down); border-color: var(--down); }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.filters a { padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); color: var(--text); font-size: 14px; }
.filters a span { color: var(--muted); margin-left: 4px; }
.filters a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filters a.active span { color: #fff; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
tr.row-buy { background: var(--up-soft); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.symbol { font-weight: 700; }
.name { color: var(--muted); font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--neutral-soft); color: var(--muted); vertical-align: middle; }
.badge.buy { background: var(--up); color: #fff; }
.badge.falling { background: var(--down-soft); color: var(--down); }

.empty { padding: 32px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--border); border-radius: 10px; }

.back { display: inline-block; margin-bottom: 12px; }
.detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-head h1 { margin: 0; font-size: 28px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 10px; font-size: 16px; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  input[type=text] { width: 140px; }
}

/* Buyers vs sellers bar: green share = volume on up days */
.pressure { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pressure-bar { width: 60px; height: 6px; border-radius: 3px; background: var(--down); overflow: hidden; flex-shrink: 0; }
.pressure-bar span { display: block; height: 100%; background: var(--up); }
.pressure-bar.wide { width: 100%; max-width: 220px; margin: 6px 0 2px; }

.table-wrap.flat { border: none; border-radius: 0; }

.fund-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.fund-grid .card { margin-bottom: 0; }
.facts { margin: 0; display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 10px 12px; }
.facts dt { color: var(--muted); font-size: 13px; padding-top: 2px; }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.facts dd small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 2px; }
.facts dd small.inline { display: inline; }
.rec { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--neutral-soft); font-size: 13px; }

.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.chart-head .filters { margin-bottom: 0; }
.ranges a { padding: 4px 10px; font-size: 13px; }
.period { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 14px; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .period { align-items: flex-start; } }

.filter-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.filter-bar .filters { margin-bottom: 0; }
.finders { display: flex; gap: 8px; flex-wrap: wrap; }
.finders form { margin: 0; }
select, input[type=search] {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}
input[type=search] { width: 200px; }
button:disabled { opacity: 0.6; cursor: wait; }

/* Navigation & page headers */
.mainnav { display: flex; flex-wrap: wrap; gap: 4px; }
.mainnav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.mainnav a:hover { background: var(--neutral-soft); color: var(--text); }
.mainnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar { align-items: center; }
.lead { color: var(--muted); margin: 0 0 16px; max-width: 760px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; }
.page-head h1 { margin: 0 0 6px; font-size: 26px; }
.asof { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.6; }
.mode-note { margin: -4px 0 12px; }
.disclaimer { max-width: 1600px; margin: 0 auto; padding: 0 16px 32px; font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

/* Dense sortable tables */
table.dense th, table.dense td { padding: 8px 10px; font-size: 13px; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--text); }
th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
.badge.small { font-size: 10px; padding: 1px 6px; margin-left: 4px; }
td.why { white-space: normal; min-width: 240px; font-size: 12px; line-height: 1.4; }
.score-cell { display: inline-flex; align-items: center; gap: 6px; }
.score-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 18px; }
.score-bars span { width: 4px; min-height: 1px; background: var(--accent); border-radius: 1px; }

/* Score on the stock page */
.score-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.score-total { display: flex; align-items: center; gap: 10px; }
.score-num { font-size: 44px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; margin-bottom: 8px; }
.score-card h2 { margin: 16px 0 8px; font-size: 15px; }
.flags { list-style: none; margin: 0 0 8px; padding: 10px 14px; background: var(--warn-soft); border-radius: 8px; font-size: 14px; }
.flags li + li { margin-top: 4px; }
.flags.notes { background: var(--neutral-soft); font-size: 13px; color: var(--muted); }
.checks { list-style: none; padding: 0; margin: 0; font-size: 14px; line-height: 1.9; }
.category { border-bottom: 1px solid var(--border); padding: 8px 0; }
.category summary { display: grid; grid-template-columns: 1fr 120px 48px; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.category summary b { text-align: right; font-variant-numeric: tabular-nums; }
.category .bar { height: 8px; border-radius: 4px; background: var(--neutral-soft); overflow: hidden; }
.category .bar span { display: block; height: 100%; background: var(--accent); }
.category ul { list-style: none; padding: 6px 0 0 4px; margin: 0; font-size: 13px; line-height: 1.7; }

/* Forms */
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 600; }
.field input:not([type=checkbox]):not([type=radio]), .field select { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); }
.field label.check { font-weight: 400; }
.settings-form h2 { margin: 20px 0 8px; font-size: 16px; }
.entry-form .field-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.entry-form button { margin-top: 4px; }
.link-button { background: none; border: none; padding: 0; color: var(--down); font-size: 13px; cursor: pointer; }
tr.move td { color: var(--muted); }
.settings-form h2:first-of-type { margin-top: 0; }
.settings-form button { margin-top: 12px; }
input.tickers { text-transform: uppercase; }

/* Backtest */
table.metrics td:first-child { color: var(--muted); }
.runs { padding-left: 18px; margin: 0; line-height: 1.9; font-size: 14px; }
.runs a.active { font-weight: 700; }
#equityChart { margin-top: 16px; }

.risk { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.risk.low { background: var(--up-soft); color: var(--up); }
.risk.medium { background: var(--warn-soft); color: var(--series-2); }
.risk.high { background: var(--down-soft); color: var(--down); }
.rank-bars span:nth-child(2) { background: var(--series-2); }
.rank-bars span:nth-child(3) { background: var(--up); }

.account-menu { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.account-menu form { margin: 0; }
.account-menu button { padding: 5px 10px; }
.auth-card { max-width: 380px; margin: 40px auto; }
.auth-card .field { margin-bottom: 12px; }
.auth-card button { width: 100%; margin: 4px 0 12px; }
.currency-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.currency-switch button { border: 0; border-radius: 0; padding: 5px 10px; background: var(--card); color: var(--muted); font-size: 13px; }
.currency-switch button.active { background: var(--accent); color: #fff; font-weight: 600; }
.fx-rate { font-size: 13px; white-space: nowrap; }
.chart-help { margin: 8px 0 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chart-help button { padding: 3px 10px; font-size: 13px; }
#priceChart { touch-action: pan-y; cursor: grab; }

/* Progress of Refresh all prices / Load lists: big, tinted and pinned to the top while scrolling. */
.job-progress {
  position: sticky; top: 12px; z-index: 20;
  margin-bottom: 16px; padding: 18px 20px;
  background: var(--card); background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
  border: 2px solid var(--accent); border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.job-progress[hidden] { display: none; }
.job-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.job-text { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.job-text strong { font-size: 18px; }
.job-text span { font-size: 15px; color: var(--text); }
.job-numbers { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.job-pct { font-size: 30px; font-weight: 700; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.job-time { font-size: 13px; color: var(--muted); white-space: nowrap; }
.job-spinner {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 4px solid var(--accent-soft); border-top-color: var(--accent);
  animation: job-spin 0.9s linear infinite;
}
.job-bar { height: 18px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.job-bar span {
  display: block; height: 100%; width: 0; border-radius: 999px; background-color: var(--accent);
  background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.22) 25%, transparent 25%, transparent 50%,
    rgba(255, 255, 255, 0.22) 50%, rgba(255, 255, 255, 0.22) 75%, transparent 75%, transparent);
  background-size: 28px 28px;
  animation: job-stripes 0.8s linear infinite;
  transition: width 0.4s;
}
.job-bar span.busy { opacity: 0.45; }
.job-note { margin-top: 10px; font-size: 13px; color: var(--muted); }
@keyframes job-spin { to { transform: rotate(360deg); } }
@keyframes job-stripes { to { background-position: 28px 0; } }
@media (prefers-reduced-motion: reduce) {
  .job-spinner, .job-bar span { animation: none; }
}
@media (max-width: 600px) {
  .job-pct { font-size: 24px; }
  .job-text strong { font-size: 16px; }
}
