/* =========================
   Dark theme base
   ========================= */
/* =========================
   THEME TOKENS BY BODY CLASS
   ========================= */

/* Fallback: if no class present, use Breakout */
body:not(.style-standard):not(.style-breakout) {
  --bg: #0b0d10;
  --fg: #e9eef3;
  --muted: #9aa7b2;
  --card: #12161b;
  --accent: #3a8bff;
  --ok: #1fbf75;
  --bad: #ff5a5f;

  --row-odd: rgba(255, 255, 255, .02);
  --row-even: rgba(255, 255, 255, .05);
  --row-hover: rgba(58, 139, 255, .12);
  --table-border: #1c2430;
  --table-head: #11161c;
  --card-border: #1b2430;

  /* Charts (Breakout default) */
  --lwc-bg: #0E1012;
  --lwc-fg: #AEB6C2;
  --lwc-grid: #14161a;
  --lwc-scale-border: #191B20;

  /* Monochrome candles */
  --lwc-candle-up: #C9CED6;
  --lwc-candle-down: #93989c;
  --lwc-wick-up: #9FA6B2;
  --lwc-wick-down: #8E95A1;

  /* Accents */
  --accent-teal: #3EC1D3;
  --accent-orange: #F39C12;
  --accent-base: #3EC1D3;
  --accent-dip: #E77AEF;

  /* Baseline (P&L) */
  --lwc-bl-top-line: rgba(38, 166, 154, 1);
  --lwc-bl-top-fill1: rgba(38, 166, 154, 0.12);
  --lwc-bl-top-fill2: rgba(38, 166, 154, 0.04);
  --lwc-bl-bot-line: rgba(239, 83, 80, 1);
  --lwc-bl-bot-fill1: rgba(239, 83, 80, 0.04);
  --lwc-bl-bot-fill2: rgba(239, 83, 80, 0.12);

  /* Crosshair */
  --lwc-xhair-vert-color: #C3BCDB44;
  --lwc-xhair-vert-width: 2;
  --lwc-xhair-vert-style: solid;
  --lwc-xhair-vert-label-bg: #3EC1D3;

  --lwc-xhair-horz-color: #3EC1D3;
  --lwc-xhair-horz-width: 1;
  --lwc-xhair-horz-style: solid;
  --lwc-xhair-horz-label-bg: #3EC1D3;
}

/* Breakout (current monochrome style) */
body.style-breakout {
  --bg: #0b0d10;
  --fg: #e9eef3;
  --muted: #9aa7b2;
  --card: #12161b;
  --accent: #3a8bff;
  --ok: #1fbf75;
  --bad: #ff5a5f;

  --row-odd: rgba(255, 255, 255, .02);
  --row-even: rgba(255, 255, 255, .05);
  --row-hover: rgba(58, 139, 255, .12);
  --table-border: #1c2430;
  --table-head: #11161c;
  --card-border: #1b2430;

  --lwc-bg: #0E1012;
  --lwc-fg: #AEB6C2;
  --lwc-grid: #14161a;
  --lwc-scale-border: #191B20;

  --lwc-candle-up: #C9CED6;
  --lwc-candle-down: #93989c;
  --lwc-wick-up: #9FA6B2;
  --lwc-wick-down: #8E95A1;

  --accent-teal: #3EC1D3;
  --accent-orange: #F39C12;
  --accent-base: #3EC1D3;
  --accent-dip: #E77AEF;

  --lwc-bl-top-line: rgba(38, 166, 154, 1);
  --lwc-bl-top-fill1: rgba(38, 166, 154, 0.12);
  --lwc-bl-top-fill2: rgba(38, 166, 154, 0.04);
  --lwc-bl-bot-line: rgba(239, 83, 80, 1);
  --lwc-bl-bot-fill1: rgba(239, 83, 80, 0.04);
  --lwc-bl-bot-fill2: rgba(239, 83, 80, 0.12);

  --lwc-xhair-vert-color: #C3BCDB44;
  --lwc-xhair-vert-width: 2;
  --lwc-xhair-vert-style: solid;
  --lwc-xhair-vert-label-bg: #3EC1D3;

  --lwc-xhair-horz-color: #3EC1D3;
  --lwc-xhair-horz-width: 1;
  --lwc-xhair-horz-style: solid;
  --lwc-xhair-horz-label-bg: #3EC1D3;
}

/* Standard (typical green/red chart) */
body.style-standard {
  --bg: #0b0d10;
  --fg: #e9eef3;
  --muted: #9aa7b2;
  --card: #12161b;
  --accent: #3a8bff;
  --ok: #1fbf75;
  --bad: #ff5a5f;

  --row-odd: rgba(255, 255, 255, .02);
  --row-even: rgba(255, 255, 255, .05);
  --row-hover: rgba(58, 139, 255, .12);
  --table-border: #2a2f36;
  --table-head: #141a21;
  --card-border: #21262d;

  --lwc-bg: #0b0d10;
  --lwc-fg: #e9eef3;
  --lwc-grid: #1f232a;
  /* a bit brighter grid */
  --lwc-scale-border: #2a2f36;

  /* classic candles */
  --lwc-candle-up: #26a69a;
  --lwc-candle-down: #ef5350;
  --lwc-wick-up: #1f8f83;
  --lwc-wick-down: #d04441;

  --accent-teal: #26a69a;
  /* MA20 etc. */
  --accent-orange: #ffa726;
  /* price line/volume spikes */
  --accent-base: #26a69a;
  /* base breakout */
  --accent-dip: #ab47bc;
  /* dip breakout */

  /* P&L baseline fills a bit stronger */
  --lwc-bl-top-line: rgba(38, 166, 154, 1);
  --lwc-bl-top-fill1: rgba(38, 166, 154, 0.20);
  --lwc-bl-top-fill2: rgba(38, 166, 154, 0.06);
  --lwc-bl-bot-line: rgba(239, 83, 80, 1);
  --lwc-bl-bot-fill1: rgba(239, 83, 80, 0.06);
  --lwc-bl-bot-fill2: rgba(239, 83, 80, 0.20);

  --lwc-xhair-vert-color: #C3BCDB88;
  --lwc-xhair-vert-width: 1;
  --lwc-xhair-vert-style: solid;
  --lwc-xhair-vert-label-bg: #2b2f36;

  --lwc-xhair-horz-color: #8aa0b5;
  --lwc-xhair-horz-width: 1;
  --lwc-xhair-horz-style: solid;
  --lwc-xhair-horz-label-bg: #2b2f36;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
}

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

a:hover {
  text-decoration: underline;
}

nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #0f1318;
  border-bottom: 1px solid #1b2128;
}

.nav-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: .6rem .9rem;
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  margin-right: .5rem;
}

.spacer {
  flex: 1;
}

.nav a {
  padding: .25rem .5rem;
  border-radius: .35rem;
}

.nav a.active {
  background: #18202a;
}

.content {
  max-width: 1200px;
  margin: 1rem auto;
  padding: 0 .9rem;
}

.flashes {
  list-style: none;
  margin: .5rem 0;
  padding: 0;
}

.flashes li {
  background: #17202a;
  border: 1px solid #25313d;
  border-radius: .5rem;
  padding: .5rem .75rem;
  margin: .25rem 0;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  font-variant-numeric: tabular-nums;
}

.up {
  color: var(--ok);
}

.down {
  color: var(--bad);
}

.neutral,
span.neutral {
  color: var(--muted) !important;
}

.btn {
  display: inline-block;
  border: 1px solid #2a3947;
  background: #15202b;
  border-radius: .5rem;
  padding: .35rem .6rem;
  color: var(--fg);
  text-decoration: none;
}

.btn:hover {
  background: #1a2733;
}

.btn-secondary {
  background: #121a23;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: .9rem;
}

.dashboard.tight {
  gap: .6rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: .8rem;
  padding: .8rem;
}

.card h2 {
  margin: .25rem 0 .5rem;
  font-size: 1.25rem;
}

/* Tables: dark defaults */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.table th,
.table td {
  padding: .35rem .45rem;
  border-bottom: 1px solid var(--table-border);
  vertical-align: middle;
  font-size: .875rem;
  line-height: 1.2;
}

.table thead th {
  font-weight: 600;
  text-align: left;
  background: var(--table-head);
  position: sticky;
  top: 0;
  z-index: 1;
}

.table.compact th,
.table.compact td {
  padding: .25rem .35rem;
}

.table.no-zebra tbody tr:nth-child(odd) {
  background: transparent;
}

/* Keep Awesomplete above the chart canvas */
.awesomplete,
.awesomplete ul,
.awesomplete>ul {
  z-index: 10000 !important;
}

/* Create a higher stacking context for the toolbar card */
.card.toolbar {
  position: relative;
  z-index: 5;
}

.card.chart-card {
  position: relative;
  z-index: 1;
}

.right-align {
  text-align: right;
}

.bad-stocks-words {
  background-color: orange;
  font-weight: bold;
}

/* Tooltip */
.hint {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted #888;
}

.hint:focus,
.hint:hover {
  outline: none;
}

.hint:focus::after,
.hint:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 10;
  white-space: normal;
  max-width: 28rem;
  background: #111;
  color: #fff;
  padding: .5rem .6rem;
  border-radius: .5rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
  transform: translateY(6px);
  font-size: .85rem;
  line-height: 1.2;
}

.hint:focus::before,
.hint:hover::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 100%;
  border: 6px solid transparent;
  border-top-color: #111;
}

/* Buttons */
.btn-danger {
  background: #e53935;
  color: #fff;
  border: 1px solid #e53935;
  border-radius: .5rem;
  cursor: pointer;
  padding: .6rem 1rem;
}

.btn-danger:hover,
.btn-danger:focus {
  background: #c62828;
  border-color: #c62828;
}

.btn-danger:active {
  background: #b71c1c;
  border-color: #b71c1c;
}

/* === Chart playback buttons === */
.chart-playback {
  padding: .5rem .75rem;
}

.playback-controls {
  display: flex;
  gap: .6rem;
  justify-content: center;
  align-items: center;
}

.play-btn {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  /* square with small rounding */
  border: 1px solid #2a3947;
  background: #0f141a;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.play-btn:hover {
  background: #1a2733;
}

.play-btn:active {
  transform: translateY(1px);
}

.play-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.play-label {
  min-width: 140px;
  text-align: center;
  padding: .2rem .5rem;
  color: var(--fg);
  background: #0f141a;
  border: 1px solid #2a3947;
  border-radius: 6px;
}

/* Hero */
.hero {
  max-width: 900px;
  margin: 4rem auto 2rem;
  padding: 0 1rem;
  text-align: center;
}

.hero h1 {
  font-size: 2.5rem;
  margin: .25rem 0;
}

.hero p {
  color: #c9d3dc;
  margin: 0 auto 1.25rem;
  max-width: 680px;
}

.cta {
  display: flex;
  gap: .75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary {
  background: #111;
  color: #fff;
}

.btn-ghost {
  border: 1px solid #111;
  color: #111;
}

/* Grid cards */
.grid {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.card h3 {
  margin: .25rem 0 .5rem;
}

.muted {
  color: var(--muted);
}

/* Footer */
footer {
  max-width: 900px;
  margin: 3rem auto 2rem;
  padding: 0 1rem;
  color: var(--muted);
  text-align: center;
}

/* Forms */
.form {
  max-width: 420px;
  margin: 3rem auto;
  padding: 1rem;
}

.form h1 {
  margin: .25rem 0 1rem;
}

.field {
  margin: .6rem 0;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: .25rem;
}

.field input {
  width: 100%;
  padding: .6rem;
  border: 1px solid #2a3947;
  border-radius: .5rem;
  background: #0e141a;
  color: var(--fg);
}

.actions {
  margin-top: 1rem;
  display: flex;
  gap: .5rem;
}

/* Duplicate .btn kept for completeness */
.btn {
  padding: .6rem 1rem;
  border-radius: .5rem;
  border: 1px solid #2a3947;
  background: #15202b;
  color: var(--fg);
  text-decoration: none;
}

.btn-secondary {
  background: #121a23;
  color: var(--fg);
}

/* ===== Dashboard layout for portfolio ===== */
.dashboard {
  max-width: 1000px;
  margin: 1rem auto;
  padding: 0 .5rem;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  grid-auto-flow: dense;
}

/* Make every card take the full row */
.dashboard>.card {
  grid-column: 1 / -1;
}

/* Optional: variant you can toggle with a class */
.dashboard.one-per-row {
  grid-template-columns: 1fr;
}

/* full-row cards regardless of column count */
.span-full {
  grid-column: 1 / -1;
}

/* tighter tables on narrow screens */
@media (max-width: 520px) {

  .table th,
  .table td {
    font-size: .82rem;
    padding: .24rem .32rem;
  }
}

/* allow two-column spans where used */
.span-2 {
  grid-column: span 2;
}

/* Table tweaks */
.table th {
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* headings inside cards */
h1 {
  font-size: 1.4rem;
  margin: .75rem 0;
}

/* ===== Dense screen layout (opt-in with .tight) ===== */
.dashboard.tight {
  max-width: 1000px;
  gap: 8px;
  padding: 0 .15rem;
}

.table.tight th,
.table.tight td {
  padding: .18rem .28rem;
  font-size: .84rem;
  line-height: 1.15;
}

/* allow long names to wrap in tight tables */
.table.tight td.ellipsis {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

/* summary table: allow content */
.table.summary.tight td {
  overflow: visible;
  text-overflow: clip;
}

/* tight tables should auto-size columns */
.table.tight {
  table-layout: auto;
}

.table.tight .muted {
  font-size: .8em;
}

/* Trim card padding in tight mode */
.dashboard.tight>.card {
  padding: .75rem;
}

/* Chart holder */
#chart {
  position: relative;
}

/* Simulation guide */
:root {
  --sim: #3f51b5;
  --sim-70: rgba(63, 81, 181, .70);
  --sim-55: rgba(63, 81, 181, .55);
  --sim-12: rgba(63, 81, 181, .12);
}

.sim-guide {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  pointer-events: none;
  z-index: 4;
  transform: translateX(0);
}

.sim-guide-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-left: 2px solid var(--sim-55);
}

.sim-guide-badge {
  position: absolute;
  top: 200px;
  left: 0;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  line-height: 1;
  padding: 4px 8px;
  background: #0f141a;
  color: var(--fg);
  border: 1px solid var(--sim-70);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

.sim-badge-pill {
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--sim-12);
  color: var(--sim);
}

.sim-badge-date {
  font-variant-numeric: tabular-nums;
}

/* ===== Scanner table polish (dark) ===== */
#scanner {
  table-layout: fixed;
}

/* Make the whole header row sticky at the top */
#scanner thead {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--card);
}

/* Reset sticky th (thead already sticky) */
#scanner thead th {
  position: static;
}

/* First column (header + body) sticks to the left */
#scanner thead th:first-child,
#scanner tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 7;
  background: var(--card);
  background-clip: padding-box;
  /* avoids bleed in Safari */
}

#scanner td {
  text-align: right;
}

#scanner td:first-child {
  text-align: left;
}

#scanner tbody tr:hover {
  background: var(--row-hover);
}

/* periodic divider */
#scanner tbody tr:nth-child(10n) td {
  padding-bottom: .6rem;
  border-bottom: 6px solid #0e141a;
}

/* ===== Dark-friendly zebra + detail rows (overrides) ===== */

/* Default: transparent; alternate body rows with subtle tints */
.table tr {
  background: transparent;
}

.table tbody tr:nth-child(even) {
  background: var(--row-even);
}

/* Zebra that only stripes the visible main rows (your .clickable rows) */
.table.zebra tbody tr.detail {
  background: transparent !important;
}

.table.zebra tbody tr:nth-child(odd of .clickable) {
  background: var(--row-odd);
}

.table.zebra tbody tr:nth-child(even of .clickable) {
  background: var(--row-even);
}

/* Expandable detail rows (for open/closed positions) */
.table tbody tr.detail {
  background: rgba(255, 255, 255, .04) !important;
}

/* ===== Print: show everything, no truncation ===== */
@media print {
  .dashboard {
    max-width: none;
    margin: 0;
    padding: 0;
    gap: 6px;
  }

  .card {
    border: 0;
    padding: .4rem 0;
    box-shadow: none;
    background: transparent;
  }

  /* Hide non-essential UI for space (optional) */
  .toolbar,
  .chart-card,
  #chart {
    display: none !important;
  }

  /* Loosen tables and remove zebra for print */
  .table {
    table-layout: auto !important;
    border-spacing: 0;
  }

  .table th,
  .table td {
    padding: 2px 4px;
    font-size: 11px;
    line-height: 1.15;
  }

  .ellipsis,
  .table.summary td {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  table col {
    width: auto !important;
  }

  @page {
    margin: 10mm;
  }
}

/* symbol styles */
.symbol-cell {
  text-align: center;
  width: 1.8rem;
}

.sym {
  font-size: 13px;
  line-height: 1;
  display: inline-block;
}

.sym.up {
  color: var(--ok);
}

/* ▲ */
.sym.down {
  color: var(--bad);
}

/* ▼ */
.sym.new {
  color: var(--ok);
}

/* ◆ green */
.sym.re {
  color: #f4d03f;
}

/* ◆ yellow */

/* === Order page layout helpers === */
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
}

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

/* === Order page layout helpers === */
.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .75rem;
}

@media (max-width: 900px) {
  .form-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .form-grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Required/invalid field highlighting */
.field input:required:invalid {
  border-color: var(--bad) !important;
  box-shadow: inset 0 0 0 1px var(--bad);
}

.field input:focus:invalid {
  outline: none;
  border-color: var(--bad) !important;
  box-shadow: 0 0 0 2px rgba(255, 90, 95, .35);
}

/* Custom invalid highlight (set via JS .invalid) */
.field input.invalid {
  border-color: var(--bad) !important;
  box-shadow: inset 0 0 0 1px var(--bad);
}

.field input.invalid:focus {
  outline: none;
  border-color: var(--bad) !important;
  box-shadow: 0 0 0 2px rgba(255, 90, 95, .35);
}

.order-stats {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.order-stats>div {
  display: inline-flex;
  gap: .4rem;
}

.order-type-row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.order-type-option {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .35rem .55rem;
  background: #0e141a;
  border: 1px solid #2a3947;
  border-radius: .5rem;
  user-select: none;
}

.order-type-option input {
  accent-color: var(--accent);
}

.order-type-option.disabled {
  opacity: .45;
  cursor: not-allowed;
}

.order-subrow {
  margin-top: .4rem;
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

/* Disabled CTA visual */
button[disabled],
.btn[disabled] {
  opacity: .6;
  cursor: not-allowed;
  filter: grayscale(20%);
}

.btn-block {
  width: 100%;
  padding: 1rem;
  font-weight: 700;
}

/* === Order page: stat grid (labels over values) === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .75rem;
  margin: .5rem 0 1rem;
}

.stat-grid .stat label {
  display: block;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: .25rem;
}

.stat-grid .stat .value {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }
}

/* === Segmented radio groups === */
.seg {
  display: inline-flex;
  border: 1px solid #2a3947;
  background: #0e141a;
  border-radius: .5rem;
  overflow: hidden;
}

.seg label {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.seg label+label span {
  border-left: 1px solid #2a3947;
}

.seg input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg label span {
  display: inline-block;
  padding: .45rem .8rem;
  cursor: pointer;
  user-select: none;
}

.seg label:hover span {
  background: #121a23;
}

.seg input[type="radio"]:checked+span {
  background: #18202a;
  color: var(--fg);
  font-weight: 600;
}

.seg-full {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0;
  /* keep the built-in borders touching */
}
