/*
 * Market engine components: tables, coin masthead, charts, signals, calculators.
 * Loaded only on the routes and pages that use them.
 *
 * Every class here was checked against style.css first — none of these names
 * already exist, so nothing in this file silently restyles another template.
 */

/* ------------------------------------------------------------------ tables */

.tb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.tb-table th,
.tb-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--tb-border);
  text-align: left;
  vertical-align: middle;
}

.tb-table thead th {
  background: var(--tb-surface);
  font-family: var(--tb-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--tb-muted);
  white-space: nowrap;
}

.tb-table tbody tr:hover { background: var(--tb-surface); }

.tb-num {
  font-family: var(--tb-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.tb-table thead th.tb-num { text-align: right; }

.tb-up { color: var(--tb-bull); }
.tb-down { color: var(--tb-bear); }

.tb-table__coin {
  display: inline-flex;
  align-items: center;
  gap: var(--tb-2, 8px);
  font-weight: 600;
  color: var(--tb-text);
  min-width: 0;
}

.tb-table__coin:hover { color: var(--tb-link); }

.tb-table__sym {
  font-family: var(--tb-mono);
  font-size: 12px;
  color: var(--tb-muted);
  font-weight: 400;
}

/* Marks are decorative and sized inline, so they hold their box before CSS. */
.tb-coinmark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 999px;
  color: #fff;
  font-family: var(--tb-display);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

/* --------------------------------------------------------- coin masthead */

.tb-coinhead {
  display: grid;
  gap: var(--tb-5, 24px);
  grid-template-columns: minmax(0, 1fr);
  background: var(--tb-card);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-lg);
  padding: var(--tb-5, 24px);
  margin-block: var(--tb-5, 24px);
}

@media (min-width: 900px) {
  .tb-coinhead { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; column-gap: 32px; }
  .tb-coinhead__main { grid-area: 1 / 1; }
  .tb-coinhead__chart { grid-area: 1 / 2; }
  /* 🔴 .tb-coinhead .tb-coinhead__stats, not .tb-coinhead__stats. The generic
     .tb-statgrid rule further down this file sets auto-fit/minmax(190px) and a
     media query adds NO specificity, so at equal weight the LATER rule won and
     forced 3 columns with the fourth card orphaned on its own row. */
  .tb-coinhead .tb-coinhead__stats { grid-area: 2 / 1 / auto / -1; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tb-coinhead__trust { grid-area: 3 / 1 / auto / -1; }
  /* No Binance history means no chart element at all, so the second column
     would otherwise sit empty and the masthead would read as broken. */
  .tb-coinhead--nochart .tb-coinhead__main { grid-area: 1 / 1 / auto / -1; }
}

.tb-coinhead__id { display: flex; align-items: center; gap: 12px; }
.tb-coinhead__name { font-family: var(--tb-display); font-size: 26px; font-weight: 700; margin: 0; line-height: 1.1; }
.tb-coinhead__sym { font-family: var(--tb-mono); font-size: 13px; color: var(--tb-muted); margin: 2px 0 0; }

.tb-coinhead__price {
  font-family: var(--tb-display);
  font-size: 40px;
  font-weight: 700;
  margin: 16px 0 4px;
  line-height: 1;
}

.tb-coinhead__chg {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  font-family: var(--tb-mono); font-size: 15px; font-weight: 600; margin: 0;
}

.tb-coinhead__chglab { font-size: 11px; color: var(--tb-muted); font-weight: 400; margin-right: 12px; }
.tb-coinhead__chart { min-width: 0; }
.tb-coinhead__chartlab {
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--tb-muted); font-weight: 600; margin: 0 0 8px;
}

.tb-coinhead__trust { font-size: 12px; color: var(--tb-muted); margin: 16px 0 0; }
.tb-coinhead__trust a { color: var(--tb-muted); text-decoration: underline; }

/* Range bar --------------------------------------------------------------- */

.tb-rangebar { margin: 16px 0 0; }
.tb-rangebar__lab {
  display: flex; justify-content: space-between; gap: 12px;
  font-family: var(--tb-mono); font-size: 11px; color: var(--tb-muted); margin: 0 0 8px;
}
.tb-rangebar__t { text-transform: uppercase; letter-spacing: .07em; }
.tb-rangebar__track {
  position: relative; height: 6px; border-radius: 999px;
  background: linear-gradient(90deg, var(--tb-bear), var(--tb-surface) 50%, var(--tb-bull));
}
.tb-rangebar__dot {
  position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 999px;
  background: var(--tb-text); border: 2px solid var(--tb-card); transform: translate(-50%, -50%);
}

/* ------------------------------------------------------------------- stats */

.tb-statgrid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  margin-block: var(--tb-5, 24px);
}

.tb-stat {
  background: var(--tb-card);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
  padding: 16px;
}

.tb-stat__k {
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--tb-muted); margin: 0 0 8px; font-weight: 600;
}
.tb-stat__v { font-family: var(--tb-display); font-size: 22px; font-weight: 700; margin: 0; line-height: 1.15; }
.tb-stat__d { font-size: 12px; color: var(--tb-muted); margin: 6px 0 0; }

/* ------------------------------------------------------------------ charts */

.tb-chart { display: block; width: 100%; height: auto; }
.tb-chart__line { stroke: currentColor; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.tb-chart__bar { fill: currentColor; opacity: .68; }
.tb-chart__grid { stroke: var(--tb-border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tb-chart__ylab {
  font-family: var(--tb-mono); font-size: 10px; fill: var(--tb-muted);
  /* Labels sit in the right-hand gutter reserved by the SVG padding, so they
     are never clipped by the viewBox the way an inside-the-plot label is. */
}

.tb-chart--up { color: var(--tb-bull); }
.tb-chart--down { color: var(--tb-bear); }
.tb-chart--neutral { color: var(--tb-muted); }
.tb-chart--bars { color: var(--tb-brand-deep); }

.tb-chartbox {
  background: var(--tb-card);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
  padding: 16px;
  margin-bottom: 16px;
}

.tb-chartbox__lab {
  font-family: var(--tb-display); font-size: 14px; font-weight: 700;
  margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
}
.tb-chartbox__lab span { font-family: var(--tb-mono); font-size: 11px; font-weight: 400; color: var(--tb-muted); }
.tb-chartbox__note { font-size: 13px; color: var(--tb-muted); margin: 10px 0 0; }

/* ----------------------------------------------------------------- signals */

.tb-siglist { list-style: none; margin: 0 0 16px; padding: 0; }

.tb-siglist li {
  display: flex; gap: 12px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--tb-border);
}

.tb-sigtag {
  flex: 0 0 auto;
  font-family: var(--tb-display); font-size: 11px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px;
  background: var(--tb-surface); border: 1px solid var(--tb-border); color: var(--tb-muted);
}
.tb-sigtag--up { color: var(--tb-bull); }
.tb-sigtag--down { color: var(--tb-bear); }
.tb-siglist__t { font-size: 15px; }

/* ------------------------------------------------------------- misc chrome */

.tb-chiprow { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.tb-chip--coins { color: #7D5107; }

.tb-article__stand { font-size: 19px; line-height: 1.55; color: var(--tb-muted); margin-bottom: 20px; }

.tb-stale { font-size: 12px; color: var(--tb-muted); margin-top: 12px; }
.tb-stale a { color: var(--tb-muted); text-decoration: underline; }

.tb-markets__links { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 24px; }

/* -------------------------------------------------------------- calculators */

.tb-calc {
  background: var(--tb-card);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
  padding: 20px;
}

.tb-calc__grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.tb-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.tb-field > span {
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--tb-muted);
}

.tb-field input,
.tb-field select {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--tb-mono);
  font-size: 15px;
  color: var(--tb-text);
  background: var(--tb-bg);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-sm);
}

.tb-field input:focus,
.tb-field select:focus { outline: 2px solid var(--tb-brand); outline-offset: 1px; }

.tb-calc__note { font-size: 13px; color: var(--tb-muted); margin: 14px 0 0; }

.tb-calc__out {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-top: 18px; padding-top: 18px;
  border-top: 1px solid var(--tb-border);
}

.tb-out__k {
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--tb-muted); margin: 0 0 6px; font-weight: 600;
}
.tb-out__v { font-family: var(--tb-display); font-size: 22px; font-weight: 700; margin: 0; line-height: 1.15; }

/* Mobile: let wide market tables become readable cards rather than a
   horizontal scroll nobody discovers. The wrapper still scrolls above this
   breakpoint, so desktop keeps a real table. */
@media (max-width: 640px) {
  .tb-table--markets thead { display: none; }
  .tb-table--markets,
  .tb-table--markets tbody,
  .tb-table--markets tr,
  .tb-table--markets th,
  .tb-table--markets td { display: block; width: 100%; }

  .tb-table--markets tr {
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius);
    background: var(--tb-card);
    padding: 12px 14px;
    margin-bottom: 12px;
  }

  .tb-table--markets td,
  .tb-table--markets th { border-bottom: 0; padding: 3px 0; text-align: left; }

  .tb-table--markets td[data-label]::before {
    content: attr(data-label) " ";
    font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--tb-muted); font-weight: 600; margin-right: 6px;
  }
}

/* --------------------------------------------------------- lang switcher */

.tb-langsw { position: relative; display: inline-block; }

.tb-langsw__btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; cursor: pointer; list-style: none;
  font: 700 11px/1 var(--tb-mono); letter-spacing: .03em;
  color: var(--tb-chrome-text);
  border: 1px solid var(--tb-chrome-border); border-radius: 999px;
}
.tb-langsw__btn::-webkit-details-marker { display: none; }
.tb-langsw__flag { font-size: 14px; line-height: 1; }

.tb-langsw__menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  min-width: 180px; margin: 0; padding: 6px; list-style: none;
  background: var(--tb-card); border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-sm); box-shadow: var(--tb-shadow-lg);
}
.tb-langsw__menu li { margin: 0; }

.tb-langsw__row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px;
  color: var(--tb-text); font-size: 14px; line-height: 1.3;
}
.tb-langsw__row:hover { background: var(--tb-surface); }
.tb-langsw__row--active { color: var(--tb-brand-deep); font-weight: 700; }
