/* MeritX Superchart — full-viewport TradingView-style terminal */
:root {
  --sc-bg:#ffffff; --sc-panel:#f7f7f9; --sc-border:#e3e3ea; --sc-text:#131722; --sc-text2:#5d606b;
  --sc-muted:#9598a1; --sc-hover:rgba(19,23,34,.06); --sc-accent:#33058d; --sc-up:#1a7d42; --sc-dn:#c0392b;
  --sc-grid:rgba(19,23,34,.07); --sc-tip:#ffffff;
}
[data-theme="dark"] {
  --sc-bg:#0e0e13; --sc-panel:#16161d; --sc-border:#26262f; --sc-text:#e8e8ef; --sc-text2:#b3b3c0;
  --sc-muted:#70707e; --sc-hover:rgba(232,232,239,.08); --sc-accent:#a688ff; --sc-up:#2ecc71; --sc-dn:#e74c3c;
  --sc-grid:rgba(232,232,239,.07); --sc-tip:#1d1d26;
}
html, body { height:100%; }
body.mxsc { margin:0; overflow:hidden; background:var(--sc-bg); color:var(--sc-text);
  font:400 13px/1.45 Inter, system-ui, sans-serif; display:flex; flex-direction:column; height:100vh; }
.mxsc * { box-sizing:border-box; }
button { font:inherit; color:inherit; background:none; border:0; cursor:pointer; }

/* ---------- top bar ---------- */
/* the feature strip scrolls horizontally at ANY width when its controls don't
   fit (keeps the dense terminal on the desktop view for iPads/narrow desktops
   without breaking the page) — it only scrolls when it actually overflows. */
.sc-top { display:flex; align-items:center; gap:6px; height:46px; padding:0 10px; border-bottom:1px solid var(--sc-border); flex:none; overflow-x:auto; overflow-y:hidden; scrollbar-width:none; overscroll-behavior-x:contain; }
.sc-top::-webkit-scrollbar { display:none; }
.sc-logo { display:flex; align-items:center; gap:7px; font-weight:800; letter-spacing:.06em; font-size:13px; text-decoration:none; color:var(--sc-text); padding-right:6px; }
.sc-logo img { width:20px; height:20px; border-radius:5px; }
.sc-btn { display:inline-flex; align-items:center; gap:6px; padding:7px 10px; border-radius:8px; font-weight:600; font-size:12.5px; color:var(--sc-text2); white-space:nowrap; }
.sc-btn:hover { background:var(--sc-hover); color:var(--sc-text); }
.sc-btn.is-on { color:var(--sc-accent); }
.sc-btn svg { width:16px; height:16px; }
.sc-sym { font-weight:800; font-size:13.5px; color:var(--sc-text); }
.sc-sep { width:1px; height:22px; background:var(--sc-border); margin:0 2px; flex:none; }
.sc-top__right { margin-left:auto; display:flex; align-items:center; gap:6px; }

/* dropdown menus */
.sc-menu { position:absolute; z-index:60; min-width:172px; background:var(--sc-bg); border:1px solid var(--sc-border); border-radius:10px; box-shadow:0 14px 40px rgba(10,8,24,.18); padding:5px; }
.sc-menu[hidden] { display:none; }
.sc-menu button { display:flex; align-items:center; gap:9px; width:100%; padding:8px 10px; border-radius:7px; font-size:12.5px; font-weight:500; color:var(--sc-text); text-align:left; }
.sc-menu button:hover { background:var(--sc-hover); }
.sc-menu button.is-on { color:var(--sc-accent); font-weight:700; }
.sc-menu .sc-menu__lbl { font:700 9.5px/1 "JetBrains Mono", monospace; letter-spacing:.12em; text-transform:uppercase; color:var(--sc-muted); padding:8px 10px 4px; }

/* ---------- main ---------- */
.sc-main { flex:1; display:flex; min-height:0; }

/* drawing rail */
.sc-rail { width:46px; flex:none; border-right:1px solid var(--sc-border); display:flex; flex-direction:column; align-items:center; padding:6px 0; gap:2px; overflow-y:auto; }
.sc-tool { width:34px; height:34px; display:flex; align-items:center; justify-content:center; border-radius:8px; color:var(--sc-text2); }
.sc-tool:hover { background:var(--sc-hover); color:var(--sc-text); }
.sc-tool.is-on { background:color-mix(in srgb, var(--sc-accent) 14%, transparent); color:var(--sc-accent); }
.sc-tool svg { width:18px; height:18px; }
.sc-rail__sep { width:22px; height:1px; background:var(--sc-border); margin:5px 0; flex:none; }

/* chart column */
.sc-chartcol { flex:1; display:flex; flex-direction:column; min-width:0; position:relative; }
.sc-canvas-wrap { flex:1; position:relative; min-height:0; cursor:crosshair; }
.sc-canvas-wrap canvas { position:absolute; inset:0; width:100%; height:100%; display:block; }
#scDraw { z-index:2; }
.sc-legend { position:absolute; top:8px; left:10px; z-index:5; display:flex; flex-direction:column; gap:3px; pointer-events:none; max-width:70%; }
/* chart loading overlay (Yahoo fetch can take several seconds) */
.sc-loader { position:absolute; inset:0; z-index:8; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; pointer-events:none;
  background:color-mix(in srgb, var(--sc-bg) 55%, transparent); backdrop-filter:blur(1.5px); -webkit-backdrop-filter:blur(1.5px);
  font:600 12.5px/1 Inter, system-ui, sans-serif; letter-spacing:.02em; color:var(--sc-muted); }
.sc-loader[hidden] { display:none; }
.sc-loader__spin { width:34px; height:34px; border-radius:50%; border:3px solid color-mix(in srgb, var(--sc-accent) 22%, transparent); border-top-color:var(--sc-accent); animation:sc-spin .7s linear infinite; }
@keyframes sc-spin { to { transform:rotate(360deg); } }
.sc-legend__row { display:flex; align-items:center; gap:8px; font:600 11.5px/1.3 Inter, sans-serif; color:var(--sc-text2); pointer-events:auto; background:color-mix(in srgb, var(--sc-bg) 72%, transparent); border-radius:6px; padding:3px 7px; width:fit-content; }
.sc-legend__row b { color:var(--sc-text); }
.sc-legend__x { color:var(--sc-muted); cursor:pointer; padding:0 2px; font-weight:700; }
.sc-legend__x:hover { color:var(--sc-dn); }
.sc-ohlc { font:600 11.5px/1.3 "JetBrains Mono", monospace; }
.sc-ohlc .u { color:var(--sc-up); } .sc-ohlc .d { color:var(--sc-dn); }

/* bottom range bar */
.sc-bottom { display:flex; align-items:center; gap:2px; height:34px; padding:0 10px; border-top:1px solid var(--sc-border); flex:none; }
.sc-rng { padding:5px 9px; border-radius:7px; font:700 11.5px/1 "JetBrains Mono", monospace; color:var(--sc-text2); }
.sc-rng:hover { background:var(--sc-hover); }
.sc-rng.is-on { color:#fff; background:var(--sc-accent); }
.sc-clock { margin-left:auto; font:600 11px/1 "JetBrains Mono", monospace; color:var(--sc-muted); }

/* ---------- watchlist ---------- */
.sc-watch { width:292px; flex:none; border-left:1px solid var(--sc-border); display:flex; flex-direction:column; min-height:0; }
.sc-watch.is-collapsed { display:none; }
.sc-btn.is-on { color:var(--sc-accent); border-color:color-mix(in srgb, var(--sc-accent) 45%, transparent); }
.sc-watch__head { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid var(--sc-border); }
.sc-watch__title { font-weight:800; font-size:13px; }
.sc-watch__add { width:26px; height:26px; border-radius:7px; display:flex; align-items:center; justify-content:center; color:var(--sc-text2); font-size:17px; font-weight:700; }
.sc-watch__add:hover { background:var(--sc-hover); color:var(--sc-accent); }
/* Header, group labels and rows must share one column geometry or the labels
   drift off their data. .sc-wrow adds a 4th 16px track for its ✕ and a 2px
   left border, so both are mirrored here (border transparent, 4th track empty)
   and the right padding matched at 6px — without that the LAST/CHG% labels sat
   16px right of their numbers and SYMBOL 2px left of the names. */
.sc-watch__cols { display:grid; grid-template-columns:1fr 68px 74px 16px; gap:6px; padding:7px 6px 5px 12px; border-left:2px solid transparent; font:700 9.5px/1 "JetBrains Mono", monospace; letter-spacing:.1em; text-transform:uppercase; color:var(--sc-muted); border-bottom:1px solid var(--sc-border); }
.sc-watch__cols span:nth-child(n+2) { text-align:right; }
.sc-watch__list { flex:1; overflow-y:auto; min-height:0; }
.sc-wgroup { font:700 9.5px/1 "JetBrains Mono", monospace; letter-spacing:.12em; text-transform:uppercase; color:var(--sc-muted); padding:10px 12px 4px; border-left:2px solid transparent; }
.sc-wrow { display:grid; grid-template-columns:1fr 68px 74px 16px; gap:6px; align-items:center; width:100%; padding:7px 6px 7px 12px; text-align:left; border-left:2px solid transparent; }
.sc-wrow:hover { background:var(--sc-hover); }
.sc-wrow.is-active { border-left-color:var(--sc-accent); background:color-mix(in srgb, var(--sc-accent) 7%, transparent); }
.sc-wrow__sym { font-weight:700; font-size:12px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sc-wrow__last, .sc-wrow__chg { font:600 11.5px/1 "JetBrains Mono", monospace; text-align:right; }
.sc-wrow__x { color:transparent; font-weight:700; font-size:12px; text-align:center; cursor:pointer; }
.sc-wrow:hover .sc-wrow__x { color:var(--sc-muted); }
.sc-wrow__x:hover { color:var(--sc-dn) !important; }
.u { color:var(--sc-up); } .d { color:var(--sc-dn); }

/* symbol detail card */
.sc-detail { border-top:1px solid var(--sc-border); padding:12px 14px; flex:none; }
.sc-detail__name { font-weight:800; font-size:13.5px; }
.sc-detail__sub { color:var(--sc-muted); font-size:11px; margin-top:1px; }
.sc-detail__px { font:800 24px/1.15 "JetBrains Mono", monospace; margin-top:8px; letter-spacing:-.5px; }
.sc-detail__chg { font:700 12.5px/1 "JetBrains Mono", monospace; margin-top:3px; }
.sc-detail__research { display:flex; align-items:center; justify-content:center; gap:7px; margin-top:11px; padding:9px 12px; border-radius:9px; font:700 12.5px/1 Inter, sans-serif; text-decoration:none; color:#fff; background:var(--sc-accent); transition:filter .15s ease; }
.sc-detail__research:hover { filter:brightness(1.08); }
[data-theme="dark"] .sc-detail__research { background:#4969FF; color:#000; }
.sc-detail__mkt { display:flex; align-items:center; gap:6px; margin-top:8px; font-size:11px; color:var(--sc-muted); }
.sc-detail__dot { width:7px; height:7px; border-radius:50%; background:var(--sc-muted); }
.sc-detail__dot.is-open { background:var(--sc-up); }

/* ---------- modals ---------- */
.sc-overlay { position:fixed; inset:0; z-index:100; background:rgba(10,8,24,.44); backdrop-filter:blur(3px); display:flex; align-items:flex-start; justify-content:center; padding:8vh 16px 16px; }
.sc-overlay[hidden] { display:none; }
.sc-dialog { width:min(720px, 100%); max-height:80vh; display:flex; flex-direction:column; background:var(--sc-bg); border:1px solid var(--sc-border); border-radius:14px; box-shadow:0 24px 70px rgba(10,8,24,.4); overflow:hidden; }
.sc-dialog__head { display:flex; align-items:center; justify-content:space-between; padding:14px 16px 10px; }
.sc-dialog__title { font-weight:800; font-size:16px; }
.sc-dialog__close { color:var(--sc-muted); font-weight:700; padding:4px 8px; border-radius:7px; }
.sc-dialog__close:hover { background:var(--sc-hover); color:var(--sc-text); }
.sc-dialog__search { margin:0 16px 10px; padding:9px 12px; font:500 13px/1.2 Inter, sans-serif; color:var(--sc-text); background:var(--sc-panel); border:1px solid var(--sc-border); border-radius:9px; outline:none; }
.sc-dialog__search:focus { border-color:var(--sc-accent); }
.sc-dialog__body { overflow-y:auto; min-height:0; padding:0 8px 10px; }
.sc-item { display:flex; align-items:center; gap:10px; width:100%; padding:8px 10px; border-radius:8px; text-align:left; }
.sc-item:hover { background:var(--sc-hover); }
.sc-item__name { font-weight:600; font-size:13px; flex:1; }
/* the bold instrument name in symbol search — brand indigo, not body text.
   Only the search rows wrap the name in <b>; the indicators list and the raw-
   symbol fallback use bare text, so they keep --sc-text. */
.sc-item__name b { color:#2708A0; }
[data-theme="dark"] .sc-item__name b { color:#4969FF; }
.sc-item__tag { font:600 9.5px/1 "JetBrains Mono", monospace; letter-spacing:.06em; text-transform:uppercase; color:var(--sc-muted); border:1px solid var(--sc-border); border-radius:5px; padding:3px 6px; }
.sc-item__added { color:var(--sc-accent); font-weight:700; font-size:11px; }
.sc-dialog__foot { padding:9px 16px; border-top:1px solid var(--sc-border); font-size:11px; color:var(--sc-muted); display:flex; justify-content:space-between; }

/* text-input floater for the Text tool */
.sc-textin { position:absolute; z-index:40; font:600 12.5px/1.3 Inter, sans-serif; color:var(--sc-text); background:var(--sc-bg); border:1px solid var(--sc-accent); border-radius:7px; padding:5px 8px; outline:none; min-width:120px; }

/* emoji picker strip */
.sc-emojis { position:absolute; z-index:45; display:flex; gap:2px; background:var(--sc-bg); border:1px solid var(--sc-border); border-radius:9px; padding:4px; box-shadow:0 10px 30px rgba(10,8,24,.2); }
.sc-emojis[hidden] { display:none; }
.sc-emojis button { font-size:17px; padding:4px 6px; border-radius:6px; }
.sc-emojis button:hover { background:var(--sc-hover); }

@media (max-width: 639px) { .sc-watch { display:none; } }

/* detail-card stats grid */
.sc-detail__grid { display:grid; grid-template-columns:1fr 1fr; gap:7px 12px; margin-top:12px; padding-top:11px; border-top:1px solid var(--sc-border); }
.sc-detail__cell { display:flex; flex-direction:column; gap:2px; }
.sc-detail__cell span { font:600 8.5px/1 "JetBrains Mono", monospace; letter-spacing:.1em; text-transform:uppercase; color:var(--sc-muted); }
.sc-detail__cell b { font:700 11.5px/1.2 "JetBrains Mono", monospace; color:var(--sc-text); }

/* =========================================================================
   PHONES — the terminal itself must not pan sideways
   .sc-top holds the whole feature strip (logo, timeframe, chart type,
   indicators, snapshot…) which measures ~724px. With overflow-x visible that
   content widened the document to 724px, so a sideways swipe dragged the WHOLE
   terminal — chart, rail and all — instead of the strip. Same story on a
   smaller scale in .sc-chartcol (381px of content in a 329px column).

   Now: the page is pinned, and the only two things that scroll are the top
   strip (horizontally) and the drawing-tool rail (vertically).
   ========================================================================= */
@media (max-width: 639px) {
  html, body.mxsc { overflow-x: hidden; max-width: 100%; }

  .sc-top {
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;   /* swiping the strip must not chain to the page */
    scrollbar-width: none;
  }
  .sc-top::-webkit-scrollbar { display: none; }

  /* the chart column fits its slot rather than pushing the layout wider */
  .sc-chartcol { overflow-x: hidden; }

  /* the tool rail keeps its own vertical scroll and never grows the page */
  .sc-rail { overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; }
}

/* Phones: the two toolbars were set at desktop sizes, so they read as sparse
   and over-wide — and the timeframe row needed 381px inside a 329px column,
   which meant "All" was being clipped off the end. Tightening type, padding
   and gaps brings that row back inside its slot and shortens the top strip's
   scroll run. */
@media (max-width: 639px) {
  .sc-top  { gap: 3px; padding: 0 8px; }
  .sc-logo { font-size: 11.5px; gap: 5px; padding-right: 4px; }
  .sc-btn  { font-size: 11px; padding: 5px 7px; gap: 4px; }

  .sc-bottom { padding: 0 8px; }
  .sc-rng    { padding: 4px 6px; font-size: 10.5px; }
  .sc-clock  { font-size: 9.5px; }
}

/* =========================================================================
   Top-bar "more" dropdown
   Desktop keeps every control inline: .sc-more is display:contents, so its
   children lay out as direct flex items of .sc-top exactly as before, and the
   caret is hidden. On phones the caret appears next to the interval button and
   the rest collapse into a panel beneath it — the strip stops being a long
   horizontal scroll of half-visible buttons.
   ========================================================================= */
.sc-more { display: contents; }
.sc-morebtn { display: none; }

@media (max-width: 639px) {
  .sc-top { position: relative; }
  .sc-morebtn { display: inline-flex; padding: 5px 4px; }
  .sc-morebtn svg { width: 14px; height: 14px; }
  .sc-morebtn[aria-expanded="true"] svg { transform: rotate(180deg); }
  .sc-morebtn svg { transition: transform .22s ease; }

  .sc-more {
    display: none;
    /* fixed, NOT absolute: .sc-top is a horizontal scroll container
       (overflow-x:auto), and that clips descendants — an absolutely-positioned
       panel hanging below the 46px strip was being cut off entirely, so the
       menu opened but was invisible. Fixed escapes ancestor overflow clipping.
       top/left are set by mx-super.js so it hangs under the caret; fixed
       coordinates cannot be derived from the button in CSS alone. */
    position: fixed; top: 46px; left: 0; right: auto; z-index: 60;
    width: max-content; min-width: 170px; max-width: calc(100vw - 16px);
    flex-direction: column; align-items: stretch; gap: 2px;
    padding: 6px; max-height: 60vh; overflow-y: auto;
    background: var(--sc-bg);
    border: 1px solid var(--sc-border); border-radius: 10px;
    box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .55);
  }
  .sc-top.is-more-open .sc-more { display: flex; }
  /* the right-hand group is just another row in the panel here */
  .sc-more .sc-top__right { display: flex; flex-direction: column; align-items: stretch; gap: 2px; margin: 0; }
  .sc-more .sc-btn { justify-content: flex-start; width: 100%; padding: 9px 10px; font-size: 12px; }
  /* Watchlist toggle and Full screen are dropped from the phone menu: the
     watchlist is collapsed to zero width here so its toggle does nothing, and
     the full-screen button is already marked [hidden] in the markup — that
     attribute only rendered because `.sc-btn { display:inline-flex }` overrides
     the UA's [hidden] rule. */
  .sc-more #scWatchToggle,
  .sc-more #scFsBtn,
  .sc-more .sc-btn[hidden] { display: none; }
  /* Snapshot is promoted to its own top-bar button here, so drop the copy that
     would otherwise still be listed in the panel via .sc-top__right. */
  .sc-more #scShotBtn { display: none; }
  .sc-more #scWatchOpen { display: flex; }
}

/* Snapshot mirrored into the top bar (phones). margin-left:auto parks it at the
   far right of the strip; if the strip ever overflows the auto margin simply
   collapses and it stays inline after the caret. */
.sc-topshot { display: none; }
.sc-watchbtn { display: none; }
@media (max-width: 639px) {
  .sc-topshot { display: inline-flex; margin-left: auto; flex: none; padding: 6px; }
  .sc-topshot svg { width: 17px; height: 17px; }
}

/* Declared ahead of the phone block below: a media query adds no specificity,
   so a later base rule would beat the `display:flex` inside it. */
.sc-watch__close { display: none; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  font-size: 13px; font-weight: 700; color: var(--sc-text2); }
.sc-watch__close:hover { background: var(--sc-hover); color: var(--sc-text); }

/* =========================================================================
   PHONES — the watchlist as a right-hand sheet
   .sc-watch is a docked 292px sidebar that goes display:none below 1050px, so
   on a phone it was unreachable. Opened from the More menu, it returns as an
   overlay. .is-collapsed is repeated in the selector because that class is
   driven by a localStorage flag set on desktop — without it a user who had
   collapsed the sidebar there would find the phone sheet permanently hidden.
   ========================================================================= */
@media (max-width: 639px) {
  .sc-watch, .sc-watch.is-collapsed {
    display: flex; position: fixed; top: 46px; right: 0; z-index: 70;
    width: min(86vw, 330px); height: calc(100dvh - 46px);
    background: var(--sc-bg); border-left: 1px solid var(--sc-border);
    box-shadow: -20px 0 48px -24px rgba(0, 0, 0, .55);
    transform: translateX(102%); visibility: hidden;
    transition: transform .28s cubic-bezier(.22, 1, .36, 1), visibility 0s linear .28s;
  }
  .sc-watch.is-open { transform: none; visibility: visible; transition-delay: 0s, 0s; }
  .sc-watch__head { gap: 4px; }
  .sc-watch__close { display: flex; }
  /* the sheet is short, so let the whole column scroll rather than only the list */
  .sc-watch .sc-detail { overflow-y: auto; }
  /* The top bar already carries this CTA on phones, so the panel's copy is
     redundant. Hidden rather than removed from the markup: mx-super.js mirrors
     this anchor's href onto #scResearchTop, so deleting it would leave the
     top-bar button pointing at the wrong stock. */
  .sc-detail__research { display: none; }
}

/* Top-bar "Research this stock" CTA — mirrors .sc-detail__research (the
   watchlist panel's button), which is unreachable on a phone because that
   panel is collapsed. Phone-only: on desktop the panel shows it already. */
.sc-cta { display: none; }
@media (max-width: 639px) {
  .sc-cta {
    display: inline-flex; align-items: center; gap: 5px; flex: none;
    padding: 6px 9px; border-radius: 8px;
    font: 700 12.1px/1 Inter, sans-serif; text-decoration: none;   /* 11px +10% */
    color: #fff; background: var(--sc-accent); white-space: nowrap;
  }
  .sc-cta svg { width: 12px; height: 12px; }
  [data-theme="dark"] .sc-cta { background: #4969FF; color: #000; }
  /* The symbol label is the only variable-width item on the strip, so a long
     name used to shove everything after it past the edge — NIFTY_FIN_SERVICE.NS
     pushed the CTA 52px off-screen. min-width:0 defeats the flex item's
     automatic minimum so the label can shrink and ellipsis instead. */
  #scSymBtn { min-width: 0; }
  #scSymBtn .sc-sym { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Narrow phones: the CTA pushed the strip 19px past the edge, so the button sat
   half off-screen. The MERITX wordmark is the cheapest thing to give up — the
   favicon still marks it and still links home. font-size:0 because the label is
   a bare text node with no element to target. */
@media (max-width: 639px) {
  .sc-logo { font-size: 0; gap: 0; padding-right: 2px; }
  .sc-logo img { width: 20px; height: 20px; }
  .sc-cta { padding: 5px 7px; font-size: 11.55px; }   /* 10.5px +10% */
}
