﻿/* ============================================================
   MeritX â€” full-screen chart panel (chart-panel.css)
   A CSP-safe, vanilla TradingView-style overlay. Opens over the
   terminal on click. Themed via the shared --mxc-* variables so it
   follows dark/light. All chart drawing is inline SVG (no libs).
   ============================================================ */
.mxp {
  position: fixed; inset: 0; z-index: 4000;
  display: none; flex-direction: column;
  background: var(--mxc-bg, #06060c);
  color: var(--mxc-text, #e9e9f2);
  font-family: Inter, system-ui, sans-serif;
  opacity: 0; transition: opacity .18s ease;
}
.mxp.is-open { display: flex; opacity: 1; }
@media (prefers-reduced-motion: reduce) { .mxp { transition: none; } }

/* ---- top bar ---- */
.mxp__bar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 14px; min-height: 56px;
  border-bottom: 1px solid var(--mxc-border, #23232e);
  background: var(--mxc-surface, #0c0d12);
  flex-wrap: wrap;
}
.mxp__sym { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.mxp__sym b { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.mxp__sym .exch {
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--mxc-muted, #8a8a99);
  border: 1px solid var(--mxc-border, #23232e); border-radius: 5px; padding: 2px 6px;
}
.mxp__sym .nm { font-size: 12px; color: var(--mxc-muted, #8a8a99); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

/* live OHLC readout in the bar */
.mxp__ohlc { display: flex; gap: 12px; font-size: 12px;
  font-family: "JetBrains Mono", monospace; color: var(--mxc-text-2, #b9b9c6); }
.mxp__ohlc span b { color: var(--mxc-text, #e9e9f2); font-weight: 700; }
.mxp__ohlc .chg.pos, .mxp .pos { color: var(--mxc-green, #2fd27a); }
.mxp__ohlc .chg.neg, .mxp .neg { color: var(--mxc-red, #f4564f); }

.mxp__spacer { flex: 1 1 auto; }
.mxp__ctrls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* segmented controls */
.mxp-seg { display: inline-flex; background: var(--mxc-surface-2, #141420);
  border: 1px solid var(--mxc-border, #23232e); border-radius: 9px; padding: 2px; gap: 2px; }
.mxp-seg button {
  font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
  color: var(--mxc-muted, #8a8a99); background: transparent; border: 0;
  padding: 5px 9px; border-radius: 7px; line-height: 1; transition: color .15s, background .15s;
}
.mxp-seg button:hover { color: var(--mxc-text, #e9e9f2); }
.mxp-seg button.is-on { color: #fff; background: var(--mx-brand, #33058d); }
[data-theme="light"] .mxp-seg button.is-on { color: #fff; }

/* toggle chips (SMA / Vol) */
.mxp-tog {
  font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
  color: var(--mxc-muted, #8a8a99);
  background: var(--mxc-surface-2, #141420);
  border: 1px solid var(--mxc-border, #23232e);
  padding: 6px 10px; border-radius: 8px; transition: all .15s;
}
.mxp-tog.is-on { color: var(--mxc-text, #e9e9f2); border-color: var(--mx-brand-bright, #8d68f0);
  box-shadow: inset 0 0 0 1px var(--mx-brand-bright, #8d68f0); }

.mxp__icon {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--mxc-muted, #8a8a99);
  background: var(--mxc-surface-2, #141420);
  border: 1px solid var(--mxc-border, #23232e); border-radius: 9px; transition: all .15s;
}
.mxp__icon:hover { color: var(--mxc-text, #e9e9f2); border-color: var(--mxc-border-strong, #34343f); }
.mxp__icon svg { width: 17px; height: 17px; }
.mxp__x:hover { color: var(--mxc-red, #f4564f); border-color: var(--mxc-red, #f4564f); }

/* ---- body: left rail + chart ---- */
.mxp__main { flex: 1 1 auto; display: flex; min-height: 0; }
.mxp__rail {
  width: 46px; flex: 0 0 46px; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 8px 0;
  border-right: 1px solid var(--mxc-border, #23232e);
  background: var(--mxc-surface, #0c0d12);
}
.mxp__tool {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--mxc-muted, #8a8a99); background: transparent;
  border: 1px solid transparent; border-radius: 8px; transition: all .15s;
}
.mxp__tool:hover { color: var(--mxc-text, #e9e9f2); background: var(--mxc-surface-2, #141420); }
.mxp__tool.is-on { color: #fff; background: var(--mx-brand, #33058d); }
.mxp__tool svg { width: 17px; height: 17px; }
.mxp__rail hr { width: 22px; border: 0; border-top: 1px solid var(--mxc-border, #23232e); margin: 4px 0; }

.mxp__chart { position: relative; flex: 1 1 auto; min-width: 0; cursor: crosshair; user-select: none; touch-action: none; overscroll-behavior: contain; }
.mxp__chart.is-grabbing { cursor: grabbing; }
.mxp__chart svg { display: block; width: 100%; height: 100%; }

/* subtle interaction hint (bottom-left) */
.mxp__hint { position: absolute; left: 12px; bottom: 5px; z-index: 2; pointer-events: none;
  font-size: 10.5px; color: var(--mxc-muted, #8a8a99); opacity: .5; }

/* crosshair readout */
.mxp__read {
  position: absolute; top: 10px; left: 12px; pointer-events: none;
  font-family: "JetBrains Mono", monospace; font-size: 11.5px;
  color: var(--mxc-text-2, #b9b9c6); background: color-mix(in srgb, var(--mxc-surface, #0c0d12) 86%, transparent);
  border: 1px solid var(--mxc-border, #23232e); border-radius: 8px; padding: 6px 9px;
  display: none; white-space: nowrap; line-height: 1.5; z-index: 3;
}
.mxp__read b { color: var(--mxc-text, #e9e9f2); }

/* axis price/time tags that ride the crosshair */
.mxp__tag {
  position: absolute; pointer-events: none; z-index: 3; display: none;
  font-family: "JetBrains Mono", monospace; font-size: 10.5px; font-weight: 700; color: #fff;
  background: var(--mx-brand, #33058d); border-radius: 4px; padding: 2px 5px; white-space: nowrap;
  transform: translateY(-50%);
}
.mxp__tag--y { right: 2px; }
.mxp__tag--x { bottom: 2px; transform: translateX(-50%); }
/* always-on last-price tag (green/red like TradingView) */
.mxp__tag--last { display: none; right: 2px; color: #04160c; background: var(--mxc-green, #2fd27a); }
.mxp__tag--last.neg { color: #1a0606; background: var(--mxc-red, #f4564f); }

.mxp__loading {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; color: var(--mxc-muted, #8a8a99); font-size: 13px; z-index: 4;
}
.mxp__loading.is-on { display: flex; }
.mxp__spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--mxc-border, #23232e); border-top-color: var(--mx-brand-bright, #8d68f0);
  animation: mxp-spin .8s linear infinite;
}
@keyframes mxp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .mxp__spin { animation: none; } }

/* ---- foot ---- */
.mxp__foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 7px 14px; font-size: 11px; color: var(--mxc-muted, #8a8a99);
  border-top: 1px solid var(--mxc-border, #23232e); background: var(--mxc-surface, #0c0d12);
}
.mxp__foot .live { display: inline-flex; align-items: center; gap: 6px; }
.mxp__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mxc-green, #2fd27a);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--mxc-green, #2fd27a) 70%, transparent);
  animation: mxp-pulse 2s infinite; }
.mxp__dot.is-stale { background: var(--mxc-muted, #8a8a99); animation: none; }
@keyframes mxp-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--mxc-green,#2fd27a) 55%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.mxp__foot .sebi b { color: #ffd700; }

@media (max-width: 639px) {
  .mxp__rail { display: none; }
  .mxp__ohlc { display: none; }
  .mxp__sym .nm { max-width: 120px; }
}

/* ============================================================
   Side drawer (opens first on a row click; has a Full-screen button)
   ============================================================ */
.mxd-back { position: fixed; inset: 0; z-index: 3900; background: rgba(4,4,10,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.mxd-back.is-open { opacity: 1; pointer-events: auto; }
.mxd {
  position: fixed; top: 0; right: 0; z-index: 3950; height: 100vh;
  width: min(440px, 92vw); display: flex; flex-direction: column; gap: 14px;
  padding: 16px 18px; overflow-y: auto;
  background: var(--mxc-surface, #0c0d12); color: var(--mxc-text, #e9e9f2);
  border-left: 1px solid var(--mxc-border, #23232e);
  box-shadow: -24px 0 60px rgba(0,0,0,.45);
  transform: translateX(100%); transition: transform .24s cubic-bezier(.22,1,.36,1);
  font-family: Inter, system-ui, sans-serif;
}
.mxd.is-open { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) { .mxd, .mxd-back { transition: none; } }
.mxd__head { display: flex; align-items: center; justify-content: space-between; }
.mxd__id { display: flex; align-items: baseline; gap: 8px; }
.mxd__id b { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.mxd__px { display: flex; align-items: baseline; gap: 10px; }
.mxd__px .v { font-size: 26px; font-weight: 800; font-family: "JetBrains Mono", monospace; }
.mxd__px .c { font-size: 14px; font-weight: 700; }
.mxd__chart { height: 210px; width: 100%; border: 1px solid var(--mxc-border, #23232e);
  border-radius: 12px; background: var(--mxc-bg, #06060c); overflow: hidden; }
.mxd__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.mxd__stat { display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; padding: 7px 10px; border-radius: 9px;
  background: var(--mxc-surface-2, #141420); border: 1px solid var(--mxc-border, #23232e); }
.mxd__stat span { color: var(--mxc-muted, #8a8a99); }
.mxd__stat b { font-family: "JetBrains Mono", monospace; font-weight: 700; }
.mxd__act { display: flex; gap: 10px; }
.mxd__act .btn { flex: 1; text-align: center; justify-content: center; }
/* Terminal (primary) -> electric blue + white, overriding the global dark button */
.mxd__act .btn--primary { background: #4969ff; color: #fff; }
.mxd__act .btn--primary:hover { background: #3a57e0; }
/* light theme takes the deep brand indigo instead; the electric blue above is
   tuned for the dark panel and is left alone there (per user) */
[data-theme="light"] .mxd__act .btn--primary { background: #2708A0; color: #fff; }
[data-theme="light"] .mxd__act .btn--primary:hover { background: #1d0678; }
/* Research (ghost) keeps its base outline and turns gold on hover */
.mxd__act .btn--ghost:hover { border-color: #c9a227; }
.mxd__foot { margin-top: auto; display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--mxc-muted, #8a8a99);
  padding-top: 12px; border-top: 1px solid var(--mxc-border, #23232e); }
.mxd .sebi-y { color: #c9a227; }

/* drawer: 52-week range bar */
.mxd__w52 { display: flex; flex-direction: column; gap: 5px; }
.mxd__w52lab { display: flex; justify-content: space-between; font-size: 11px; color: var(--mxc-muted, #8a8a99); }
.mxd__w52lab b { color: var(--mxc-text, #e9e9f2); font-family: "JetBrains Mono", monospace; }
.mxd__w52bar { position: relative; height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--mxc-red, #f4564f), var(--mxc-muted, #8a8a99), var(--mxc-green, #2fd27a)); opacity: .85; }
.mxd__w52dot { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--mx-brand, #33058d); transform: translate(-50%, -50%); box-shadow: 0 1px 4px rgba(0,0,0,.4); }

/* "loading history" pill (shown while lazy-loading older candles on drag-left) */
.mxp__more { position: absolute; top: 50%; left: 14px; transform: translateY(-50%); z-index: 4; display: none;
  align-items: center; gap: 8px; padding: 7px 12px; font-size: 12px; color: var(--mxc-text, #e9e9f2);
  background: color-mix(in srgb, var(--mxc-surface, #0c0d12) 92%, transparent);
  border: 1px solid var(--mxc-border, #23232e); border-radius: 20px; }
.mxp__spin--sm { width: 14px; height: 14px; border-width: 2px; display: inline-block; }

/* ---- drawer returns strip (1W/1M/3M/6M) ---- */
.mxd__rets { display:grid; grid-template-columns:repeat(4, 1fr); gap:8px; margin-top:10px; padding-top:11px; border-top:1px solid var(--mxc-border, rgba(120,120,140,.18)); grid-column:1 / -1; }
.mxd__ret { display:flex; flex-direction:column; gap:4px; align-items:center; }
.mxd__ret span { font:600 9px/1 "JetBrains Mono", monospace; letter-spacing:.12em; text-transform:uppercase; color:var(--mxc-muted, #8a8a9a); }
.mxd__ret b { font:700 12px/1 "JetBrains Mono", monospace; }
.mxd__ret b.pos { color:var(--mxc-green, #1a7d42); }
.mxd__ret b.neg { color:var(--mxc-red, #c0392b); }

/* =========================================================================
   PHONES â€” index/stock side drawer at 3/4 of the screen
   It was min(440px, 92vw), i.e. effectively full-bleed on a phone. At 75vw
   (~281px, ~253px of content) the stats drop from two columns to one, since
   two label+value pairs cannot share ~120px. The graph is deliberately NOT
   shrunk to fit: .mxd already has overflow-y:auto, so it keeps its full 210px
   height and the drawer scrolls internally instead of compromising the chart.
   ========================================================================= */
@media (max-width: 639px) {
  .mxd { width: 75vw; padding: 12px 14px; gap: 10px; }
  /* -webkit for momentum scrolling on iOS; overscroll-contain stops the page
     behind the drawer from scrolling once the drawer hits its end */
  .mxd { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  /* .mxd is a fixed-height (100vh) flex column, so its children shrink to fit
     by default — on a short phone that squeezed the 210px chart down to ~73px
     and overflow-y:auto never fired. Pinning every child to its natural height
     makes the content overflow instead, so the drawer scrolls and the graph
     (and every stat) keeps full size. */
  .mxd > * { flex-shrink: 0; }

  .mxd__id b { font-size: 14px; }
  .mxd__id { gap: 5px; }
  .mxd__px { gap: 6px; flex-wrap: wrap; }
  .mxd__px .v { font-size: 19px; }
  .mxd__px .c { font-size: 11.5px; }

  /* full height, not the old 140px — the graph is the point of the drawer, so
     it keeps its size and the panel scrolls to reveal the stats below it */
  .mxd__chart { height: 210px; }

  .mxd__w52lab { font-size: 10px; }
  .mxd__w52dot { width: 10px; height: 10px; }

  /* one stat per row â€” the label and its value need the full width here */
  .mxd__stats { grid-template-columns: 1fr; gap: 5px; }
  .mxd__stat { padding: 6px 8px; font-size: 11px; }

  .mxd__rets { grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 7px; padding-top: 8px; }
  .mxd__ret span { font-size: 8.5px; letter-spacing: .08em; }
  .mxd__ret b { font-size: 11px; }

  .mxd__act { gap: 6px; }
  .mxd__act .btn { padding: 8px 8px; font-size: 11.5px; }

  .mxd__foot { font-size: 9.5px; gap: 6px; flex-wrap: wrap; }
}
