/* ═══════════════════════════════════════════════════════════════
   HARAZI — Base styles (reset + layout primitives)
   ═══════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── iOS / Android safe-area insets ──────────────────────────────
   The browser injects env(safe-area-inset-*) values for the notch /
   home-indicator on iOS and gesture nav bars on Android. Expose them
   as CSS variables so any component can opt in to "respect the notch"
   with a single `padding-top: var(--safe-top)`. device.js also reads
   these so JS layout code stays in sync. */
:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* Stop iOS Safari's pull-to-refresh from firing on the chart page
   (vertical pull on the chart used to reload the whole page mid-
   pan). overscroll-behavior-y: contain keeps the chart's own pan
   responsive while preventing the gesture from bleeding to the
   browser's reload. Touch-only — desktop keeps wheel-overscroll. */
html.is-touch,
html.is-touch body {
  overscroll-behavior-y: contain;
}

/* Kill the grey tap-flash on every touch of a link/button (the chart
   surfaces already suppress it via touch-action; this covers the rest
   — auth, landing, settings, tables). Cosmetic but it's the difference
   between "native-feeling" and "web page". */
html { -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ─── No-select on chart UI (TradingView-style) ──────────────────
   Right-clicking on a chip used to drag the browser's text selection
   into the chip label, which fights the custom context menu. Disable
   selection across the whole charting surface — chart area, chip
   rail, drawing toolbar, alpha badge, sub-pane labels, etc. — and
   keep selection enabled inside actual text-entry surfaces (inputs,
   textareas, contenteditable, settings modals). */
#chart-wrap,
.backtest__chart-area,
.hrzi-chip-rail,
.hrzi-chip-allvis,
.hrzi-chip-add,
.hrzi-alpha-badge,
.hrzi-chip-ctxmenu,
.hrzi-chip-addmenu,
.draw-toolbar,
.draw-floats,
.draw-clickhint,
.draw-cheatsheet,
.chart-engine__subpane,
.chart-engine__subpane-label,
.chart-watermark,
.chart-legend {
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  -webkit-touch-callout: none;          /* iOS long-press menu */
}
/* Re-enable selection wherever the user is actually typing or might
   reasonably want to copy a value (settings modals, alert dialogs,
   the OHLC legend's numbers). */
input, textarea, [contenteditable="true"],
.ind-panel input, .ind-panel textarea, .ind-panel select,
.hrzi-alerts-modal__body, .hrzi-alerts-modal__body input,
.hrzi-alerts-modal__body select, .hrzi-alerts-modal__body textarea,
.modal__body, .modal__body input, .modal__body textarea,
.chart-legend .cl-o, .chart-legend .cl-h,
.chart-legend .cl-l, .chart-legend .cl-c,
.chart-legend .cl-vol, .chart-legend .cl-time {
  -webkit-user-select: text;
     -moz-user-select: text;
      -ms-user-select: text;
          user-select: text;
}

body {
  display: flex;
  flex-direction: column;
}

a {
  color: var(--info);
  text-decoration: none;
}
a:hover { color: #7aa9ff; }

button {
  font-family: var(--font-ui);
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input, select, textarea {
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  color: var(--text-0);
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 5px 9px;
  outline: none;
  transition: border-color var(--t-fast), background var(--t-fast);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--info);
  background: var(--bg-1);
}
input[type="checkbox"] {
  accent-color: var(--info);
  cursor: pointer;
}
input[type="number"] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  padding: 1px 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--text-1);
}

/* ── Monospace for numbers ───────────────────────────────── */
.mono,
.num,
td.num,
th.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ── Layout shell ────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.app > main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: var(--sp-4) var(--sp-5);
}
.page--flush {
  padding: 0;
  overflow: hidden;
}

/* ── Scrollbars ──────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg-0);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border: 2px solid var(--bg-0);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--bg-4);
}

/* ── Reduced motion (a11y) ───────────────────────────────────
   Honor the OS "reduce motion" setting globally: near-instant any
   transition/animation, and explicitly stop the infinite pulse loops
   (live dot, watchlist pulse, loader bars, spinners, fav star) which
   are the most vestibular-triggering. Scoped so it can't break layout
   that depends on a transition completing. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Text utilities ──────────────────────────────────────── */
.muted  { color: var(--text-1); }
.dim    { color: var(--text-2); }
.faint  { color: var(--text-3); }
.bull   { color: var(--bull); }
.bear   { color: var(--bear); }
.win    { color: var(--win); }
.loss   { color: var(--loss); }
.warn   { color: var(--warn); }
.info   { color: var(--info); }
.accent { color: var(--accent); }
.up::before    { content: "▲ "; color: var(--bull); }
.down::before  { content: "▼ "; color: var(--bear); }

.tabular { font-variant-numeric: tabular-nums; }

.h-label {
  font-size: var(--fs-11);
  font-weight: var(--fw-semi);
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.h-section {
  font-size: var(--fs-14);
  font-weight: var(--fw-bold);
  color: var(--text-0);
}

/* ── Flex helpers ────────────────────────────────────────── */
.row { display: flex; align-items: center; }
.row--gap-1 { gap: var(--sp-1); }
.row--gap-2 { gap: var(--sp-2); }
.row--gap-3 { gap: var(--sp-3); }
.row--gap-4 { gap: var(--sp-4); }
.row--between { justify-content: space-between; }
.row--end     { justify-content: flex-end; }
.stack {
  display: flex;
  flex-direction: column;
}
.stack--gap-1 { gap: var(--sp-1); }
.stack--gap-2 { gap: var(--sp-2); }
.stack--gap-3 { gap: var(--sp-3); }
.stack--gap-4 { gap: var(--sp-4); }
.spacer { flex: 1 1 auto; }

/* ── Hidden ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ── Focus ring (accessibility, subtle) ──────────────────── */
:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 1px;
  border-radius: var(--r-2);
}

/* Plotly svg crispness */
.js-plotly-plot .plotly .modebar { display: none !important; }
