/* BBMA Tracker: hand-written dark theme. */
:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --sell: #f0616d;
  --sell-bg: rgba(240, 97, 109, 0.14);
  --buy: #3fcf8e;
  --buy-bg: rgba(63, 207, 142, 0.14);
  --accent: #58a6ff;
  --warn: #e3b341;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 0.6rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
small, .small { font-size: 0.8rem; }
code { font-family: var(--mono); background: var(--panel-2); padding: 0 0.3em; border-radius: 4px; }
.muted { color: var(--muted); }
.sell { --side: var(--sell); --side-bg: var(--sell-bg); }
.buy { --side: var(--buy); --side-bg: var(--buy-bg); }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.6rem 1rem;
  background: rgba(14, 17, 22, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand span { color: var(--accent); }
.scan-info { display: flex; gap: 0.4rem; align-items: center; flex: 1; flex-wrap: wrap; }
.scan-info time { font-family: var(--mono); }
.scan-age { color: var(--muted); font-size: 0.8rem; }
.scan-age.warn { color: var(--warn); }
.refresh-form { margin: 0; }

.btn {
  background: var(--accent);
  color: #0b1220;
  border: 0;
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { background: var(--panel-2); color: var(--muted); cursor: progress; }
.btn.small { padding: 0.25rem 0.6rem; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

/* iOS "Add to Home Screen" hint */
.install-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.hint-close { background: none; border: 0; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 0.25rem; }

.container { max-width: 1600px; margin: 0 auto; padding: 1rem; }
.footer { text-align: center; padding: 1.5rem 1rem; font-size: 0.8rem; }

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* Timeframe tabs */
.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; }
.tab {
  flex: 0 0 auto;
  padding: 0.45rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #0b1220; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active:hover { color: #0b1220; }

/* Recommendations */
.rec-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.6rem;
}
.rec {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--side, var(--border));
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}
.rec-head { display: flex; align-items: center; gap: 0.5rem; }
.rec-rank { color: var(--muted); font-family: var(--mono); }
.rec-pair { font-weight: 700; font-size: 1.05rem; }
.rec-score {
  margin-left: auto;
  font-family: var(--mono);
  font-weight: 700;
  background: var(--bg);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
}
.rec-next { margin: 0.45rem 0 0.25rem; }
.rec-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.chip.warn { color: var(--warn); }
.tier { font-family: var(--mono); font-weight: 700; font-size: 0.75rem; border-radius: 4px; padding: 0 0.35rem; border: 1px solid currentColor; }
.tier-a { color: var(--buy); }
.tier-b { color: var(--warn); }
.tier-c { color: var(--muted); }
.rec-why summary, .history summary { cursor: pointer; color: var(--muted); font-size: 0.8rem; }
.rec-why ul, .reasons { margin: 0.3rem 0 0; padding-left: 1rem; font-size: 0.82rem; }
.pts { display: inline-block; min-width: 2.2em; font-family: var(--mono); color: var(--accent); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: end; margin-bottom: 0.75rem; }
.filters label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.78rem; color: var(--muted); }
.filters label.check { flex-direction: row; align-items: center; gap: 0.35rem; padding-bottom: 0.4rem; }
.filters select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font: inherit;
}
.filters .count { margin-left: auto; padding-bottom: 0.4rem; }

/* Main table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}
.grid { width: 100%; border-collapse: collapse; min-width: 1250px; }
.grid th, .grid td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.grid thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}
.grid tbody tr:hover { background: rgba(88, 166, 255, 0.05); }
.grid .sticky { position: sticky; left: 0; background: var(--panel); z-index: 1; }
.grid thead .sticky { z-index: 2; background: var(--panel-2); }
.pair-cell a { font-weight: 700; display: block; }
.grid td.next { min-width: 220px; max-width: 320px; font-size: 0.85rem; }
tr.is-stale td, tr.is-stale th { opacity: 0.45; }
tr.is-invalid td { opacity: 0.6; }

.cell { display: flex; flex-direction: column; min-width: 100px; }
.cell.pending { color: var(--muted); }
.cell.note { font-size: 0.78rem; font-style: italic; }
.cell.done .cell-text { color: var(--side); font-weight: 600; white-space: nowrap; }
.cell-meta { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.cell-flag { font-size: 0.72rem; color: var(--warn); }

.trend { font-weight: 600; color: var(--side, var(--muted)); white-space: nowrap; }

/* Pills and badges */
.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--side, var(--muted));
  background: var(--side-bg, var(--panel-2));
  border: 1px solid var(--side, var(--border));
}
.pill-none { color: var(--muted); background: transparent; border-style: dashed; border-color: var(--border); }
.pill-invalidated { color: var(--muted); background: transparent; border-color: var(--border); text-decoration: line-through; }
.pill-csak, .pill-re_csak, .pill-csm, .pill-re_csm { color: #0b1220; background: var(--side); }
.pill.is-stale { color: var(--muted); background: transparent; border-color: var(--border); }

.badge {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.counter { color: var(--side); border-color: var(--side); }
.badge.status-active { color: var(--accent); border-color: var(--accent); }
.badge.status-invalidated { color: var(--sell); }

.age { font-family: var(--mono); font-size: 0.8rem; white-space: nowrap; }
.age-fresh { color: var(--buy); }
.age-aging { color: var(--warn); }
.age-stale { color: var(--muted); }

/* Pair page */
.pair-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 1rem; margin-bottom: 1rem; }
.pair-header h1 { margin: 0; }
.alignment { font-weight: 600; color: var(--side, var(--muted)); }
.topdown { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.6rem; }
.td-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.6rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.td-item:hover { text-decoration: none; border-color: var(--accent); }
.td-tf { font-weight: 700; font-size: 1.05rem; }
.tf-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; }
.kv { border-collapse: collapse; width: 100%; font-family: var(--mono); font-size: 0.85rem; }
.kv th { text-align: left; font-weight: 400; color: var(--muted); padding: 0.2rem 0.5rem 0.2rem 0; font-family: system-ui, sans-serif; }
.kv td { text-align: right; padding: 0.2rem 0; }
.next-box { background: var(--panel-2); border-radius: var(--radius); padding: 0.5rem 0.75rem; }

.cycle-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.cycle-head .badge { margin-top: 0; }
.cycle-sub { margin: 0.35rem 0; font-size: 0.82rem; }
.side-tag { font-weight: 700; color: var(--side); }
.timeline { list-style: none; margin: 0.5rem 0 0; padding: 0 0 0 0.9rem; border-left: 2px solid var(--border); }
.ev { position: relative; padding: 0.3rem 0 0.5rem 0.5rem; }
.ev::before {
  content: "";
  position: absolute;
  left: -1.3rem;
  top: 0.65rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--side, var(--muted));
}
.ev-main { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; align-items: baseline; }
.ev-stage { font-weight: 700; color: var(--side, var(--muted)); }
.ev-label { font-weight: 600; }
.ev-main time, .ev-price { font-family: var(--mono); font-size: 0.85rem; }
.ev-detail { font-family: var(--mono); font-size: 0.72rem; margin-top: 0.15rem; word-break: break-word; }
.history { margin-top: 1rem; }
.history-cycle { border-top: 1px dashed var(--border); padding-top: 0.6rem; margin-top: 0.6rem; }

@media (max-width: 760px) {
  body { font-size: 13px; }
  .container { padding: 0.6rem; }
  .topbar { padding: 0.5rem 0.6rem; }
  .scan-info { order: 3; flex-basis: 100%; font-size: 0.8rem; }
  .refresh-form { margin-left: auto; }
  .tabs { position: sticky; top: 4.6rem; z-index: 5; background: var(--bg); padding: 0.25rem 0; }
  .tab { flex: 1; text-align: center; padding: 0.5rem 0; }
  .tf-grid { grid-template-columns: 1fr; }
  .filters label { flex: 1 1 40%; }
  .filters .count { margin-left: 0; }
  .rec-list { grid-template-columns: 1fr; }
}

.chips { display: flex; flex-wrap: wrap; gap: 0.2rem; margin-top: 0.25rem; max-width: 9.5rem; }
.chip { font-size: 0.7rem; color: var(--side, var(--muted)); background: var(--side-bg, var(--panel-2)); border-radius: 4px; padding: 0 0.3rem; white-space: nowrap; }
.td-item .pill { align-self: flex-start; }

/* Bias mode */
:root { --v-support: #58a6ff; --v-neutral: #e3b341; --v-against: #db61a2; }
.v-support { --v: var(--v-support); }
.v-neutral { --v: var(--v-neutral); }
.v-against { --v: var(--v-against); }
.biasbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; margin-bottom: 1rem; }
.biasbar-label { color: var(--muted); font-size: 0.8rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg-item { padding: 0.4rem 0.85rem; color: var(--muted); font-weight: 600; border-left: 1px solid var(--border); }
.seg-item:first-child { border-left: 0; }
.seg-item:hover { text-decoration: none; color: var(--text); }
.seg-item.active { background: var(--accent); color: #0b1220; }
.seg-item.sell.active { background: var(--sell); }
.seg-item.buy.active { background: var(--buy); }
.verdict {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--v, var(--border));
  color: var(--v, var(--muted));
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.bias-summary { border-left: 4px solid var(--v, var(--border)); }
.bias-headline { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.3rem; }
.action { display: inline-block; margin-left: 0.4rem; padding: 0.05rem 0.5rem; border-radius: 4px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; background: var(--panel-2); border: 1px solid var(--border); vertical-align: middle; }
.action-add { color: var(--v-support); border-color: var(--v-support); }
.action-hold, .action-protect { color: var(--v-neutral); border-color: var(--v-neutral); }
.action-exit { color: var(--v-against); border-color: var(--v-against); }
.td-item.is-context { opacity: 0.6; }
.td-item .verdict { align-self: flex-start; }
.bias-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; margin-bottom: 0.5rem; }
.bias-head .badge { margin-top: 0; }
.bias-warning { background: rgba(219, 97, 162, 0.1); border: 1px solid var(--v-against); border-radius: var(--radius); padding: 0.5rem 0.75rem; margin: 0.5rem 0; }
.bias-warn-inline { color: var(--v-against); max-width: 260px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bias-cell { min-width: 160px; }
.bias-cell .verdict { margin-bottom: 0.2rem; }
.rec-bias { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.plan-zone { background: var(--side-bg, var(--panel-2)); border-left: 3px solid var(--side, var(--border)); border-radius: var(--radius); padding: 0.5rem 0.75rem; }
.plan-notes { margin: 0.3rem 0 0; padding-left: 1rem; }
.plan-h { margin: 0.8rem 0 0.3rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.plan-h.ok { color: var(--v-support); }
.plan-h.bad { color: var(--v-against); }
.plan-list { margin: 0; padding-left: 1.1rem; }
.plan-list li { margin-bottom: 0.3rem; }
.signals { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.signals li { padding: 0.2rem 0; border-bottom: 1px dashed var(--border); }
.signals time, .mono { font-family: var(--mono); }
.sig-name { font-weight: 600; }
.is-ended .timeline, .is-ended .cycle-sub { opacity: 0.7; }
tr.is-opposed td:not(.bias-cell), tr.is-ended td:not(.bias-cell) { opacity: 0.5; }
@media (max-width: 760px) {
  .seg-item { padding: 0.5rem 0.9rem; }
  .biasbar .seg { flex: 1 1 auto; }
  .biasbar .seg-item { flex: 1; text-align: center; }
}

/* Anchor / per-TF lifecycle strip */
.life-strip { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.45rem; padding: 0.4rem 0.55rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.life-strip.is-against { border-color: var(--v-against); }
.life-tf { font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.life-warn { color: var(--v-against); text-transform: none; letter-spacing: 0; }
.life { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; }
.life-alt { padding-top: 0.25rem; border-top: 1px dashed var(--border); }
.life-head { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }
.life-head .badge { margin-top: 0; }
.life-latest { font-family: var(--mono); color: var(--muted); }
.steps { display: flex; flex-wrap: wrap; gap: 0.15rem; list-style: none; margin: 0; padding: 0; font-size: 0.72rem; }
.step { padding: 0 0.3rem; border-radius: 4px; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
.step .tick { margin-left: 0.15rem; }
.step.done { color: var(--side, var(--text)); background: var(--side-bg, var(--panel-2)); font-weight: 600; }
.step[title] { text-decoration: underline dotted; }
.life-rows { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.6rem 0; }
.life-row { color: var(--text); }
.life-row:hover { text-decoration: none; }
.life-row:hover .life-strip { border-color: var(--accent); }
.life-row .life-strip { margin-top: 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.75rem; }
.life-row .life-tf { min-width: 2.6rem; font-size: 0.9rem; color: var(--text); }
.anchor-td { min-width: 9rem; max-width: 12rem; }
.anchor-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; }
.anchor-meta { display: block; line-height: 1.3; }
.anchor-cell.is-against .pill { outline: 1px dashed var(--v-against); outline-offset: 1px; }
@media (max-width: 760px) {
  .life-row .life-strip { flex-direction: column; align-items: flex-start; }
  .anchor-td { min-width: 7.5rem; max-width: 9rem; }
  .anchor-meta { font-size: 0.72rem; }
}

/* Auth pages */
.auth { max-width: 420px; margin: 2rem auto; }
.auth form { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; }
.auth input { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.6rem; }
.auth input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-error { color: var(--sell); }
.auth-notice { color: var(--buy); }
.auth-resend { margin-top: 0; }
.user-menu { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
