:root {
  --bg: #0b0f14;
  --bg-elevated: #121821;
  --bg-card: #161d28;
  --border: #243041;
  --text: #e8eef7;
  --muted: #8b9bb0;
  --accent: #3d9cf0;
  --accent-2: #c9a227;
  --green: #3ecf8e;
  --red: #f07178;
  --purple: #a78bfa;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, #2a2210 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app { max-width: 1400px; margin: 0 auto; padding: 28px 16px 48px; }

.header {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}
.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-weight: 600;
}
h1 { margin: 0 0 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }

.header-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}
.meta-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.meta-label { color: var(--muted); }
.meta-value { font-family: var(--mono); font-size: 11px; }
.status { color: var(--muted); font-size: 12px; font-family: var(--mono); max-width: 280px; text-align: right; }
#feed-status { font-weight: 600; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.92; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #041018; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger { background: transparent; color: var(--red); border: 1px solid #5a3038; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.summary-grid {
  display: grid;
  /* Keep all summary cards on one row on desktop — avoids a lonely
     "Buy alerts" row with empty space beside/below it */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.summary-card {
  padding: 12px 14px;
  min-width: 0;
}
.summary-card .label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 6px;
  line-height: 1.25;
}
.summary-card .value {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -0.02em;
}
.summary-card .value.small { font-size: 14px; text-transform: capitalize; }
.summary-card.highlight {
  border-color: #3a4f2a;
  background: linear-gradient(145deg, #16241a, var(--bg-card));
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--bg-elevated); }
.tab.active {
  color: var(--text);
  background: var(--bg-elevated);
  border-color: var(--border);
}

.panel { display: none; }
.panel.active { display: block; }
.panel-head { margin-bottom: 14px; }
.panel-head.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.panel-head h2 { margin: 0 0 4px; font-size: 18px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.subhead { margin: 28px 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}
.watchlist-wrap {
  overflow-x: visible;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 11px 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #1c2533;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table .num { text-align: right; font-family: var(--mono); font-size: 12px; }

/*
  Watchlists (desktop): fixed grid so free space goes to Name,
  not into a giant empty middle gap. Actions stay one horizontal row.
*/
.watchlist-wrap {
  overflow-x: auto;
}
.watchlist-table {
  table-layout: fixed;
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
}
.watchlist-table th,
.watchlist-table td {
  padding: 10px 10px;
  vertical-align: middle;
}
.watchlist-table th {
  font-size: 11px;
}
.watchlist-table th.num,
.watchlist-table td.num {
  font-size: 12px;
  white-space: nowrap;
}
/* Column template — Name (2) absorbs leftover width */
.watchlist-table th:nth-child(1),
.watchlist-table td:nth-child(1) { width: 118px; } /* Symbol */
.watchlist-table th:nth-child(2),
.watchlist-table td:nth-child(2) { width: auto; } /* Name */
.watchlist-table th:nth-child(3),
.watchlist-table td:nth-child(3) { width: 88px; } /* Price */
.watchlist-table th:nth-child(4),
.watchlist-table td:nth-child(4) { width: 72px; } /* Chg */
.watchlist-table th:nth-child(5),
.watchlist-table td:nth-child(5) { width: 72px; } /* Chg % */
.watchlist-table th:nth-child(6),
.watchlist-table td:nth-child(6),
.watchlist-table th:nth-child(7),
.watchlist-table td:nth-child(7),
.watchlist-table th:nth-child(8),
.watchlist-table td:nth-child(8) { width: 148px; } /* DCL WCL YCL */
.watchlist-table th:nth-child(9),
.watchlist-table td:nth-child(9) { width: 228px; } /* Actions */

.watchlist-table .col-sym { white-space: nowrap; }
.watchlist-table .sym { font-size: 13px; }
.watchlist-table .sym-exch { font-size: 10px; margin-left: 4px; }
.watchlist-table .name-cell {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watchlist-table .cycle-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watchlist-table .cycle-inner {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}
.watchlist-table .cycle-cell .badge {
  font-size: 10px;
  padding: 3px 6px;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}
.watchlist-table .cycle-meta {
  display: inline;
  margin: 0;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watchlist-table td.actions {
  text-align: right;
  white-space: nowrap;
}
/* Override global .actions { display:flex } which was squeezing the button group */
.watchlist-table td.actions {
  display: table-cell;
}
.watchlist-table .action-btns {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  width: max-content;
  max-width: 100%;
}
.watchlist-table .btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  white-space: nowrap;
  flex: 0 0 auto;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 16px !important;
}
th.sortable:hover { color: var(--text); }
th.sortable::after {
  content: "↕";
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  opacity: 0.35;
}
th.sortable.sorted-asc::after {
  content: "▲";
  opacity: 0.9;
  color: var(--accent);
}
th.sortable.sorted-desc::after {
  content: "▼";
  opacity: 0.9;
  color: var(--accent);
}

.sym {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
}
.sym-exch {
  color: var(--muted);
  font-size: 11px;
  margin-left: 6px;
  font-weight: 500;
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sym-exch::before {
  content: "· ";
  opacity: 0.7;
}
.name-cell { color: var(--muted); max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-family: var(--mono);
  white-space: nowrap;
  line-height: 1.35;
}
.badge-dcl { background: #1a3350; color: #7ec8ff; }
.badge-wcl { background: #2a2450; color: #c4b5fd; }
.badge-ycl { background: #3a2a10; color: #f0c674; }
.badge-none { background: #1a2030; color: #5a6a80; }
.badge-sent { background: #143528; color: var(--green); }
.badge-outbox { background: #3a3010; color: #e6c35c; }
.badge-error { background: #3a1820; color: var(--red); }

.gain-ok { color: var(--green); font-weight: 700; }
.gain-near { color: var(--accent-2); }

.options-controls { display: flex; gap: 8px; align-items: center; }
.options-controls select, .modal input, .modal select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 13px;
}
.options-meta {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
}
.options-chain {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}
.options-chain h4 {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.options-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
@media (max-width: 900px) {
  .options-split { grid-template-columns: 1fr; }
}
.options-side { padding: 8px; }
.options-side + .options-side { border-left: 1px solid var(--border); }
.options-side h5 {
  margin: 4px 8px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.options-legend {
  margin: 0 14px 10px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.spot-pill {
  display: inline-block;
  background: #3a2a10;
  color: #f0c674;
  border: 1px solid #6a5520;
  border-radius: 999px;
  padding: 2px 10px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}
.spot-mark {
  color: #f0c674;
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
  white-space: nowrap;
}
/* Closest strike to current share price */
.data-table tr.spot-row td {
  background: rgba(240, 198, 116, 0.16) !important;
  box-shadow: inset 3px 0 0 #f0c674;
  font-weight: 600;
}
/* In the money */
.data-table tr.itm-row td {
  background: rgba(62, 207, 142, 0.08);
}
/* Out of the money — slightly dimmed */
.data-table tr.otm-row td {
  opacity: 0.85;
}
.data-table tr.spot-row.itm-row td,
.data-table tr.spot-row.otm-row td {
  background: rgba(240, 198, 116, 0.18) !important;
}
#options-expiry {
  min-width: 220px;
  max-width: 320px;
}
@media (max-width: 900px) {
  .options-side + .options-side { border-left: none; border-top: 1px solid var(--border); }
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.setup-card h3 { margin: 0 0 10px; font-size: 15px; }
.setup-card p, .setup-card li { color: var(--muted); font-size: 13px; line-height: 1.5; }
.setup-card ol, .setup-card ul { padding-left: 18px; margin: 8px 0; }
.code {
  background: #0a0e14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: #b8d4f0;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}

.footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.email-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}
.email-form input,
.email-form select {
  width: 100%;
  margin-top: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 13px;
}
.setup-card a { color: var(--accent); }
.hidden-field { display: none !important; }
.email-form .hidden-field.show { display: block !important; }

.chart-card { margin-bottom: 16px; }
.chart-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  font-family: var(--mono);
}
.chart-wrap {
  position: relative;
  height: 380px;
  width: 100%;
}
#price-chart,
#positions-price-chart { cursor: crosshair; }
.chart-wrap-sm { height: 280px; }
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.mini-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.mini-chart-card h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-family: var(--mono);
}
.mini-chart-card .mini-wrap {
  position: relative;
  height: 140px;
}
.discovery-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 8px;
}
@media (max-width: 900px) {
  .discovery-columns { grid-template-columns: 1fr; }
}
.discovery-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.discovery-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px 14px;
  align-items: start;
  transition: border-color 0.15s;
}
.discovery-card:hover { border-color: var(--accent); }
.discovery-card.buy {
  border-color: rgba(62, 207, 142, 0.45);
  box-shadow: 0 0 0 1px rgba(62, 207, 142, 0.12);
}
.discovery-rank {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-2);
  min-width: 28px;
}
.discovery-card h4 {
  margin: 0 0 4px;
  font-size: 15px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}
.discovery-card .sym {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.discovery-card .name { color: var(--muted); font-weight: 500; font-size: 13px; }
.discovery-theme {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 6px;
}
.discovery-reasons {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.discovery-reasons li {
  font-size: 11px;
  font-family: var(--mono);
  background: rgba(61, 156, 240, 0.1);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
}
.discovery-score {
  text-align: right;
  font-family: var(--mono);
}
.discovery-score .val {
  font-size: 20px;
  font-weight: 700;
  color: var(--green);
  display: block;
}
.discovery-score .lbl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.discovery-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 2px;
}
.discovery-px { font-family: var(--mono); font-size: 13px; }

.horizon-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.horizon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.horizon-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
}
.horizon-btn:hover { color: var(--text); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.hidden { display: none !important; }
.modal {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}
.modal h3 { margin: 0 0 4px; }
.modal-sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.modal label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.modal input, .modal select { width: 100%; margin-top: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ========== Mobile / narrow screens ========== */
@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app { padding: 16px 12px 40px; }
  h1 { font-size: 22px; }
  .subtitle { font-size: 13px; }
  .header-right {
    width: 100%;
    justify-content: flex-start;
  }
  .status {
    max-width: none;
    text-align: left;
  }
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .summary-card .value { font-size: 18px; }
  .summary-card { padding: 12px; }

  /* Wrap the tabs. A sideways scroller hid Cycle Fund Trades on iPhone. */
  .tabs {
    flex-wrap: wrap;
    overflow: visible;
    max-width: 100%;
    gap: 6px;
    padding-bottom: 10px;
  }
  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 10px 12px;
    font-size: 13px;
  }

  .panel-head.row {
    flex-direction: column;
  }
  .options-controls {
    width: 100%;
    flex-wrap: wrap;
  }
  .options-controls select {
    flex: 1 1 140px;
    min-width: 0;
  }

  .chart-wrap { height: 280px; }
  .chart-wrap-sm { height: 220px; }
  .chart-meta {
    font-size: 11px;
    word-break: break-word;
  }

  .horizon-toggle {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }
  .horizon-btn {
    flex: 1 1 auto;
    text-align: center;
    padding: 8px 10px;
  }

  .discovery-card {
    grid-template-columns: auto 1fr;
  }
  .discovery-score {
    grid-column: 2;
    text-align: left;
    display: flex;
    gap: 10px;
    align-items: baseline;
  }
  .discovery-score .val { display: inline; font-size: 18px; }
}

@media (max-width: 720px) {
  /* Watchlists become stacked cards — no sideways scroll */
  .watchlist-wrap {
    overflow: visible;
    border: none;
    background: transparent;
  }
  .watchlist-table {
    table-layout: auto;
  }
  .watchlist-table thead {
    display: none;
  }
  .watchlist-table,
  .watchlist-table tbody {
    display: block;
    width: 100%;
  }
  .watchlist-table tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  .watchlist-table tr:hover td {
    background: transparent;
  }
  .watchlist-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(36, 48, 65, 0.55);
    width: 100%;
    text-align: right;
  }
  .watchlist-table td:last-child {
    border-bottom: none;
    padding-top: 10px;
  }
  .watchlist-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    flex: 0 0 72px;
  }
  .watchlist-table td.col-sym {
    display: block;
    text-align: left;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  .watchlist-table td.col-sym::before {
    display: none;
  }
  .watchlist-table td.col-sym .sym {
    font-size: 16px;
  }
  .watchlist-table td.col-sym .sym-exch {
    font-size: 11px;
  }
  .watchlist-table .name-cell {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
  .watchlist-table .col-sym,
  .watchlist-table .name-cell,
  .watchlist-table .col-px,
  .watchlist-table .col-chg,
  .watchlist-table .col-pct,
  .watchlist-table .cycle-cell,
  .watchlist-table .col-actions,
  .watchlist-table td.actions {
    width: auto !important;
  }
  .watchlist-table .cycle-cell {
    align-items: center;
    white-space: normal;
    overflow: visible;
  }
  .watchlist-table .cycle-inner {
    flex-wrap: wrap;
    max-width: none;
  }
  .watchlist-table .cycle-cell .badge {
    font-size: 11px;
  }
  .watchlist-table .cycle-meta {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    overflow: visible;
  }
  .watchlist-table td.actions {
    width: auto;
    white-space: normal;
    display: block;
  }
  .watchlist-table td.actions {
    display: block;
    text-align: left;
  }
  .watchlist-table td.actions::before {
    display: block;
    margin-bottom: 8px;
  }
  .watchlist-table .action-btns {
    display: flex;
    width: 100%;
    gap: 8px;
  }
  .watchlist-table .action-btns .btn {
    flex: 1 1 auto;
    text-align: center;
    padding: 10px 8px;
    font-size: 13px;
  }

  /* Mobile sort: show a compact control above cards */
  .watchlist-mobile-sort {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
  }
  .watchlist-mobile-sort label {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
  }
  .watchlist-mobile-sort select {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    font-family: var(--font);
    font-size: 13px;
  }

  .modal-backdrop { padding: 12px; align-items: flex-end; }
  .modal {
    width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }
}

@media (min-width: 721px) {
  .watchlist-mobile-sort { display: none !important; }
}

/* Positions: same header sort affordance; keep a simple readable table */
#table-positions {
  width: 100%;
}
#panel-positions .watchlist-mobile-sort {
  margin-bottom: 12px;
}

@media (max-width: 420px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }
  .meta-pill { font-size: 11px; padding: 5px 10px; }
  .btn { padding: 10px 12px; }
}

.fund-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.fund-summary .summary-card .value { font-size: 18px; }
.fund-report {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
#table-fund-open td.why,
#table-fund-closed td.why {
  max-width: 280px;
  color: var(--muted);
  font-size: 12px;
}
.fund-charts {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.4fr);
  gap: 12px;
  margin: 8px 0 18px;
}
.fund-chart-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}
.fund-chart-card p { margin: 0 0 8px; font-size: 12px; }
.fund-chart-wrap { height: 280px; }
@media (max-width: 800px) {
  .fund-charts { grid-template-columns: 1fr; }
  .fund-chart-card,
  .fund-chart-wrap { min-width: 0; max-width: 100%; }
  .fund-chart-wrap { height: 240px; }
}

@media (max-width: 720px) {
  #panel-fund .table-wrap {
    overflow: visible;
    border: none;
    background: transparent;
  }
  #panel-fund .data-table thead { display: none; }
  #panel-fund .data-table,
  #panel-fund .data-table tbody { display: block; width: 100%; }
  #panel-fund .data-table tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  #panel-fund .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(36, 48, 65, 0.55);
    width: auto;
    max-width: none;
    text-align: right;
  }
  #panel-fund .data-table td:last-child { border-bottom: none; }
  #panel-fund .data-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    flex: 0 0 88px;
  }
  #panel-fund .data-table td:not([data-label]) {
    display: block;
    text-align: left;
  }
  #panel-fund .data-table td:not([data-label])::before { content: none; }
  #panel-fund .data-table td.sym {
    display: block;
    text-align: left;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  #panel-fund .data-table td.sym::before { content: none; }
  #panel-fund .data-table td.why {
    display: block;
    text-align: left;
    max-width: none;
  }
}
