/* Ultra-Trading PWA — dark theme, financial-dashboard aesthetic.
 *
 * Layout strategy:
 *   - Desktop: top app bar + horizontal tab nav, content fills.
 *   - Mobile: tab nav moves to bottom (thumb-reach), top bar stays.
 *   - Single CSS file, no preprocessor, no build step.
 *   - CSS variables for theming so a future light-mode toggle is one
 *     [data-theme] attribute switch.
 */

:root {
  /* Spacing scale */
  --space-0: 0.25rem;
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;

  /* Dark palette (default). Light palette below in [data-theme="light"]. */
  --bg-base:    #0d1117;  /* GitHub-dark-style canvas */
  --bg-elev-1:  #161b22;  /* panels, cards */
  --bg-elev-2:  #21262d;  /* table headers, hover */
  --bg-elev-3:  #30363d;  /* active row, modal */
  --border:     #30363d;
  --border-soft:#21262d;
  --text-primary:   #e6edf3;
  --text-secondary: #9ba6b3;
  --text-muted:     #6e7681;
  --accent:         #58a6ff;  /* link / focus */
  --accent-soft:    rgba(88, 166, 255, 0.12);
  --success:        #3fb950;
  --warning:        #d29922;
  --danger:         #f85149;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
               "Segoe UI Emoji";
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas,
               "Liberation Mono", "Courier New", monospace;

  --radius-1: 4px;
  --radius-2: 6px;
  --radius-3: 10px;

  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.2);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Light theme override — set [data-theme="light"] on <html> (or body)
 * to flip the palette. Keeps the same variable names so every UI
 * element re-themes automatically without per-rule overrides.
 * Palette inspired by GitHub Light. */
[data-theme="light"] {
  --bg-base:    #f6f8fa;
  --bg-elev-1:  #ffffff;
  --bg-elev-2:  #eaeef2;
  --bg-elev-3:  #d0d7de;
  --border:     #d0d7de;
  --border-soft:#e1e4e8;
  --text-primary:   #1f2328;
  --text-secondary: #57606a;
  --text-muted:     #6e7681;
  --accent:         #0969da;
  --accent-soft:    rgba(9, 105, 218, 0.10);
  --success:        #1a7f37;
  --warning:        #9a6700;
  --danger:         #cf222e;

  --shadow-1: 0 1px 0 rgba(31, 35, 40, 0.04);
  --shadow-2: 0 4px 16px rgba(31, 35, 40, 0.12);
}

/* Re-tint the rating + priority + stale-dot pills for the light theme.
 * Their backgrounds use hardcoded rgba(<dark-tone>, alpha) which reads
 * fine on dark but looks washed-out on light — bump alpha + use the
 * theme's success/danger so they retain contrast. */
[data-theme="light"] .rating-buy,
[data-theme="light"] .priority-badge.priority-0 {
  background: rgba(26, 127, 55, 0.14);
  border-color: rgba(26, 127, 55, 0.35);
}
[data-theme="light"] .rating-sell {
  background: rgba(207, 34, 46, 0.14);
  border-color: rgba(207, 34, 46, 0.35);
}
[data-theme="light"] .trade-confirm-rule {
  background: rgba(154, 103, 0, 0.10);
  border-color: rgba(154, 103, 0, 0.30);
}
[data-theme="light"] button.danger {
  background: rgba(207, 34, 46, 0.10);
  border-color: rgba(207, 34, 46, 0.40);
}
[data-theme="light"] button.danger:hover {
  background: rgba(207, 34, 46, 0.20);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--bg-base);
  display: grid;
  grid-template-rows: auto auto 1fr;
  /* Account for iOS safe area */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elev-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand-mark {
  color: var(--accent);
  font-size: 1.1em;
}
.brand-name {
  font-size: 1rem;
}

.status {
  margin-left: auto;
  cursor: pointer;
  font-size: 1.3em;
  line-height: 1;
  color: var(--success);
  user-select: none;
}
.status.degraded { color: var(--warning); }
.status.offline  { color: var(--danger); }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-2);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  font-size: 1.1em;
  line-height: 1;
}
button.ghost:hover {
  background: var(--bg-elev-2);
}

/* --- Tab nav --- */
.tabnav {
  display: flex;
  gap: 2px;
  padding: 0 var(--space-3);
  background: var(--bg-elev-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  font-size: 0.95em;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.tab:hover {
  color: var(--text-primary);
  background: var(--bg-elev-2);
}
.tab[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

/* --- Content area --- */
.content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-3);
  background: var(--bg-base);
}

.panel {
  max-width: 1200px;
  margin: 0 auto;
}
.panel[hidden] { display: none; }

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.panel-toolbar h2 {
  margin: 0;
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text-primary);
}
.panel-toolbar-actions {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  flex-wrap: wrap;
}

input, select, button {
  font-family: var(--font-sans);
  font-size: 0.9em;
  background: var(--bg-elev-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--space-1) var(--space-2);
}
input:focus, select:focus, button:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

button {
  cursor: pointer;
  background: var(--bg-elev-2);
}
button:hover {
  background: var(--bg-elev-3);
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
}

/* --- Markdown render --- */
.markdown {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
  padding: var(--space-4);
  line-height: 1.65;
  word-wrap: break-word;
}
.markdown h1, .markdown h2, .markdown h3 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}
.markdown h1 { font-size: 1.4em; }
.markdown h2 {
  font-size: 1.15em;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: var(--space-1);
}
.markdown h3 { font-size: 1.0em; }
.markdown h1:first-child, .markdown h2:first-child, .markdown h3:first-child {
  margin-top: 0;
}
.markdown a {
  color: var(--accent);
  text-decoration: none;
}
.markdown a:hover { text-decoration: underline; }
.markdown code {
  background: var(--bg-elev-2);
  color: var(--text-primary);
  padding: 1px 5px;
  border-radius: var(--radius-1);
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.markdown pre {
  background: var(--bg-elev-2);
  border-radius: var(--radius-2);
  padding: var(--space-2);
  overflow-x: auto;
  font-size: 0.85em;
}
.markdown pre code { background: transparent; padding: 0; }
.markdown table {
  border-collapse: collapse;
  margin: var(--space-2) 0;
  width: 100%;
  font-size: 0.92em;
}
.markdown table th, .markdown table td {
  border: 1px solid var(--border-soft);
  padding: var(--space-1) var(--space-2);
  text-align: left;
}
.markdown table th {
  background: var(--bg-elev-2);
  font-weight: 600;
}
.markdown blockquote {
  margin: var(--space-2) 0;
  padding-left: var(--space-3);
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
}
.markdown ul, .markdown ol {
  padding-left: var(--space-4);
}
.markdown strong { color: var(--text-primary); }
.markdown em { color: var(--text-secondary); }

/* --- Watchlist table --- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
}
.watchlist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.watchlist-table th, .watchlist-table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  white-space: nowrap;
}
.watchlist-table th {
  background: var(--bg-elev-2);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
  user-select: none;
}
.watchlist-table th:hover {
  background: var(--bg-elev-3);
}
.watchlist-table tr:hover td {
  background: var(--bg-elev-2);
}
.watchlist-table td.symbol {
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.watchlist-table td.tags {
  font-size: 0.85em;
  color: var(--text-secondary);
}
.watchlist-table td.gain { color: var(--success); font-weight: 500; }
.watchlist-table td.loss { color: var(--danger); font-weight: 500; }
.watchlist-table td.spark-cell {
  padding: 2px var(--space-1);
  vertical-align: middle;
}
.sparkline {
  display: block;
}

/* --- Data-staleness dot ---
 * Tiny coloured indicator next to a row's symbol showing how old the
 * fundamentals snapshot is. Green < 24h, amber < 7d, red older. */
.stale-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  cursor: help;
}
.stale-fresh { background: var(--success); }
.stale-warn  { background: var(--warning); }
.stale-old   { background: var(--danger); }

/* --- Article-TOC (briefing right-sidebar + journal in-body strip) ---
 * Shared class so both surfaces use the same visual vocabulary.
 * Briefing places it as a right-column inside .briefing-layout;
 * journal places it as a sticky strip inside the body area. */
.article-toc[hidden] { display: none; }
.article-toc-label {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}
.article-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.article-toc-list li {
  margin: 0;
}
.article-toc-list a {
  display: block;
  padding: 4px 8px;
  border-radius: var(--radius-1);
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.article-toc-list a:hover {
  color: var(--text-primary);
  background: var(--bg-elev-1);
}
.article-toc-list a.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* --- Today briefing layout (content + sticky TOC) ---
 * Desktop: 2-col grid, TOC sticks on the right.
 * Mobile (<768px): TOC collapses to a horizontal-scroll strip above
 * the content via the @media block further down. */
.briefing-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: var(--space-4);
}
.briefing-toc {
  position: sticky;
  top: 80px;  /* below sticky topbar + tabnav */
  align-self: start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  font-size: 0.9em;
  padding-left: var(--space-2);
  border-left: 1px solid var(--border-soft);
}

/* Journal in-body TOC — sticky horizontal strip above the article body.
 * Same .article-toc-list base styles, but here it sits inline-flex
 * across the top so the file content takes the full column width. */
.journal-body-wrap {
  display: flex;
  flex-direction: column;
  overflow-y: auto;  /* the article scrolls inside the wrap */
}
.journal-body-wrap .article-toc {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--bg-base);
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--space-2);
}
.journal-body-wrap .article-toc-list {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
  font-size: 0.85em;
}
.journal-body-wrap .article-toc-list a {
  border-left: none;
  white-space: nowrap;
}
.journal-body-wrap .article-toc-list a.active {
  border-left: none;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
  background: transparent;
}
.journal-body-wrap .article-toc-label {
  display: none;
}

/* --- Ticker pinned header (sub-tabs + metrics tiles) ---
 * One sticky wrapper containing both children, so they scroll as a
 * unit and don't fight for the same top:0 sticky offset. */
.ticker-pinned {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--bg-base);
  padding-top: var(--space-1);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-soft);
}
.ticker-pinned[hidden] { display: none; }

/* --- Ticker sub-tab strip --- */
.ticker-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0 0 var(--space-2) 0;
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border-soft);
}
.ticker-subtabs[hidden] { display: none; }
.subtab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-1);
  cursor: pointer;
  font-size: 0.9em;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}
.subtab:hover {
  background: var(--bg-elev-2);
  color: var(--text-primary);
}
.subtab.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(88, 166, 255, 0.3);
  font-weight: 500;
}
section.bundle-section[hidden] { display: none; }

/* --- Ticker metrics card row ---
 * Sticky horizontal row of 6 metric tiles above the bundle markdown.
 * Keeps Last / PT / Mcap / Range / Beta / Rating visible while the
 * user scrolls through the long-form analysis text. */
.ticker-metrics {
  /* Sticky behaviour now provided by the parent .ticker-pinned wrapper,
   * which scrolls subtabs + metrics together as one unit. */
  background: var(--bg-base);
  padding-bottom: var(--space-2);
}
.ticker-metrics-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
  font-size: 0.92em;
}
.ticker-metrics-symbol {
  font-weight: 700;
  font-size: 1.1em;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.ticker-metrics-name {
  color: var(--text-secondary);
  margin-right: var(--space-2);
}
.ticker-metrics-asof {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.85em;
  font-family: var(--font-mono);
}
.ticker-metrics-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  display: inline-block;
  font-size: 0.78em;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.3);
}
.priority-badge {
  display: inline-block;
  font-size: 0.78em;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-1);
  background: var(--bg-elev-2);
  color: var(--text-secondary);
}
.priority-badge.priority-0 {
  background: rgba(63, 185, 80, 0.18);
  color: var(--success);
}
.priority-badge.priority-1 {
  background: var(--accent-soft);
  color: var(--accent);
}
.priority-badge.priority-2 {
  background: var(--bg-elev-2);
  color: var(--text-muted);
}
.etf-badge {
  display: inline-block;
  font-size: 0.72em;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-1);
  background: var(--bg-elev-3);
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

/* "→ Log trade" button in the ticker-pinned header. Sits next to the
 * asof timestamp (which has margin-left: auto), pushing this button
 * to the far right of the row. */
.ticker-trade-jump {
  font-size: 0.85em;
  padding: 2px 10px;
}

/* --- Analyst rating pill (Watchlist table + ticker-metrics card) ---
 * Same vocabulary as recommendation_key from yfinance: strong_buy /
 * buy / hold / sell / strong_sell. */
.rating-badge {
  display: inline-block;
  font-size: 0.78em;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.rating-buy {
  background: rgba(63, 185, 80, 0.18);
  color: var(--success);
  border: 1px solid rgba(63, 185, 80, 0.35);
}
.rating-sell {
  background: rgba(248, 81, 73, 0.18);
  color: var(--danger);
  border: 1px solid rgba(248, 81, 73, 0.35);
}
.rating-hold {
  background: var(--bg-elev-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.rating-none {
  color: var(--text-muted);
}

/* Smaller chip variant for table cells (Watchlist tag column). */
.chip-sm {
  font-size: 0.7em;
  padding: 0 6px;
}

/* Clickable chip variant (recent-tickers row). */
.chip-clickable {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85em;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.3);
}
.chip-clickable:hover {
  background: rgba(88, 166, 255, 0.25);
  border-color: var(--accent);
}

/* --- Recent-tickers row (above Ticker tab symbol input) --- */
.recent-tickers {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-1) 0 var(--space-3) 0;
  flex-wrap: wrap;
}
.recent-tickers-label {
  font-size: 0.85em;
  color: var(--text-muted);
}
.recent-tickers-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ticker-metrics-grid {
  display: grid;
  /* 6 tiles on desktop; auto-wrap on narrower screens via auto-fit + minmax */
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-2);
}
.metric-card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--space-2) var(--space-2);
  min-height: 60px;
}
.metric-label {
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.metric-value {
  font-size: 1.15em;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.2;
}
.metric-value.gain  { color: var(--success); }
.metric-value.loss  { color: var(--danger); }
.metric-sub {
  font-size: 0.78em;
  color: var(--text-secondary);
  margin-top: 2px;
}
.metric-sub.gain { color: var(--success); }
.metric-sub.loss { color: var(--danger); }

/* --- Journal --- */
.journal-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--space-3);
  height: calc(100vh - 200px);
}
.journal-sidebar {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
  padding: var(--space-2);
  overflow-y: auto;
}
#journal-filter {
  width: 100%;
  margin-bottom: var(--space-2);
}
.journal-tree {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.9em;
}
.journal-tree li {
  padding: var(--space-0) var(--space-1);
  cursor: pointer;
  border-radius: var(--radius-1);
}
.journal-tree li:hover {
  background: var(--bg-elev-2);
}
.journal-tree li.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Grouped sidebar: <details> per top-level directory, with a count. */
.journal-group {
  margin: var(--space-1) 0;
}
.journal-group > summary {
  cursor: pointer;
  font-size: 0.78em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: var(--space-0) var(--space-1);
  user-select: none;
  list-style-position: outside;
}
.journal-group > summary:hover {
  color: var(--text-secondary);
}
.journal-group > ul {
  list-style: none;
  padding: 0 0 0 var(--space-2);
  margin: 0;
}
.journal-group-count {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}
.journal-group-root {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-2) 0;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: var(--space-1);
}

/* Recent files (top of Journal sidebar). Same visual treatment as the
 * file tree below, just under a distinct label. */
.journal-recent {
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border-soft);
}
.journal-recent-label {
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: var(--space-0);
  padding-left: var(--space-1);
}
.journal-recent ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.88em;
}
.journal-recent li {
  padding: var(--space-0) var(--space-1);
  cursor: pointer;
  border-radius: var(--radius-1);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.journal-recent li:hover {
  background: var(--bg-elev-2);
  color: var(--text-primary);
}
.journal-recent li.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.journal-body {
  /* Scroll is now on .journal-body-wrap so the sticky article-TOC has
   * a proper scrolling ancestor. Article itself just flows naturally. */
}

/* --- Trade form --- */
.trade-form {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 720px;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.form-row.two-col {
  flex-direction: row;
  gap: var(--space-3);
}
.form-row.two-col > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.form-row label {
  font-size: 0.85em;
  color: var(--text-secondary);
  font-weight: 500;
}
.form-row input, .form-row select, .form-row textarea {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: var(--space-2);
  border-radius: var(--radius-2);
  font-family: var(--font-sans);
  font-size: 0.95em;
}
.form-row textarea {
  font-family: var(--font-mono);
  resize: vertical;
  min-height: 60px;
}
.action-buttons {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}
.action-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-2);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.action-btn:hover {
  background: var(--bg-elev-3);
  color: var(--text-primary);
}
.action-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.action-btn[data-action="buy"].active,
.action-btn[data-action="cover"].active {
  background: rgba(63, 185, 80, 0.12);
  color: var(--success);
  border-color: var(--success);
}
.action-btn[data-action="sell"].active,
.action-btn[data-action="short"].active {
  background: rgba(248, 81, 73, 0.12);
  color: var(--danger);
  border-color: var(--danger);
}
.form-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-2);
}
.form-actions button {
  padding: var(--space-2) var(--space-4);
  font-weight: 500;
}
.form-actions button[type="submit"] {
  background: var(--accent);
  color: var(--bg-base);
  border-color: var(--accent);
}
.form-actions button[type="submit"]:hover {
  background: #79b9ff;
}
.trade-preview {
  background: var(--bg-elev-2);
  border-left: 3px solid var(--accent);
  padding: var(--space-3);
  border-radius: var(--radius-2);
  font-size: 0.92em;
}
.trade-preview .success {
  color: var(--success);
  margin-bottom: var(--space-1);
}
.trade-preview .error {
  color: var(--danger);
}
.recent-trades-heading {
  margin-top: var(--space-5);
  margin-bottom: var(--space-2);
  font-size: 1em;
  font-weight: 600;
  color: var(--text-primary);
}
.watchlist-table td.action-buy { color: var(--success); }
.watchlist-table td.action-sell { color: var(--danger); }
.watchlist-table td.action-short { color: var(--warning); }
.watchlist-table td.action-cover { color: var(--accent); }

@media (max-width: 768px) {
  .form-row.two-col {
    flex-direction: column;
  }
}

/* --- Signal toolbar + modal --- */
.signal-toolbar {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.signal-toolbar-label {
  color: var(--text-secondary);
  font-size: 0.9em;
}
.signal-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-2);
  cursor: pointer;
  font-size: 0.9em;
}
.signal-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-3);
  padding: var(--space-4);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.modal h3 {
  margin: 0 0 var(--space-1) 0;
  font-size: 1.05em;
  font-weight: 600;
}

/* --- Trade discretionary-limit confirmation modal ---
 * Visually distinct from the regular signal modal — orange warning
 * accent + a "danger" button so it doesn't feel like a routine OK. */
.trade-confirm-modal h3 {
  color: var(--warning);
}
.trade-confirm-summary {
  background: var(--bg-elev-2);
  border-left: 3px solid var(--warning);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-1);
  font-family: var(--font-mono);
  font-size: 0.95em;
  margin: 0;
}
.trade-confirm-rule {
  background: rgba(210, 153, 34, 0.08);
  border: 1px solid rgba(210, 153, 34, 0.25);
  border-radius: var(--radius-2);
  padding: var(--space-2) var(--space-3);
  font-size: 0.9em;
  color: var(--text-secondary);
  line-height: 1.5;
}
.trade-confirm-prompt {
  margin: var(--space-1) 0 0 0;
  font-weight: 500;
}
button.danger {
  background: rgba(248, 81, 73, 0.18);
  color: var(--danger);
  border: 1px solid rgba(248, 81, 73, 0.4);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-2);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95em;
}
button.danger:hover {
  background: rgba(248, 81, 73, 0.28);
  border-color: var(--danger);
}

/* --- Keyboard-shortcut help overlay --- */
.shortcut-help {
  max-width: 460px;
}
.shortcut-table {
  width: 100%;
  border-collapse: collapse;
}
.shortcut-table td {
  padding: var(--space-1) 0;
  color: var(--text-secondary);
}
.shortcut-table td:first-child {
  width: 80px;
  text-align: left;
}
kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-weight: 600;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: var(--radius-1);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  color: var(--text-primary);
  text-align: center;
}
.shortcut-hint {
  font-size: 0.85em;
  margin: 0;
}

/* --- Loading skeletons ---
 * Shape-matched placeholders replace "Loading…" text so the user sees
 * the layout immediately and the eventual content paints in place
 * rather than rearranging. Subtle shimmer signals activity without
 * being distracting. */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elev-1) 0%,
    var(--bg-elev-2) 50%,
    var(--bg-elev-1) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-1);
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-line {
  height: 14px;
  margin: 8px 0;
}
.skeleton-line.short  { width: 35%; }
.skeleton-line.medium { width: 60%; }
.skeleton-line.long   { width: 85%; }
.skeleton-line.full   { width: 100%; }
.skeleton-heading {
  height: 20px;
  width: 30%;
  margin: 18px 0 10px 0;
}
.skeleton-block {
  height: 48px;
  margin: var(--space-2) 0;
}
.skeleton-tile {
  height: 60px;
  border-radius: var(--radius-2);
}
.skeleton-cell {
  height: 12px;
  display: inline-block;
  vertical-align: middle;
}
/* Respect reduced-motion users — keep the layout but skip the shimmer. */
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev-3);
  color: var(--text-primary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-2);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Mobile responsive --- */
@media (max-width: 768px) {
  body {
    grid-template-rows: auto 1fr auto;
  }
  .tabnav {
    order: 3;
    border-top: 1px solid var(--border);
    border-bottom: none;
    padding: var(--space-1);
    justify-content: space-around;
  }
  .tab {
    flex: 1;
    text-align: center;
    padding: var(--space-2) var(--space-1);
    font-size: 0.85em;
  }
  .tab[aria-selected="true"] {
    border-bottom-color: transparent;
    background: var(--accent-soft);
    color: var(--accent);
  }
  .content {
    padding: var(--space-2);
  }
  .journal-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .journal-sidebar {
    max-height: 220px;
  }

  /* Watchlist: collapse the 12-column table into per-row cards.
   * Each <td> becomes a labelled key:value line so Edwin sees all the
   * data without horizontal scrolling. The data-label attribute (set
   * in app.js when rendering rows) supplies the column header. */
  .watchlist-table,
  .watchlist-table thead,
  .watchlist-table tbody,
  .watchlist-table tr,
  .watchlist-table th,
  .watchlist-table td {
    display: block;
    width: auto;
  }
  .watchlist-table thead {
    display: none;
  }
  .watchlist-table tbody {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }
  .watchlist-table tr {
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-2);
    padding: var(--space-2);
  }
  .watchlist-table tr:hover td {
    background: transparent;  /* override the desktop row-hover */
  }
  .watchlist-table td {
    border: none;
    padding: 2px 0;
  }
  .watchlist-table td[data-label]::before {
    content: attr(data-label) ": ";
    display: inline-block;
    min-width: 80px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  .watchlist-table td.symbol {
    font-size: 1.1em;
    padding-bottom: var(--space-1);
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: var(--space-1);
  }
  .watchlist-table td.symbol::before {
    display: none;  /* the symbol speaks for itself */
  }
  .table-scroll {
    overflow-x: visible;  /* no horizontal scroll on cards */
  }
  /* Briefing TOC: collapse 2-col → 1-col, TOC becomes a horizontal
     scroll strip pinned to the top of the briefing area. */
  .briefing-layout {
    grid-template-columns: 1fr;
  }
  .briefing-toc {
    position: sticky;
    top: 60px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding-left: 0;
    border-left: none;
    border-bottom: 1px solid var(--border-soft);
    padding-bottom: var(--space-1);
    margin-bottom: var(--space-2);
    background: var(--bg-base);
    z-index: 4;
  }
  .briefing-toc .article-toc-label { display: none; }
  .briefing-toc .article-toc-list {
    display: flex;
    gap: var(--space-1);
    flex-wrap: nowrap;
  }
  .briefing-toc .article-toc-list li {
    flex: 0 0 auto;
  }
  .briefing-toc .article-toc-list a {
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    white-space: nowrap;
  }
  .briefing-toc .article-toc-list a.active {
    border-left: none;
    border-bottom-color: var(--accent);
    background: transparent;
  }
}
