/* =========================================================
   TradeApes Brand Styles
   Two themes: dark (default) and light, toggled via
   data-theme="light" on <html>. All colors go through
   CSS custom properties — no hardcoded palette values
   in component rules below.
   ========================================================= */

/* ── DARK THEME (default) ─────────────────────────────── */
:root {
  /* Page backgrounds */
  --bg-900: #0B0F24;
  --bg-800: #0F1535;
  --bg-700: #111A40;

  /* Surface / card backgrounds */
  --surface-800: #151C45;
  --surface-700: #1B2357;

  /* Text */
  --text-100: #E7E9F4;
  --text-200: #C6CBE3;
  --text-300: #9AA3C7;
  --text-muted: #7380AD;

  /* Semantic surface alphas */
  --surface-xs:   rgba(255,255,255,.03);
  --surface-sm:   rgba(255,255,255,.05);
  --surface-md:   rgba(255,255,255,.08);

  /* Semantic border alphas */
  --border-subtle: rgba(255,255,255,.06);
  --border-md:     rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.22);
  --border:        rgba(255,255,255,.08); /* alias for legacy usage */

  /* Interactive / state */
  --hover-bg:       rgba(255,255,255,.06);
  --invert-surface: rgba(0,0,0,.35);
  --input-bg:       rgba(255,255,255,.04);
  --pill-bg:        rgba(255,255,255,.06);

  /* Cards */
  --card-gradient: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.015));
  --card-bg:       var(--surface-800);

  /* Score / ring track */
  --score-track-bg: rgba(255,255,255,.10);
  --ring-track-bg:  rgba(255,255,255,.10);

  /* Stars empty */
  --star-empty: rgba(255,255,255,.20);

  /* Subscore divider */
  --subscore-divider: rgba(255,255,255,.07);

  /* Shadows */
  --shadow-soft: 0 8px 24px rgba(0,0,0,.40);
  --shadow-card: 0 4px 16px rgba(0,0,0,.30);

  /* Glows */
  --glow-primary: 0 0 0 2px rgba(124,58,237,.35), 0 16px 40px rgba(124,58,237,.25);
  --glow-cyan:    0 0 0 2px rgba(34,211,238,.35),  0 16px 40px rgba(34,211,238,.25);

  /* Valuation marker ring color */
  --val-marker-ring: rgba(34,211,238,.6);

  /* Theme toggle icon */
  --theme-toggle-icon: "☀";
}

/* ── LIGHT THEME ──────────────────────────────────────── */
[data-theme="light"] {
  --bg-900: #666666;
  --bg-800: #E8EBF8;
  --bg-700: #DFE3F5;

  --surface-800: #FFFFFF;
  --surface-700: #F0F2FB;

  --text-100: #0F1535;
  --text-200: #2D3564;
  --text-300: #4A5480;
  --text-muted: #6B7399;

  --surface-xs:   rgba(0,0,0,.02);
  --surface-sm:   rgba(0,0,0,.04);
  --surface-md:   rgba(0,0,0,.07);

  --border-subtle: rgba(0,0,0,.08);
  --border-md:     rgba(0,0,0,.12);
  --border-strong: rgba(0,0,0,.20);
  --border:        rgba(0,0,0,.10);

  --hover-bg:       rgba(0,0,0,.04);
  --invert-surface: rgba(0,0,0,.03);
  --input-bg:       rgba(0,0,0,.04);
  --pill-bg:        rgba(0,0,0,.05);

  --card-gradient: linear-gradient(180deg, rgba(255,255,255,.90), rgba(255,255,255,.70));
  --card-bg:       #FFFFFF;

  --score-track-bg: rgba(0,0,0,.10);
  --ring-track-bg:  rgba(0,0,0,.10);

  --star-empty: rgba(0,0,0,.15);
  --subscore-divider: rgba(0,0,0,.07);

  --shadow-soft: 0 4px 20px rgba(15,21,53,.10);
  --shadow-card: 0 2px 10px rgba(15,21,53,.08);

  --glow-primary: 0 0 0 2px rgba(124,58,237,.25), 0 8px 24px rgba(124,58,237,.15);
  --glow-cyan:    0 0 0 2px rgba(34,211,238,.25),  0 8px 24px rgba(34,211,238,.15);

  --val-marker-ring: rgba(124,58,237,.5);
  --theme-toggle-icon: "☾";
}

/* ── ACCENT / BRAND COLOURS (same in both themes) ──────── */
:root {
  --primary:    #7C3AED;
  --primary-hi: #A855F7;
  --magenta:    #FF3D9A;
  --cyan:       #0EA5E9;
  --green:      #10B981;
  --red:        #EF4444;
  --amber:      #F59E0B;

  --series-1:#22D3EE; --series-2:#FF4DB8; --series-3:#8B5CF6;
  --series-4:#22E58C; --series-5:#F59E0B;

  --radius-xs:6px; --radius-sm:10px; --radius-md:14px;
  --radius-lg:20px; --radius-xl:28px;

  --space-xs:4px; --space-sm:8px; --space-md:12px;
  --space-lg:16px; --space-xl:24px; --space-xxl:32px;

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono","Courier New";
}

/* ── TRANSITION for smooth theme switch ─────────────────── */
*, *::before, *::after {
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
}

/* ── BASE ────────────────────────────────────────────────── */
html, body { height: 100%; }

body {
  background: var(--bg-900) !important;
  color: var(--text-100) !important;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

body,
p,
span,
small,
strong,
em,
li,
dd,
dt,
label,
div,
section,
article,
aside,
main,
header,
footer,
nav {
  color: inherit;
}

a {
  color: var(--primary-hi);
  text-decoration: none;
}

a:hover { opacity: .85; }

::selection {
  background: rgba(124,58,237,.28);
  color: #fff;
}

/* ── GLOBAL SHELL / STANDARD PAGE STRUCTURE ─────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.page-shell,
.ta-page,
.stock-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.page-stack,
.section-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.page-header,
.ta-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.page-header-main,
.page-header-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-title,
.ta-page-title {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -.02em;
  color: var(--text-100) !important;
}

.page-subtitle,
.ta-page-subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted) !important;
}

.page-actions,
.ta-page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-eyebrow,
.card-eyebrow,
.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-300) !important;
  margin-bottom: 8px;
}

/* =========================================================
   NAVBAR — 4-column flex layout
   No Bootstrap class names used — zero collision risk.
   ========================================================= */
.ta-navbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  padding: 12px 0;
  flex-wrap: nowrap;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 8px;
  box-sizing: border-box;
}

.ta-nb-col {
  display: flex;
  align-items: center;
  min-width: 0;
}

.ta-nb-logo {
  flex: 0 0 auto;
  justify-content: flex-start;
}

.ta-nb-logo a {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.ta-logo-img {
  height: 44px;
  width: auto;
  display: block;
}

.ta-nb-theme {
  flex: 0 0 auto;
  justify-content: center;
  white-space: nowrap;
}

.ta-nb-links {
  flex: 1 1 auto;
  justify-content: center;
  gap: 22px;
  white-space: nowrap;
}

.ta-nb-auth {
  flex: 0 0 auto;
  justify-content: flex-end;
  white-space: nowrap;
}

.ta-theme-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  white-space: nowrap;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s ease;
}

.ta-theme-link:hover            { color: var(--primary-hi); text-decoration: none; }
[data-theme="light"] .ta-theme-link:hover { color: var(--primary); }

.ta-auth-btn { white-space: nowrap; }

.ta-nb-auth form,
.ta-nb-auth .button_to {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

@media (max-width: 900px) {
  .ta-navbar  { gap: 12px; }
  .ta-nb-links { gap: 14px; }
  .ta-nav-link, .ta-theme-link { font-size: 0.9rem; padding: 6px 8px; }
  .ta-logo-img { height: 38px; }
}

@media (max-width: 700px) {
  .ta-navbar { overflow-x: auto; }
}

.brand {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.footer {
  margin-top: 40px;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border-subtle);
}

/* ── CARDS ───────────────────────────────────────────────── */
.card,
.surface-card,
.panel {
  background: var(--card-gradient), var(--card-bg) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 22px;
  color: var(--text-100) !important;
}

.card > *,
.surface-card > *,
.panel > * {
  color: inherit;
}

.card--glow { box-shadow: var(--glow-primary); }

.card-header,
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
}

.card-header:last-child,
.panel-header:last-child {
  margin-bottom: 0;
}

.card-title,
.panel-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--text-100) !important;
}

.card-subtitle,
.panel-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted) !important;
}

.card-body {
  color: var(--text-100);
}

.card-section + .card-section {
  margin-top: var(--space-xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--border-subtle);
}

/* ── TYPOGRAPHY ─────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-100);
  margin-top: 0;
}

.headline,
.ta-headline {
  color: var(--text-100) !important;
  font-weight: 800;
  letter-spacing: .2px;
}

.h1 { font-size: 34px; font-weight: 800; letter-spacing: .2px; }
.h2 { font-size: 24px; font-weight: 700; }
.h3 { font-size: 18px; font-weight: 700; color: var(--text-200); }

.muted,
.helper-text,
.text-muted {
  color: var(--text-muted) !important;
}

.ta-text,
.text-strong {
  color: var(--text-100) !important;
}

.text-soft {
  color: var(--text-200) !important;
}

.metric-label,
.meta-label {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-300) !important;
}

.metric-value {
  color: var(--text-100) !important;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ── PILLS & BADGES ─────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--text-100);
  border: 1px solid var(--border-md);
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  background: var(--surface-sm);
  color: var(--text-200);
  border: 1px solid var(--border-subtle);
}

.badge--up   { background: rgba(16,185,129,.15); color: #10B981; border-color: rgba(16,185,129,.3); }
.badge--down { background: rgba(239,68,68,.15);  color: #EF4444; border-color: rgba(239,68,68,.3); }
.badge--muted { background: var(--surface-sm); color: var(--text-300); }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-100);
  transition: transform .15s, opacity .15s, background .15s, box-shadow .15s;
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hi));
  color: #fff !important;
  box-shadow: var(--glow-primary);
}

.btn-primary:hover { transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--primary-hi) !important;
  border: 1px solid var(--primary);
}

.btn-outline:hover {
  background: rgba(124,58,237,.12);
  color: #fff !important;
  border-color: var(--primary-hi);
}

.btn-sm {
  padding: 7px 12px;
  border-radius: var(--radius-xs);
  font-size: 13px;
}

.btn-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--border-md);
  background: var(--surface-xs);
  color: var(--text-100);
  transition: transform .15s, border-color .15s, background .15s, box-shadow .15s;
}

.btn-mini:hover {
  transform: translateY(-1px);
  background: var(--surface-sm);
  border-color: var(--border-strong);
}

.btn-mini.primary {
  border-color: rgba(34,211,238,.55);
  box-shadow: 0 0 0 2px rgba(34,211,238,.18);
}

.btn-mini.primary:hover {
  border-color: rgba(34,211,238,.85);
  box-shadow: var(--glow-cyan);
}

.btn-inline-form {
  display: inline;
  margin: 0;
}

/* Secondary (ghost/muted) action */
.btn--secondary {
  background: transparent;
  color: var(--text-300);
  border: 1px solid var(--border-md);
}
.btn--secondary:hover {
  background: var(--hover-bg);
  color: var(--text-200);
  border-color: var(--border-strong);
}

/* Destructive action */
.btn--danger {
  background: transparent;
  color: #ef4444;
  border: 1px solid rgba(239,68,68,.40);
}
.btn--danger:hover {
  background: rgba(239,68,68,.10);
  border-color: rgba(239,68,68,.75);
  color: #f87171;
}

/* ── THEME TOGGLE BUTTON — line art: purple (dark) / charcoal (light) ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(99,102,241,.55);
  background: rgba(99,102,241,.08);
  color: #a5b4fc;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}

.theme-toggle:hover {
  background: rgba(99,102,241,.16);
  border-color: rgba(99,102,241,.85);
  color: #c4b5fd;
  box-shadow: 0 0 0 2px rgba(99,102,241,.18);
}

[data-theme="light"] .theme-toggle {
  border: 1px solid rgba(40,40,55,.35);
  background: rgba(40,40,55,.06);
  color: #2d3148;
}

[data-theme="light"] .theme-toggle:hover {
  background: rgba(40,40,55,.12);
  border-color: rgba(40,40,55,.60);
  color: #0f1535;
  box-shadow: 0 0 0 2px rgba(40,40,55,.10);
}

/* ── FORMS ───────────────────────────────────────────────── */
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  margin-bottom: 4px;
}

.field label,
label,
.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-200) !important;
}

.input,
.select,
.form-control,
.form-select,
.form-input,
.form-textarea,
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 11px 14px;
  color: var(--text-100) !important;
  background: var(--input-bg) !important;
  border: 1px solid var(--border-md) !important;
  border-radius: var(--radius-sm) !important;
  outline: none;
  font-size: 14px;
  font-family: var(--font-sans);
  box-shadow: none;
  box-sizing: border-box;
}

textarea,
.form-textarea {
  resize: vertical;
  min-height: 96px;
}

.input::placeholder,
.form-control::placeholder,
.form-input::placeholder,
.form-textarea::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--text-muted) !important;
}

.input:focus,
.form-control:focus,
.form-input:focus,
.form-textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  color: var(--text-100) !important;
  background: var(--input-bg) !important;
  box-shadow: var(--glow-primary) !important;
  border-color: transparent !important;
  outline: none !important;
}

.input-group,
.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: var(--space-md);
}

@media (max-width: 720px) {
  .input-group,
  .form-row {
    grid-template-columns: 1fr;
  }
}

/* ── HR & TABLES ─────────────────────────────────────────── */
hr {
  height: 1px;
  border: 0;
  background: var(--border-subtle);
}

.table-wrap,
.data-table-wrap,
.fin-table-wrap,
.pp-table-wrap {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-xs);
}

.table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: transparent !important;
  color: var(--text-100) !important;
}

.table th,
.data-table th {
  text-align: left;
  font-weight: 700;
  color: var(--text-200) !important;
  border-bottom: 1px solid var(--border-md) !important;
  background: transparent !important;
  padding: 10px 12px;
  font-size: 13px;
}

.table td,
.data-table td {
  background: transparent !important;
  color: var(--text-100) !important;
  border-bottom: 1px solid var(--border-subtle) !important;
  padding: 10px 12px;
}

.table > :not(caption) > * > *,
.data-table > :not(caption) > * > * {
  background-color: transparent !important;
  color: var(--text-100) !important;
}

.table tbody tr:hover td,
.data-table tbody tr:hover td {
  background: var(--hover-bg) !important;
}

/* ── GAIN / LOSS COLORS ───────────────────────────────────── */
.ta-pos  { color: #10B981 !important; }
.ta-neg  { color: #EF4444 !important; }
.ta-zero { color: var(--text-300) !important; }

/* =========================================================
   Portfolio Header
   ========================================================= */
.ta-section { padding: 24px 0; }

.ta-portfolio-header { margin-bottom: 16px; }

.ta-portfolio-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.ta-portfolio-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text-100);
}

.ta-portfolio-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ta-portfolio-asof {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Portfolio summary tiles */
.ta-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 14px;
  margin-top: 12px;
}

@media (max-width: 900px) {
  .ta-tiles {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
}

.ta-tile-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: .08em;
  font-weight: 600;
}

.ta-tile-value {
  font-weight: 800;
  font-size: 20px;
  color: var(--text-100);
  font-variant-numeric: tabular-nums;
}

.ta-tile-sub {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
}

/* =========================================================
   Portfolio Table
   ========================================================= */
.portfolio-table thead th {
  color: var(--text-100) !important;
  border-bottom: 1px solid var(--border-strong) !important;
}

.portfolio-table tbody td {
  border-top: 1px solid var(--border-md) !important;
  color: var(--text-100);
}

.hoverable:hover { background: var(--hover-bg); }
.summary-row { background: var(--invert-surface); }
.rule-top { border-top: 1px solid var(--border-subtle); }

.ticker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-100);
  text-decoration: none;
  font-weight: 700;
}

.ticker-toggle .chev {
  transition: transform .15s ease;
  display: inline-block;
}

.portfolio-quotes-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
}

/* Price roll animation */
.price-line {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  vertical-align: middle;
}

.price-now { font-weight: 700; }

.roll {
  position: relative;
  vertical-align: middle;
}

.roll .val {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .25s ease, transform .25s ease;
  white-space: nowrap;
}

.roll .val.show {
  opacity: 1;
  transform: translateY(0);
  position: static;
}

#portfolio-table:not(.show-pct) .val.dollar { display: inline; }
#portfolio-table:not(.show-pct) .val.pct    { display: none; }
#portfolio-table.show-pct .val.dollar       { display: none; }
#portfolio-table.show-pct .val.pct          { display: inline; }

/* Delta pills */
.delta-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}

.delta-pill.ta-pos  { background: #10B981; color: #fff; }
.delta-pill.ta-neg  { background: #EF4444; color: #fff; }
.delta-pill.ta-zero { background: var(--surface-md); color: var(--text-300); }

.portfolio-table,
.portfolio-table .number,
.portfolio-table .slot,
.portfolio-table .delta-pill {
  font-variant-numeric: tabular-nums;
}

.col-qty .slot,
.col-cost .slot,
.col-day .slot,
.col-pl .roll,
.col-price .price-now,
.col-price .roll {
  white-space: nowrap;
  display: inline-block;
}

.col-qty  .slot  { width: 10ch; text-align: right; }
.col-cost .slot  { width: 12ch; text-align: right; }
.col-day  .slot  { width: 14ch; text-align: right; }
.col-pl   .roll  { width: 16ch; }
.col-pl   .val   { text-align: right; }
.col-price .price-now { width: 12ch; text-align: right; }
.col-price .roll  { width: 8.5em; }

/* Spinner */
.btn-loading {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-loading .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ta-spin .8s linear infinite;
  display: inline-block;
}

@keyframes ta-spin {
  to { transform: rotate(360deg); }
}

/* Toggle mini-cards */
.ta-mini-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: var(--space-lg);
}

@media (max-width: 900px) {
  .ta-mini-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 520px) {
  .ta-mini-grid { grid-template-columns: 1fr; }
}

.mini-card {
  padding: 10px 12px;
  border: 1px solid var(--border-md);
  border-radius: 10px;
  background: var(--surface-sm);
  color: var(--text-100);
}

.mini-card .muted {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-300);
  letter-spacing: .04em;
}

.mini-card .mini-value {
  font-weight: 800;
  color: var(--text-100);
}

.lots-link {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  color: var(--text-100);
  border-radius: var(--radius-sm);
}

.lots-link:hover {
  border-color: var(--text-100);
  background: var(--hover-bg);
}

/* =========================================================
   Top-nav links — live inside .ta-nb-links flex container.
   Prefixed "ta-" to avoid Bootstrap .nav-link collision.
   ========================================================= */
.ta-nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--primary-hi);
  text-decoration: none;
  white-space: nowrap;
  background: none;
  border-radius: 0;
  line-height: 1;
  transition: color .15s ease;
}

/* Glowing underline — slides in from left on hover, stays on active */
.ta-nav-link::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--primary-hi);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(168,85,247,.65), 0 0 16px rgba(168,85,247,.30);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform .22s ease;
}

.ta-nav-link:hover {
  color: #c084fc;
  text-decoration: none;
  background: none;
}

.ta-nav-link:hover::after {
  transform: scaleX(1);
}

.ta-nav-link.active {
  color: var(--primary-hi);
  font-weight: 600;
  background: none;
}

.ta-nav-link.active::after {
  transform: scaleX(1);
}

/* Light theme */
[data-theme="light"] .ta-nav-link       { color: var(--primary); }
[data-theme="light"] .ta-nav-link:hover,
[data-theme="light"] .ta-nav-link.active { color: var(--primary-hi); }
[data-theme="light"] .ta-nav-link::after {
  background: var(--primary);
  box-shadow: 0 0 6px rgba(124,58,237,.45), 0 0 12px rgba(124,58,237,.20);
}

/* =========================================================
   Public Profile
   ========================================================= */
.pp-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.pp-title {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: .2px;
  color: var(--text-100);
}

.pp-meta {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.pp-toolbar {
  margin-top: var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.pp-search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-xs);
  border: 1px solid var(--border-subtle);
}

.pp-search label {
  font-weight: 900;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-300);
  white-space: nowrap;
  margin: 0;
}

.pp-search input {
  border: 0;
  outline: none;
  background: transparent !important;
  color: var(--text-100);
  padding: 0;
  width: 100%;
  box-shadow: none !important;
}

.pp-search input::placeholder { color: var(--text-muted); }

.pp-count {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-md);
  background: var(--surface-xs);
  color: var(--text-200);
  font-size: 12px;
  font-weight: 900;
}

.pp-table thead th {
  color: var(--text-100) !important;
  border-bottom: 1px solid var(--border-strong) !important;
}

.pp-table tbody td {
  border-top: 1px solid var(--border-md) !important;
  color: var(--text-100);
}

.pp-sort {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-300);
  font-weight: 900;
}

.pp-sort:hover { color: var(--text-100); }

.pp-sort-ind {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border-md);
  background: var(--surface-xs);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1;
}

.pp-sort[aria-pressed="true"] .pp-sort-ind {
  color: var(--text-100);
  border-color: rgba(34,211,238,.45);
  box-shadow: 0 0 0 2px rgba(34,211,238,.18);
}

.pp-ticker   { font-weight: 900; letter-spacing: .02em; color: var(--text-100); }
.pp-name     { color: var(--text-200); }
.pp-right    { text-align: right; }

.pp-footnote {
  padding: 16px 22px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

/* =========================================================
   HEALTH SCORING & ISSUER ANALYSIS
   ========================================================= */

/* Health label badges */
.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.4;
}

.health-badge.strong   { background: rgba(16,185,129,.15); color: #059669; border: 1px solid rgba(16,185,129,.35); }
.health-badge.healthy  { background: rgba(16,185,129,.10); color: #10B981; border: 1px solid rgba(16,185,129,.25); }
.health-badge.mixed    { background: rgba(245,158,11,.15);  color: #D97706; border: 1px solid rgba(245,158,11,.35); }
.health-badge.weak     { background: rgba(249,115,22,.15);  color: #EA580C; border: 1px solid rgba(249,115,22,.30); }
.health-badge.stressed { background: rgba(239,68,68,.15);   color: #DC2626; border: 1px solid rgba(239,68,68,.30); }
.health-badge.loading  { background: var(--surface-sm); color: var(--text-muted); border: 1px solid var(--border-subtle); }
.health-badge.na       { background: var(--surface-xs); color: var(--text-muted); border: 1px solid var(--border-subtle); }

/* Action label badges */
.action-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.action-badge.add    { background: rgba(16,185,129,.15);  color: #059669; border: 1px solid rgba(16,185,129,.35); }
.action-badge.hold   { background: rgba(99,102,241,.15);  color: #6366F1; border: 1px solid rgba(99,102,241,.30); }
.action-badge.reduce { background: rgba(249,115,22,.15);  color: #EA580C; border: 1px solid rgba(249,115,22,.30); }
.action-badge.review { background: rgba(239,68,68,.15);   color: #DC2626; border: 1px solid rgba(239,68,68,.30); }

/* Sub-score progress bars */
.score-track {
  height: 6px;
  background: var(--score-track-bg);
  border-radius: 999px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .4s ease;
}

.score-fill.strong   { background: #10B981; }
.score-fill.healthy  { background: #34D399; }
.score-fill.mixed    { background: #F59E0B; }
.score-fill.weak     { background: #F97316; }
.score-fill.stressed { background: #EF4444; }

/* Score ring */
.score-ring {
  width: 72px;
  height: 72px;
  position: relative;
  flex-shrink: 0;
}

.score-ring svg { transform: rotate(-90deg); }

.score-ring .ring-bg {
  fill: none;
  stroke: var(--ring-track-bg);
  stroke-width: 6;
}

.score-ring .ring-val {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset .5s ease;
}

.score-ring .ring-val.strong   { stroke: #10B981; }
.score-ring .ring-val.healthy  { stroke: #34D399; }
.score-ring .ring-val.mixed    { stroke: #F59E0B; }
.score-ring .ring-val.weak     { stroke: #F97316; }
.score-ring .ring-val.stressed { stroke: #EF4444; }

.score-ring .ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
  color: var(--text-100);
}

.score-ring .ring-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Stock detail header */
.stock-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  color: var(--text-100) !important;
}

.stock-header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stock-ticker-lg {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -.01em;
  color: var(--text-100);
}

.stock-name-lg {
  font-size: 15px;
  color: var(--text-200);
}

.stock-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.stock-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.stock-grid,
.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: var(--space-xl);
}

@media (max-width: 980px) {
  .stock-grid,
  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

/* Financials table */
.fin-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text-100) !important;
  background: transparent !important;
}

.fin-table thead,
.fin-table tbody,
.fin-table tr,
.fin-table th,
.fin-table td {
  background: transparent !important;
}

.fin-table th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-200) !important;
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border-md);
}

.fin-table th:first-child { text-align: left; }

.fin-table td {
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-100) !important;
  text-align: right;
  border-bottom: 1px solid var(--border-subtle);
}

.fin-table td:first-child {
  text-align: left;
  color: var(--text-200) !important;
  font-weight: 500;
}

.fin-table tr:last-child td { border-bottom: none; }

.fin-table tbody tr:hover td {
  background: var(--hover-bg) !important;
}

/* KPI tiles */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-md);
}

.kpi-tile {
  background: var(--surface-sm);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text-100) !important;
}

.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-100);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Valuation band bar */
.val-band-track {
  position: relative;
  height: 10px;
  background: linear-gradient(90deg, #10B981 0%, #F59E0B 50%, #EF4444 100%);
  border-radius: 999px;
  margin: 8px 0;
}

.val-band-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%,-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-800);
  border: 3px solid var(--surface-800);
  box-shadow: 0 0 0 2px var(--val-marker-ring);
}

/* Thesis / rating form */
.rating-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-md);
}

.rating-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-100) !important;
}

.rating-field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-200) !important;
}

.rating-field textarea,
.rating-field input,
.rating-field select {
  color: var(--text-100) !important;
  background: var(--input-bg) !important;
}

.rating-stars {
  display: flex;
  gap: 4px;
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.rating-stars input[type=radio] { display: none; }

.rating-stars label {
  font-size: 20px;
  cursor: pointer;
  color: var(--star-empty);
  transition: color .15s;
  text-transform: none;
  letter-spacing: normal;
  margin: 0;
}

.rating-stars label:hover,
.rating-stars label:hover ~ label,
.rating-stars input[type=radio]:checked ~ label {
  color: #F59E0B;
}

/* Sub-score rows */
.subscore-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--subscore-divider);
}

.subscore-row:last-child { border-bottom: none; }

.subscore-label {
  flex: 0 0 160px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-200);
}

.subscore-track { flex: 1; }

.subscore-val {
  flex: 0 0 36px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-100);
  font-variant-numeric: tabular-nums;
}

/* Analysis link */
.analysis-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 700;
  background: rgba(14,165,233,.10);
  color: var(--cyan);
  border: 1px solid rgba(14,165,233,.25);
  text-decoration: none;
  transition: background .15s, border-color .15s;
}

.analysis-link:hover {
  background: rgba(14,165,233,.18);
  border-color: rgba(14,165,233,.45);
}

/* Flash messages */
.flash-wrap {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-subtle);
  color: var(--text-100);
  background: var(--surface-sm);
}

.flash.notice,
.flash.success {
  background: rgba(16,185,129,.12);
  border-color: rgba(16,185,129,.3);
  color: #10B981;
}

.flash.alert,
.flash.error {
  background: rgba(239,68,68,.12);
  border-color: rgba(239,68,68,.3);
  color: #EF4444;
}

/* =========================================================
   NEW STANDARDIZED HELPERS FOR CONSISTENT UX
   ========================================================= */

/* Page sections */
.section-card + .section-card {
  margin-top: var(--space-xl);
}

.split-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.inline-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 13px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-md);
}

.stat-tile {
  background: var(--surface-sm);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text-100) !important;
}

.stat-tile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  color: var(--text-300) !important;
  margin-bottom: 6px;
}

.stat-tile-value {
  font-size: 22px;
  font-weight: 900;
  color: var(--text-100) !important;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-tile-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted) !important;
}

/* Utility alignment */
.text-right { text-align: right; }
.text-left  { text-align: left; }
.text-center { text-align: center; }

.flex-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.stack-xs > * + * { margin-top: var(--space-xs); }
.stack-sm > * + * { margin-top: var(--space-sm); }
.stack-md > * + * { margin-top: var(--space-md); }
.stack-lg > * + * { margin-top: var(--space-lg); }

/* Safer inheritance for dark cards/tables/forms */
.card a,
.card p,
.card span,
.card strong,
.card small,
.card div,
.stock-header a,
.stock-header p,
.stock-header span,
.fin-table a,
.fin-table p,
.fin-table span,
.rating-field span,
.rating-field small {
  color: inherit;
}

/* Responsive helpers */
@media (max-width: 900px) {
  .page-shell,
  .ta-page,
  .stock-page,
  .container {
    padding: 18px;
  }

  .page-title,
  .ta-page-title {
    font-size: 26px;
  }

  .stock-ticker-lg {
    font-size: 28px;
  }
}

@media (max-width: 640px) {
  .card,
  .surface-card,
  .panel {
    padding: 18px;
    border-radius: 16px;
  }

  .page-title,
  .ta-page-title {
    font-size: 24px;
  }

  .stock-ticker-lg {
    font-size: 24px;
  }

  .subscore-row {
    flex-wrap: wrap;
  }

  .subscore-label,
  .subscore-val,
  .subscore-track {
    flex: 1 1 100%;
  }

  .subscore-val {
    text-align: left;
  }
}

/* ── TOOLTIPS ────────────────────────────────────────────── */
.tip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.tip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 800;
  font-style: normal;
  cursor: help;
  margin-left: 5px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.15);
  line-height: 1;
  transition: background .15s, color .15s;
}

.tip-icon:hover {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.tip-box {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%);
  background: #1A2060;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-200);
  width: 210px;
  z-index: 200;
  text-align: left;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  white-space: normal;
}

/* Arrow */
.tip-box::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1A2060;
}

.tip-wrap:hover .tip-box {
  display: block;
}

/* Light theme adjustments */
[data-theme="light"] .tip-icon {
  background: rgba(0,0,0,.08);
  border-color: rgba(0,0,0,.12);
}

[data-theme="light"] .tip-box {
  background: #FFFFFF;
  border-color: rgba(0,0,0,.12);
  color: var(--text-200);
  box-shadow: 0 4px 16px rgba(15,21,53,.12);
}

[data-theme="light"] .tip-box::after {
  border-top-color: #FFFFFF;
}
