/* =============================================================================
   STOCKSAATHI — Design System
   Minimalist Indian fintech. Light-mode primary. Green-accent. Clean numbers.
   Inspired by the genre (Groww/Kite/Upstox) — original color/motion tokens.
   ============================================================================= */

:root {
  /* ---------- Palette (LIGHT — default) ---------- */
  --bg: #F8F9FB;
  --bg-soft: #F1F3F7;
  --bg-subtle: #EEF1F5;
  --surface: #FFFFFF;
  --surface-elev: #FFFFFF;
  --border: #E6E8EE;
  --border-strong: #D3D7DF;
  --divider: #EDEFF3;

  --text: #141414;
  --text-strong: #0A0A0A;
  --text-muted: #5C6473;
  --text-dim: #878E9C;
  --text-faint: #A8AFBC;

  --brand: #00B386;                 /* primary green — gains, primary CTA */
  --brand-dark: #00906B;
  --brand-soft: #E6F7F1;
  --brand-ring: rgba(0, 179, 134, 0.25);

  --accent: #5367FF;                /* secondary blue */
  --accent-soft: #EAEDFF;

  --positive: #00B386;
  --positive-soft: #E6F7F1;
  --negative: #EB5757;
  --negative-soft: #FDEBEB;
  --warning: #F39C12;
  --warning-soft: #FEF4E4;

  /* Chart palette — charts.js reads these with #10B981 / #EF4444 fallbacks.
     Defining both light + dark values here is the single source of truth. */
  --green: #10B981;
  --red: #EF4444;
  --yellow: #F39C12;

  --saffron: #FF8A2A;               /* India accent */
  --saffron-soft: #FFF0E2;

  /* ---------- Typography ---------- */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --text-10: 0.625rem;
  --text-11: 0.6875rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-md: 0.875rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --text-6xl: 3.75rem;

  /* ---------- Spacing ---------- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;
  --sp-24: 96px;

  /* ---------- Radii ---------- */
  --r-sm: 6px;
  --r: 10px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 24px;
  --r-full: 999px;

  /* ---------- Shadows ---------- */
  --sh-xs: 0 1px 2px rgba(20, 20, 20, 0.04);
  --sh-sm: 0 2px 6px rgba(20, 20, 20, 0.05);
  --sh-md: 0 6px 18px rgba(20, 20, 20, 0.08);
  --sh-lg: 0 16px 40px rgba(20, 20, 20, 0.12);
  --sh-brand: 0 8px 24px rgba(0, 179, 134, 0.25);
  --sh-focus: 0 0 0 3px var(--brand-ring);

  /* ---------- Motion ---------- */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-snap: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-1: 120ms;
  --dur-2: 220ms;
  --dur-3: 380ms;

  /* ---------- Layout ---------- */
  --nav-h: 64px;
  --coach-w: 380px;
  --max-w: 1280px;
}

[data-theme="dark"] {
  --bg: #0A0B0F;
  --bg-soft: #111319;
  --bg-subtle: #171A22;
  --surface: #13161E;
  --surface-elev: #191C26;
  --border: #262A36;
  --border-strong: #353A4A;
  --divider: #1E212B;
  --text: #F1F3F7;
  --text-strong: #FFFFFF;
  --text-muted: #A8AFBC;
  --text-dim: #8189A0;
  --text-faint: #5C6473;
  --brand-soft: rgba(0, 179, 134, 0.12);
  --accent-soft: rgba(83, 103, 255, 0.12);
  --positive-soft: rgba(0, 179, 134, 0.12);
  --negative-soft: rgba(235, 87, 87, 0.14);
  --warning-soft: rgba(243, 156, 18, 0.14);
  --saffron-soft: rgba(255, 138, 42, 0.14);
  --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --sh-sm: 0 2px 6px rgba(0, 0, 0, 0.45);
  --sh-md: 0 6px 18px rgba(0, 0, 0, 0.5);
  --sh-lg: 0 16px 40px rgba(0, 0, 0, 0.6);
  /* Brighter variants so charts/sparklines stay readable on dark bg. */
  --green: #34D399;
  --red: #F87171;
  --yellow: #FBBF24;
}

/* Respect users who opted out of motion. Disables page transitions, shake
   animations on the intervention modal, scroll smoothing, etc. */
@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;
  }
}

/* Give the intervention modal the shake animation referenced from JS. */
@keyframes ss-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.btn.shake { animation: ss-shake 0.3s ease-in-out; }
.modal-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--yellow);
}
.intervention-caption {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.intervention-fineprint {
  font-size: 13px;
  line-height: 1.6;
}

/* -------------------- Reset / base -------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;   /* kill grey iOS tap flash */
  scroll-behavior: smooth;
  font-feature-settings: "ss01", "cv11";
  /* account for notches / dynamic island */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;  /* mobile browser chrome accounted for */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.005em;
  overscroll-behavior-y: none;    /* no iOS bounce chaining to window */
}
/* body scroll lock when drawer / modal is open */
body.scroll-lock {
  overflow: hidden;
  touch-action: none;
}
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  color: var(--text-strong);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
p { margin: 0; }
a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--dur-1) var(--ease);
}
a:hover { color: var(--brand-dark); }
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}
input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
/* Prevent iOS "date/time/number" zoom on focus — requires font-size >= 16px */
@media screen and (max-width: 820px) {
  input, select, textarea,
  .input, .select, .qty-stepper input,
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="search"], input[type="tel"] {
    font-size: 16px !important;
  }
}
:focus-visible {
  outline: none;
  box-shadow: var(--sh-focus);
  border-radius: var(--r-sm);
}
hr { border: none; border-top: 1px solid var(--divider); margin: var(--sp-4) 0; }

/* -------------------- A11y / motion -------------------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  top: -48px; left: 0;
  background: var(--brand);
  color: white;
  padding: 10px 18px;
  z-index: 1000;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--r) 0;
}
.skip-link:focus { top: 0; color: white; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* -------------------- Layout primitives -------------------- */
.main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-24);
  padding-bottom: calc(var(--sp-24) + env(safe-area-inset-bottom));
  min-height: calc(100vh - var(--nav-h));
  min-height: calc(100dvh - var(--nav-h));
}
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding-left: var(--sp-6);
  padding-right: var(--sp-6);
}
.grid { display: grid; gap: var(--sp-5); }
.flex { display: flex; gap: var(--sp-3); }
.flex-col { display: flex; flex-direction: column; gap: var(--sp-3); }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-5 { gap: var(--sp-5); }
.gap-6 { gap: var(--sp-6); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

@media (min-width: 1280px) {
  body.coach-docked { padding-right: var(--coach-w); }
  body.coach-docked .nav { padding-right: var(--coach-w); }
}

/* -------------------- Type utilities -------------------- */
.text-10 { font-size: var(--text-10); }
.text-11 { font-size: var(--text-11); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }
.text-5xl { font-size: var(--text-5xl); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.font-semi { font-weight: 600; }
.font-med { font-weight: 500; }
.font-reg { font-weight: 400; }
.uppercase { text-transform: uppercase; letter-spacing: 0.06em; }
.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.strong { color: var(--text-strong); }
.brand { color: var(--brand); }
.up { color: var(--positive); }
.down { color: var(--negative); }
.warn { color: var(--warning); }
.center { text-align: center; }
.right { text-align: right; }
.tight { letter-spacing: -0.03em; }

/* -------------------- Buttons -------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px 18px;
  font-size: var(--text-md);
  font-weight: 600;
  border-radius: var(--r-md);
  transition: all var(--dur-1) var(--ease);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1;
  min-height: 40px;
  letter-spacing: -0.005em;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-primary {
  background: var(--brand);
  color: white;
  box-shadow: var(--sh-xs);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); box-shadow: var(--sh-brand); color: white; }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--sh-xs);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); background: var(--bg-soft); }
.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { background: var(--bg-soft); border-color: var(--border-strong); }
.btn-buy {
  background: var(--positive);
  color: white;
  box-shadow: var(--sh-xs);
}
.btn-buy:hover:not(:disabled) { background: #009972; box-shadow: var(--sh-brand); }
.btn-sell {
  background: var(--negative);
  color: white;
  box-shadow: var(--sh-xs);
}
.btn-sell:hover:not(:disabled) { background: #DA3D3D; }
.btn-danger {
  background: transparent;
  color: var(--negative);
  border-color: var(--border);
}
.btn-danger:hover:not(:disabled) { background: var(--negative-soft); border-color: var(--negative); }
.btn-link { background: transparent; color: var(--brand); padding: 6px 4px; min-height: 0; }
.btn-link:hover { color: var(--brand-dark); }
.btn-sm { padding: 6px 12px; font-size: var(--text-sm); min-height: 32px; border-radius: var(--r); }
.btn-lg { padding: 14px 24px; font-size: var(--text-base); min-height: 48px; }
.btn-icon { padding: 8px; min-height: 36px; min-width: 36px; }
.btn-block { width: 100%; }

/* -------------------- Cards -------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--sh-xs);
}
.card-compact { padding: var(--sp-4); }
.card-tight { padding: var(--sp-3); }
.card-flat { box-shadow: none; }
.card-hover:hover { border-color: var(--border-strong); box-shadow: var(--sh-sm); }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  gap: var(--sp-3);
}
.card-head h3 { font-size: var(--text-lg); }

/* -------------------- Pills -------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: var(--text-11);
  font-weight: 600;
  border-radius: var(--r-full);
  line-height: 1.4;
  letter-spacing: 0.01em;
}
.pill-green { background: var(--positive-soft); color: var(--positive); }
.pill-red { background: var(--negative-soft); color: var(--negative); }
.pill-yellow { background: var(--warning-soft); color: var(--warning); }
.pill-blue { background: var(--accent-soft); color: var(--accent); }
.pill-saffron { background: var(--saffron-soft); color: var(--saffron); }
.pill-neutral { background: var(--bg-soft); color: var(--text-muted); border: 1px solid var(--border); }
.pill-brand { background: var(--brand-soft); color: var(--brand); }
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }

/* -------------------- Inputs -------------------- */
.input, .select, textarea.input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
  min-height: 44px;
  box-shadow: var(--sh-xs);
}
textarea.input { min-height: 88px; resize: vertical; }
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--sh-focus);
}
.input-prefix {
  display: flex; align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--sh-xs);
  min-height: 44px;
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.input-prefix:focus-within { border-color: var(--brand); box-shadow: var(--sh-focus); }
.input-prefix > .px { padding: 0 var(--sp-3); color: var(--text-muted); font-size: var(--text-sm); font-weight: 600; }
.input-prefix > input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: 10px 14px 10px 0;
  font-size: var(--text-md);
  min-width: 0;
  color: var(--text);
}
.label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.checkbox, .radio {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  transition: background var(--dur-1), border-color var(--dur-1);
}
.radio { border-radius: 50%; }
.checkbox:checked, .radio:checked { background: var(--brand); border-color: var(--brand); }
.checkbox:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.radio:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: white;
}

/* -------------------- Table -------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-md);
  background: var(--surface);
}
.table th, .table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--divider);
}
.table th {
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-soft);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 2;
}
.table tbody tr { transition: background var(--dur-1); }
.table tbody tr:hover { background: var(--bg-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table .num { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }

/* -------------------- Skeleton -------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-soft), var(--bg-subtle), var(--bg-soft));
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: var(--r-sm);
  display: inline-block;
}
@keyframes skel {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* -------------------- Page transitions -------------------- */
.page-enter { animation: pageIn 240ms var(--ease); }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(0, 179, 134, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(0, 179, 134, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 179, 134, 0); }
}

/* -------------------- Disclaimer footer -------------------- */
.disclaimer {
  border-top: 1px solid var(--divider);
  padding: var(--sp-6);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-faint);
  max-width: 900px;
  margin: 0 auto;
  line-height: 1.7;
}
.disclaimer strong { color: var(--text-muted); }

/* -------------------- NoScript warning -------------------- */
.noscript-warning {
  padding: var(--sp-12);
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
}

/* -------------------- Responsive -------------------- */
/* Universal mobile safeguards: prevent horizontal scroll from any rogue
   wide element. IMPORTANT: don't use overflow-x: hidden on html/body —
   that kills pull-to-refresh + sometimes the vertical scroll context on
   Android. overflow-x: clip is the modern equivalent that contains
   horizontal overflow WITHOUT creating a new scroll context. */
@media (max-width: 768px) {
  body { overflow-x: clip; }
  img, svg, video, iframe { max-width: 100%; height: auto; }
  /* Tables usually need horizontal scroll rather than squished cells */
  .admin-table-wrap, .scroll-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Inputs + buttons never wider than their container */
  input, textarea, select, button { max-width: 100%; }
}
@media (max-width: 768px) {
  .main {
    padding: var(--sp-4);
    padding-bottom: calc(var(--sp-20) + env(safe-area-inset-bottom));
  }
  .card { padding: var(--sp-4); }
  .card-compact { padding: var(--sp-3); }
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  h3 { font-size: var(--text-lg); }
  .text-5xl { font-size: var(--text-3xl); }
  .text-4xl { font-size: var(--text-2xl); }
  .text-3xl { font-size: var(--text-2xl); }
  .grid, .flex-col { gap: var(--sp-3); }
  .flex { gap: var(--sp-2); }
  /* Buttons bump to iOS-standard tap target on phones */
  .btn { min-height: 44px; padding: 11px 18px; }
  .btn-sm { min-height: 36px; padding: 8px 13px; }
  .btn-icon { min-height: 40px; min-width: 40px; }
  .disclaimer { padding: var(--sp-5) var(--sp-4); font-size: 11px; }
}
@media (max-width: 420px) {
  .main { padding: var(--sp-3); }
  .card { padding: var(--sp-3); }
  h1 { font-size: var(--text-xl); }
}
/* Landscape phones: don't waste vertical space on hero */
@media (max-height: 480px) and (orientation: landscape) {
  .hero { padding: var(--sp-6) var(--sp-4); }
  .hero h1 { font-size: 2rem; margin-bottom: var(--sp-3); }
  .hero .tagline { font-size: var(--text-base); margin-bottom: var(--sp-4); }
  .hero .stat-row { margin-top: var(--sp-5); }
}

/* -------------------- Scrollbars (subtle, desktop only) -------------------- */
@media (hover: hover) and (pointer: fine) {
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
}
/* Momentum scrolling for horizontal overflow (tables, tab rows) */
.table-wrap, .filter-pills, .lb-tabs, .tf-buttons {
  -webkit-overflow-scrolling: touch;
}

/* -------------------- Utility extras -------------------- */
.divider { height: 1px; background: var(--divider); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounded-full { border-radius: var(--r-full); }
