/* =========================================================================
   chart.css - scoped styles for /markets/chart (the Chrysofi Chart Studio,
   the site's own candlestick chart with drawing tools). Everything is
   prefixed .cs- so nothing leaks in or out; colors come from the global
   theme tokens so light/dark/accent presets apply automatically.
   The chart engine is the self-hosted KLineChart bundle in js/vendor/
   (canvas-based: it cannot be broken by page CSS, and its own colors are
   set from JS reading the same tokens).
   ========================================================================= */

/* ---------- Card shell (same visual language as the terminal cards) ---------- */
.cs-card {
  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;
}
.cs-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);
}

/* ---------- Top control rows ---------- */
.cs-top { display: grid; gap: .55rem; padding: .8rem 1rem; border-bottom: 1px solid var(--color-border); }
.cs-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.cs-spacer { flex: 1 1 auto; min-width: .25rem; }

.cs-chip {
  padding: .42rem .85rem;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit; font-size: .8rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  transition: all var(--transition);
}
.cs-chip:hover { border-color: var(--color-accent); color: var(--color-accent-deep); }
.cs-chip.is-on { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }

.cs-sel {
  padding: .42rem .7rem;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit; font-size: .8rem; font-weight: 700;
  cursor: pointer; max-width: 170px;
}
.cs-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); }

/* Segmented controls (interval + chart type) */
.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); }

/* ---------- Popovers (indicator picker + chart settings) ---------- */
.cs-pop {
  position: fixed; z-index: 60; display: none;
  width: 340px; max-width: calc(100vw - 20px); max-height: 68vh; overflow: hidden;
  display: none; flex-direction: column;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg, 0 12px 40px rgba(0,0,0,.18));
}
.cs-pop.is-open { display: flex; }
.cs-pop--set { width: 330px; }
.cs-pop__head { flex: 0 0 auto; padding: .7rem .8rem; border-bottom: 1px solid var(--color-border); }
.cs-pop__search {
  width: 100%; padding: .55rem .8rem; font: inherit; font-size: .85rem;
  color: var(--color-text); background: var(--color-surface-2);
  border: 1.5px solid var(--color-border); border-radius: var(--radius-full);
}
.cs-pop__search:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 24%, transparent); }
/* min-height:0 lets the flex child actually shrink so overflow-y can scroll */
.cs-pop__list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: .3rem 0 .5rem; -webkit-overflow-scrolling: touch; }
.cs-pop__group { padding: .6rem .9rem .3rem; font-size: .68rem; letter-spacing: .07em; text-transform: uppercase; font-weight: 800; color: var(--color-text-muted); }
.cs-pop__empty { padding: 1.4rem; text-align: center; color: var(--color-text-muted); font-size: .88rem; }

.cs-ind { border-bottom: 1px solid color-mix(in srgb, var(--color-border) 55%, transparent); }
.cs-ind__row { display: flex; align-items: flex-start; gap: .6rem; width: 100%; padding: .55rem .9rem; background: none; border: none; text-align: left; cursor: pointer; font: inherit; }
.cs-ind__row:hover { background: color-mix(in srgb, var(--color-accent) 6%, transparent); }
.cs-ind__check { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px; border: 1.5px solid var(--color-border); border-radius: 5px; position: relative; }
.cs-ind.is-on .cs-ind__check { background: var(--color-accent); border-color: var(--color-accent); }
.cs-ind.is-on .cs-ind__check::after { content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid var(--color-on-accent); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.cs-ind__body { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.cs-ind__body b { color: var(--color-heading); font-size: .84rem; font-weight: 800; }
.cs-ind__pro { display: inline-block; font-style: normal; font-size: .58rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--color-on-accent); background: var(--color-accent); border-radius: 5px; padding: .08rem .3rem; vertical-align: 1px; }
.cs-ind__name { color: var(--color-text); font-size: .82rem; }
.cs-ind__body small { color: var(--color-text-muted); font-size: .74rem; }
.cs-ind__params { display: flex; align-items: center; gap: .5rem; padding: 0 .9rem .6rem 2.1rem; }
.cs-ind__params label { font-size: .72rem; color: var(--color-text-muted); font-weight: 700; }
.cs-ind__params input { flex: 1 1 auto; min-width: 0; padding: .35rem .55rem; font: inherit; font-size: .8rem; font-variant-numeric: tabular-nums; color: var(--color-text); background: var(--color-surface-2); border: 1.5px solid var(--color-border); border-radius: 8px; }
.cs-ind__params input:focus { outline: none; border-color: var(--color-accent); }

/* Settings panel rows */
.cs-set-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: .6rem; padding: .5rem .9rem; }
.cs-set-row > label { font-size: .78rem; font-weight: 700; color: var(--color-text-muted); }
.cs-seg-mini-wrap { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
.cs-seg-mini { padding: .32rem .6rem; border: 1.5px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-surface); color: var(--color-text); font: inherit; font-size: .75rem; font-weight: 700; cursor: pointer; }
.cs-seg-mini:hover { border-color: var(--color-accent); color: var(--color-accent-deep); }
.cs-seg-mini.is-on { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
.cs-set-toggles { display: flex; gap: 1rem; flex-wrap: wrap; }
.cs-chk { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--color-text); cursor: pointer; }
.cs-chk input { accent-color: var(--color-accent); }
.cs-set-colors { display: flex; gap: 1rem; }
.cs-color { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--color-text); }
.cs-color input[type="color"] { width: 30px; height: 24px; padding: 0; border: 1.5px solid var(--color-border); border-radius: 6px; background: none; cursor: pointer; }
.cs-set-foot { padding: .5rem .9rem .2rem; }
.cs-set-foot .cs-act { width: 100%; justify-content: center; }
.cs-set-row--fmt { border-bottom: 1px solid var(--color-border); padding-bottom: .6rem; margin-bottom: .1rem; }
.cs-exp-actions { display: flex; gap: .5rem; padding: .7rem .9rem .3rem; flex-wrap: wrap; }
.cs-exp-actions .cs-act { flex: 1 1 0; justify-content: center; }
.cs-exp-actions .cs-act:disabled { cursor: wait; opacity: .68; }
.cs-act--primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
.cs-act--primary:hover { border-color: var(--color-accent); color: var(--color-on-accent); filter: brightness(1.05); }

/* Small labelled icon buttons (undo / clear / PNG) */
.cs-act {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .4rem .75rem;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit; font-size: .78rem; font-weight: 700;
  cursor: pointer; transition: all var(--transition);
}
.cs-act:hover { border-color: var(--color-accent); color: var(--color-accent-deep); }
.cs-act svg { display: block; }
.cs-act--icon { padding: .4rem .5rem; }
.cs-act.is-on { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
/* Icon-only actions on small screens (the title attribute keeps the name) */
@media (max-width: 560px) {
  .cs-act .cs-act__t { display: none; }
  .cs-act { padding: .45rem .6rem; }
}

/* ---------- Active-indicator chips ---------- */
.cs-active { display: flex; flex-wrap: wrap; gap: .4rem; padding-top: .1rem; }
.cs-active[hidden] { display: none; }
.cs-ai { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .3rem .2rem .55rem; border: 1.5px solid var(--color-border); border-radius: var(--radius-full); background: color-mix(in srgb, var(--color-accent) 8%, transparent); font-size: .74rem; font-weight: 800; color: var(--color-heading); }
.cs-ai--pro { border-color: color-mix(in srgb, var(--color-accent) 55%, var(--color-border)); }
.cs-ai__x { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border: none; border-radius: 50%; background: color-mix(in srgb, var(--color-text-muted) 22%, transparent); color: var(--color-heading); font-size: 13px; line-height: 1; cursor: pointer; padding: 0; }
.cs-ai__x:hover { background: #cf5b5b; color: #fff; }

/* ---------- Fullscreen (native :fullscreen + CSS fallback) ---------- */
.cs-card:fullscreen, .cs-card--fs { position: fixed; inset: 0; z-index: 200; width: 100vw; height: 100vh; border-radius: 0; }
.cs-card:fullscreen .cs-chartwrap, .cs-card--fs .cs-chartwrap { height: auto; flex: 1 1 auto; }
.cs-card:fullscreen, .cs-card--fs { display: flex; flex-direction: column; }
.cs-card:fullscreen .cs-stage, .cs-card--fs .cs-stage { flex: 1 1 auto; min-height: 0; }

/* ---------- Stage: drawing tool rail + chart ---------- */
.cs-stage { display: flex; align-items: stretch; }
.cs-tools {
  display: flex; flex-direction: column; gap: .3rem;
  padding: .6rem .45rem;
  border-right: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-border) 12%, transparent);
}
.cs-tool {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid transparent; border-radius: 10px;
  background: transparent; color: var(--color-text-muted);
  cursor: pointer; transition: all var(--transition);
}
.cs-tool:hover { color: var(--color-accent-deep); border-color: var(--color-border); background: var(--color-surface); }
.cs-tool.is-on { color: var(--color-on-accent); background: var(--color-accent); border-color: var(--color-accent); }
.cs-tool svg { display: block; }

/* On small screens the rail becomes a horizontal strip above the chart */
@media (max-width: 899px) {
  .cs-stage { flex-direction: column; }
  .cs-tools { flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--color-border); }
}

/* ---------- Live 24h stats bar (first-party, my design) ---------- */
.cs-statbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .7rem 1.15rem;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-accent) 4%, transparent);
}
.cs-statbar:empty { display: none; }
.cs-price { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.cs-price__sym { font-family: var(--font-head); font-weight: 800; font-size: 1rem; color: var(--color-heading); }
.cs-price__val { font-weight: 800; font-size: 1.5rem; color: var(--color-heading); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.cs-price__chg { font-weight: 700; font-size: .92rem; font-variant-numeric: tabular-nums; padding: .1rem .5rem; border-radius: var(--radius-full); }
.cs-price__chg.up { color: #2e9e5b; background: color-mix(in srgb, #2e9e5b 12%, transparent); }
.cs-price__chg.down { color: #cf5b5b; background: color-mix(in srgb, #cf5b5b 12%, transparent); }
.cs-statchips { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.cs-statchip { display: flex; flex-direction: column; gap: .1rem; }
.cs-statchip__k { font-size: .68rem; letter-spacing: .05em; text-transform: uppercase; color: var(--color-text-muted); }
.cs-statchip__v { font-weight: 700; font-size: .9rem; color: var(--color-heading); font-variant-numeric: tabular-nums; }

/* ---------- Chart area ---------- */
.cs-chartwrap { position: relative; flex: 1 1 auto; min-width: 0; height: 560px; contain: layout style paint; }

/* CHRYSOFI wordmark watermark: sits INSIDE the chart, centered in the candle
   area (not over the price axis), faint so candles read through it, and never
   intercepts clicks. Uses your gold logo PNG. */
.cs-watermark {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 3;
  width: min(360px, 48%); height: 68px;
  background-image: var(--logo-img);
  background-repeat: no-repeat; background-position: center; background-size: contain;
  opacity: .09; pointer-events: none;
}
/* keep the wordmark off the loading skeleton - it fades in with the data */
.cs-chartwrap:not(.is-live) .cs-watermark { opacity: 0; }
@media (max-width: 600px) { .cs-watermark { width: 62%; height: 46px; } }
@media (max-width: 1080px) { .cs-chartwrap { height: 500px; } }
@media (max-width: 600px)  { .cs-chartwrap { height: 430px; } }
.cs-chart { position: absolute; inset: 0; }
.cs-brush { position: absolute; inset: 0; z-index: 4; pointer-events: none; touch-action: none; }
.cs-brush.is-armed { pointer-events: auto; cursor: crosshair; }

/* Feed status pill (Live / Polling / Offline) */
.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 .dot { background: #2e9e5b; box-shadow: 0 0 0 3px color-mix(in srgb, #2e9e5b 22%, transparent); }
.cs-status.is-live { color: #2e9e5b; }
.cs-status.is-poll .dot { background: #e0a52e; }
.cs-status.is-off .dot { background: #cf5b5b; }

/* Loading skeleton until the first candles arrive */
.cs-chartwrap::before {
  content: "";
  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: cs-sheen 1.5s linear infinite;
}
.cs-chartwrap::after {
  content: "Loading candles...";
  position: absolute; inset: 0; z-index: 2;
  display: grid; place-items: center;
  font-size: .85rem; color: var(--color-text-muted);
}
.cs-chartwrap.is-live::before, .cs-chartwrap.is-live::after { content: none; }
@keyframes cs-sheen { to { background-position: -120% 0, 0 0; } }
@media (prefers-reduced-motion: reduce) { .cs-chartwrap::before { animation: none; } }

/* Offline message (replaces the chart if every data source fails) */
.cs-offline {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center; text-align: center;
  padding: 1.5rem; color: var(--color-text-muted); font-size: .92rem;
}

/* ---------- Technical signal gauge (my own speedometer) ---------- */
.cs-gauge-card { margin-top: 1.25rem; }
.cs-gauge-hd { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .85rem 1.15rem; border-bottom: 1px solid var(--color-border); }
.cs-gauge-title { margin: 0; font-family: var(--font-head); font-size: .95rem; font-weight: 700; color: var(--color-heading); }
.cs-gauge-for { font-size: .8rem; color: var(--color-text-muted); }
.cs-gauge-for b { color: var(--color-accent-deep); }
/* min-height reserves the finished size so the "Reading the candles..."
   placeholder never causes a jump when the gauge appears */
.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 { padding: 2rem 1rem; color: var(--color-text-muted); font-size: .9rem; text-align: center; }

/* ---------- Help strip under the card ---------- */
.cs-help { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); margin-top: 1.25rem; }
.cs-help-item {
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface); padding: .9rem 1rem;
  font-size: .85rem; color: var(--color-text-muted); line-height: 1.55;
}
.cs-help-item b { display: block; color: var(--color-heading); margin-bottom: .25rem; font-size: .88rem; }

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