/* =========================================================================
   terminal.css - the Chrysofi Market Terminal (/markets/terminal).
   Fully first-party modules (no third-party frames). Everything is prefixed
   .term-/.tvw/.cs- and themed from the global tokens in css/variables.css,
   so light/dark/accent presets apply for free. The chart is a canvas engine
   (KLineChart) so page CSS can never break it; its colors come from JS.
   ========================================================================= */

/* ---------- Ticker tape (seamless marquee under the header) ---------- */
.term-tape {
  height: 44px; overflow: hidden;
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center;
}
.term-tape__track {
  display: inline-flex; align-items: center; white-space: nowrap;
  will-change: transform; animation: term-marquee 60s linear infinite;
}
.term-tape:hover .term-tape__track { animation-play-state: paused; }
.term-tape__item { padding: 0 1.4rem; font-size: .84rem; color: var(--color-text); border-right: 1px solid var(--color-border); }
.term-tape__item b { color: var(--color-heading); font-weight: 700; }
.term-tape__item .up { color: #2e9e5b; font-weight: 600; }
.term-tape__item .down { color: #cf5b5b; font-weight: 600; }
@keyframes term-marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .term-tape__track { animation: none; } }

.term-hero-actions { margin-top: 1.2rem; display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* ---------- Symbol switcher ---------- */
.term-symbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1.25rem; }
.term-chip {
  padding: .48rem .95rem; border-radius: var(--radius-full); border: 1.5px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: all var(--transition);
}
.term-chip:hover { border-color: var(--color-accent); color: var(--color-accent-deep); }
.term-chip.is-on { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
.term-sel {
  padding: .48rem .8rem; border-radius: var(--radius-full); border: 1.5px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer; max-width: 180px;
}
.term-sel:focus-visible { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 26%, transparent); }

/* ---------- Layout ---------- */
.term-wrap { display: grid; gap: 1.25rem; }
.term-grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1080px) { .term-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, 372px); align-items: stretch; } }
.term-rail { display: grid; gap: 1.25rem; align-content: start; }
.term-duo { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }

/* ---------- Card shell ---------- */
.tvw { display: flex; flex-direction: column; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.tvw__head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .85rem 1.15rem; border-bottom: 1px solid var(--color-border); }
.tvw__title { margin: 0; font-family: var(--font-head); font-size: .95rem; font-weight: 700; color: var(--color-heading); }
.tvw__hint { font-size: .78rem; color: var(--color-text-muted); white-space: nowrap; }
.tvw__hint b { color: var(--color-accent-deep); }
.tvw__price { font-variant-numeric: tabular-nums; color: var(--color-heading); font-weight: 700; margin-left: .35rem; }
.tvw__ctl { display: flex; align-items: center; gap: .6rem; padding: .6rem 1.15rem; border-bottom: 1px solid var(--color-border); flex-wrap: wrap; }
.tvw__ctl-sp { flex: 1 1 auto; }
.term-mini-link { font-size: .78rem; font-weight: 700; color: var(--color-accent-deep); white-space: nowrap; }
.tvw__foot { padding: .6rem 1.15rem; border-top: 1px solid var(--color-border); background: color-mix(in srgb, var(--color-border) 18%, transparent); font-size: .74rem; line-height: 1.5; color: var(--color-text-muted); }
.tvw__foot a { color: var(--color-accent-deep); font-weight: 600; }
.tvw__body { position: relative; flex: 1 1 auto; contain: layout style paint; }

.tvw__body--chart { min-height: 520px; }
.tvw__body--gauge { min-height: 326px; }
.tvw__body--senti { min-height: 286px; }
.tvw__body--movers { min-height: 340px; }
.tvw__body--hours { min-height: 340px; }
.tvw__body--heat { min-height: 300px; }
@media (max-width: 600px) { .tvw__body--chart { min-height: 420px; } }

/* ---------- Chart + watermark + status ---------- */
.term-chart { position: absolute; inset: 0; }
/* CHRYSOFI wordmark INSIDE the chart (centered, faint, non-interactive) */
.term-watermark {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 3;
  width: min(360px, 46%); height: 62px;
  background-image: var(--logo-img); background-repeat: no-repeat; background-position: center; background-size: contain;
  opacity: .09; pointer-events: none;
}
.tvw__body:not(.is-live) .term-watermark { opacity: 0; }
.cs-status {
  position: absolute; top: .55rem; right: .6rem; z-index: 5;
  display: inline-flex; align-items: center; gap: .35rem; padding: .22rem .6rem;
  border-radius: var(--radius-full); border: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 82%, transparent);
  font-size: .7rem; font-weight: 700; color: var(--color-text-muted);
}
.cs-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--color-text-muted); }
.cs-status.is-live { color: #2e9e5b; } .cs-status.is-live .dot { background: #2e9e5b; box-shadow: 0 0 0 3px color-mix(in srgb, #2e9e5b 22%, transparent); }
.cs-status.is-poll .dot { background: #e0a52e; }
.cs-status.is-off .dot { background: #cf5b5b; }

/* Loading skeleton for canvas + JS modules */
.tvw__body--chart::before, .tvw__body--chart::after { content: ""; }
.tvw__body--chart::before {
  position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(100deg, transparent 32%, color-mix(in srgb, var(--color-border) 55%, transparent) 50%, transparent 68%), var(--color-surface-2);
  background-size: 220% 100%, auto; animation: term-sheen 1.5s linear infinite;
}
.tvw__body--chart::after { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; content: "Loading candles..."; font-size: .85rem; color: var(--color-text-muted); }
.tvw__body--chart.is-live::before, .tvw__body--chart.is-live::after { content: none; }
@keyframes term-sheen { to { background-position: -120% 0, 0 0; } }
@media (prefers-reduced-motion: reduce) { .tvw__body--chart::before { animation: none; } }

/* ---------- Interval segmented control (shared look) ---------- */
.cs-seg { display: inline-flex; border: 1.5px solid var(--color-border); border-radius: var(--radius-full); overflow: hidden; }
.cs-seg button { padding: .4rem .7rem; border: none; background: transparent; font: inherit; font-size: .78rem; font-weight: 700; color: var(--color-text-muted); cursor: pointer; transition: all var(--transition); }
.cs-seg button + button { border-left: 1px solid var(--color-border); }
.cs-seg button:hover { color: var(--color-accent-deep); }
.cs-seg button.is-on { background: var(--color-accent); color: var(--color-on-accent); }

/* ---------- Signal gauge (shared with Chart Studio) ---------- */
.cs-gauge { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; padding: 1.1rem 1.15rem 1.3rem; min-height: 326px; }
.cs-gauge-svg { width: 280px; max-width: 100%; height: auto; display: block; }
.cs-gauge-svg .cs-arc { fill: none; stroke-width: 15; stroke-linecap: round; }
.cs-gauge-svg .cs-needle { stroke: var(--color-heading); stroke-width: 4; stroke-linecap: round; }
.cs-gauge-svg .cs-arc--track { stroke-linecap: round; }
.cs-gauge-svg .cs-hub { fill: var(--color-accent); stroke: var(--color-surface); stroke-width: 2.5; }
.cs-gauge-svg .cs-gauge-tick { fill: var(--color-text-muted); font-size: 11px; font-weight: 700; font-family: var(--font-head); }
.cs-gauge-read { text-align: center; }
.cs-gauge-label { display: block; font-family: var(--font-head); font-weight: 800; font-size: 1.35rem; }
.cs-gauge-sub { display: block; font-size: .78rem; color: var(--color-text-muted); margin-top: .1rem; }
.cs-gauge-counts { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; margin-top: .3rem; }
.cs-gc { display: inline-flex; flex-direction: column; align-items: center; min-width: 58px; padding: .4rem .6rem; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; color: var(--color-text-muted); }
.cs-gc b { font-size: 1.05rem; font-weight: 800; color: var(--color-heading); font-variant-numeric: tabular-nums; line-height: 1.1; }
.cs-gc--sell b { color: #cf5b5b; } .cs-gc--buy b { color: #2e9e5b; } .cs-gc--neutral b { color: var(--color-accent-deep); }
.cs-gauge-empty { display: grid; place-items: center; min-height: 200px; padding: 1.5rem; color: var(--color-text-muted); font-size: .9rem; text-align: center; }

/* ---------- Crowd sentiment ---------- */
.senti-wrap { padding: 1.05rem 1.15rem 1.2rem; }
.senti-top { display: flex; align-items: baseline; gap: .6rem; }
.senti-val { font-family: var(--font-head); font-size: 2.1rem; font-weight: 800; color: var(--color-heading); font-variant-numeric: tabular-nums; }
.senti-class { font-weight: 700; font-size: .9rem; }
.senti-class.is-bull { color: #2e9e5b; } .senti-class.is-bear { color: #cf5b5b; } .senti-class.is-mid { color: var(--color-accent-deep); }
.senti-bar { position: relative; height: 12px; border-radius: 999px; background: linear-gradient(90deg, #cf5b5b, #e0a52e, #2e9e5b); margin: .95rem 0 .5rem; }
.senti-bar__pin { position: absolute; top: 50%; transform: translate(-50%, -50%); width: 18px; height: 18px; border-radius: 50%; background: var(--color-surface); border: 3px solid var(--color-heading); box-shadow: var(--shadow-sm); }
.senti-split { display: flex; justify-content: space-between; font-size: .78rem; font-weight: 700; }
.senti-split .senti-bear { color: #cf5b5b; } .senti-split .senti-bull { color: #2e9e5b; }
.senti-deltas { display: flex; gap: 1.1rem; margin-top: .8rem; font-size: .8rem; color: var(--color-text-muted); flex-wrap: wrap; }
.senti-deltas b { font-variant-numeric: tabular-nums; } .senti-deltas b.up { color: #2e9e5b; } .senti-deltas b.down { color: #cf5b5b; }
.senti-spark { margin-top: .9rem; } .senti-spark svg { width: 100%; height: 54px; display: block; }
.senti-cap { margin: .5rem 0 0; font-size: .74rem; color: var(--color-text-muted); }
.senti-err { padding: 1rem 0; color: var(--color-text-muted); font-size: .9rem; }

/* ---------- Top movers ---------- */
.tvw__body--movers { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
@media (max-width: 460px) { .tvw__body--movers { grid-template-columns: 1fr; } }
.term-mv-col { padding: .6rem .8rem 1rem; }
.term-mv-col + .term-mv-col { border-left: 1px solid var(--color-border); }
@media (max-width: 460px) { .term-mv-col + .term-mv-col { border-left: none; border-top: 1px solid var(--color-border); } }
.term-mv-h { font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; font-weight: 700; padding: .3rem .2rem .5rem; }
.term-mv-h.up { color: #2e9e5b; } .term-mv-h.down { color: #cf5b5b; }
.term-mv-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .5rem; width: 100%; padding: .5rem .2rem; background: none; border: none; border-top: 1px solid var(--color-border); cursor: pointer; text-align: left; font: inherit; }
.term-mv-row:hover { background: color-mix(in srgb, var(--color-accent) 6%, transparent); }
.term-mv-name { font-weight: 700; color: var(--color-heading); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-mv-price { font-size: .8rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.term-mv-chg { font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 62px; text-align: right; }
.term-mv-chg.up { color: #2e9e5b; } .term-mv-chg.down { color: #cf5b5b; }

/* ---------- World market hours ---------- */
.term-hours-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; padding: 1rem 1.15rem 1.2rem; }
.term-hour { border: 1px solid var(--color-border); border-radius: var(--radius); padding: .7rem .8rem; }
.term-hour__city { font-weight: 700; color: var(--color-heading); font-size: .9rem; }
.term-hour__mkt { font-size: .72rem; color: var(--color-text-muted); }
.term-hour__time { font-size: 1.25rem; font-weight: 700; color: var(--color-heading); font-variant-numeric: tabular-nums; margin-top: .25rem; }
.term-hour__st { display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; font-weight: 700; margin-top: .2rem; }
.term-hour__st .dot { width: 7px; height: 7px; border-radius: 50%; }
.term-hour__st.open { color: #2e9e5b; } .term-hour__st.open .dot { background: #2e9e5b; box-shadow: 0 0 0 3px color-mix(in srgb, #2e9e5b 22%, transparent); }
.term-hour__st.closed { color: var(--color-text-muted); } .term-hour__st.closed .dot { background: var(--color-text-muted); }
.term-hour__st.always { color: var(--color-accent); } .term-hour__st.always .dot { background: var(--color-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 22%, transparent); }

/* ---------- Currency heatmap ---------- */
.term-heat-wrap { overflow-x: auto; padding: 1rem 1.15rem 1.2rem; -webkit-overflow-scrolling: touch; }
.term-heat { border-collapse: collapse; width: 100%; min-width: 460px; font-variant-numeric: tabular-nums; }
.term-heat th, .term-heat td { padding: .5rem .4rem; text-align: center; font-size: .8rem; border: 1px solid var(--color-border); }
.term-heat thead th { color: var(--color-text-muted); font-weight: 700; background: color-mix(in srgb, var(--color-border) 20%, transparent); }
.term-heat .term-heat-row { color: var(--color-heading); font-weight: 800; background: color-mix(in srgb, var(--color-border) 20%, transparent); }
.term-heat td { color: var(--color-heading); font-weight: 600; }
.term-heat .term-heat-diag { color: var(--color-text-muted); background: color-mix(in srgb, var(--color-border) 12%, transparent); }

/* ---------- Prose ---------- */
.term-about p { color: var(--color-text-muted); font-size: .95rem; line-height: 1.7; max-width: 760px; }
.term-about p + p { margin-top: .9rem; }
.term-about a { color: var(--color-accent-deep); font-weight: 600; }
.term-note { margin-top: 1rem; font-size: .85rem; color: var(--color-text-muted); }
