:root {
  color-scheme: light dark;
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-2: #1d2740;
  --border: #2a3454;
  --text: #e7ebf5;
  --muted: #93a0c0;
  --accent: #4fd1a5;
  --accent-2: #6ea8fe;
  --loss: #ff6b6b;
  --debit: #f5b942;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

.back-to-site {
  display: inline-block;
  margin: 0.75rem 0 0 2rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.back-to-site:hover { color: var(--accent-2); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 4rem;
}

header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

header p.subtitle {
  margin: 0;
  color: var(--muted);
}

.disclaimer {
  margin: 1rem 2rem 0;
  padding: 0.75rem 1rem;
  background: #2a2210;
  border: 1px solid #5c4a12;
  color: #ecd07a;
  border-radius: 8px;
  font-size: 0.85rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.field[hidden] { display: none; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.field input, .field select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  min-width: 8rem;
}

.field.tickers input { min-width: 16rem; }

button.primary {
  background: var(--accent);
  color: #06231a;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

button.primary:hover { opacity: 0.9; }
button.primary:disabled { opacity: 0.5; cursor: default; }

#status {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.5rem 0 1.5rem;
  min-height: 1.2em;
}

.ticker-block {
  margin-bottom: 2rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
}

.ticker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.2rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.ticker-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.ticker-header .price { color: var(--accent-2); font-weight: 600; }
.ticker-header .meta { color: var(--muted); font-size: 0.8rem; }

.error-msg {
  padding: 1rem 1.2rem;
  color: var(--loss);
}

.idea-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: 1rem;
  padding: 1.2rem;
}

.idea-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  min-width: 0;
}

.idea-card .strategy-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

.idea-card .attribution {
  color: var(--muted);
  font-size: 0.75rem;
  font-style: italic;
  margin-bottom: 0.6rem;
}

.idea-card .rationale {
  font-size: 0.85rem;
  margin-bottom: 0.7rem;
  line-height: 1.4;
}

.legs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-bottom: 0.7rem;
}

.legs-table th, .legs-table td {
  text-align: left;
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

.legs-table .action-buy { color: var(--accent-2); }
.legs-table .action-sell { color: var(--accent); }

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  font-size: 0.8rem;
}

.stat-row .stat { display: flex; flex-direction: column; }
.stat-row .stat .label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-row .stat .value { font-weight: 600; }
.stat-row .value.positive { color: var(--accent); }
.stat-row .value.negative { color: var(--loss); }

table.contracts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

table.contracts-table th, table.contracts-table td {
  padding: 0.5rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

table.contracts-table th:first-child, table.contracts-table td:first-child { text-align: left; }

table.contracts-table tbody tr:hover { background: var(--panel-2); }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge.call { background: #123a2c; color: var(--accent); }
.badge.put { background: #3a1620; color: var(--loss); }

/* --- Auth --- */

.login-overlay[hidden] { display: none; }

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card h2 { margin: 0; }

.login-card .field { display: flex; flex-direction: column; gap: 0.3rem; }
.login-card label { font-size: 0.8rem; color: var(--muted); }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
}

.password-row {
  display: flex;
  gap: 0.4rem;
}

.password-row input {
  flex: 1;
  min-width: 0;
}

.password-toggle {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.login-error {
  background: #3a1620;
  color: var(--loss);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
}

button.primary.danger { background: var(--loss); color: #2a0a0a; }

/* --- Header / live banner --- */

.live-banner {
  background: #3a1620;
  color: var(--loss);
  text-align: center;
  font-weight: 700;
  padding: 0.6rem;
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--loss);
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.badge-broker {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge-broker.live {
  background: #3a1620;
  color: var(--loss);
  border-color: var(--loss);
}

/* --- Account / orders panels --- */

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.5rem 0;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  min-width: 0; /* let a grid item shrink below its content's intrinsic
                   width (e.g. a nowrap table) instead of overflowing */
}

.panel h2 { margin: 0 0 0.8rem; font-size: 1rem; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: 0.6rem;
}

table.data-table th, table.data-table td {
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.empty-row { color: var(--muted); text-align: center; padding: 1rem 0; }

.mini-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--accent-2);
  border-radius: 5px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.mini-btn:hover { background: var(--border); }

.status-filled { color: var(--accent); }
.status-rejected { color: var(--loss); }
.status-canceled { color: var(--muted); }
.status-pending { color: var(--debit); }

.fill-cell { max-width: 220px; font-size: 0.75rem; color: var(--muted); }

/* --- Confirm-live-order modal --- */

.modal-overlay[hidden] { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--loss);
  border-radius: 12px;
  padding: 1.5rem;
  width: 340px;
}

.modal-card h3 { margin: 0 0 0.6rem; color: var(--loss); }

.modal-card input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  margin: 0.5rem 0 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

/* --- Order ticket modal --- */

.order-ticket-card { width: 380px; text-align: left; }

.order-ticket-card .field[hidden] { display: none; }

.order-ticket-card .field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
}

.order-ticket-card .field input,
.order-ticket-card .field select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  width: 100%;
  margin: 0;
}

.order-ticket-summary {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 1rem;
  line-height: 1.4;
}

.order-ticket-summary strong { color: var(--text); }

.trail-row { display: flex; gap: 0.4rem; }
.trail-row input { flex: 1; min-width: 0; }
.trail-row select { width: 4.5rem; flex-shrink: 0; }

/* --- E*TRADE connection panel --- */

#etradePanel {
  margin-bottom: 1.5rem;
}

.etrade-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 0.8rem;
  line-height: 1.4;
}

.etrade-hint code {
  background: var(--panel-2);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
}

.etrade-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.etrade-verifier-row[hidden] { display: none; }

.etrade-verifier-row {
  display: flex;
  gap: 0.5rem;
}

.etrade-verifier-row input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  min-width: 14rem;
}

.etrade-status {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* --- Mobile --- */

@media (max-width: 640px) {
  .back-to-site { margin: 0.6rem 0 0 1rem; }

  header { padding: 1.1rem 1rem 0.8rem; }
  header h1 { font-size: 1.2rem; }

  .header-row { flex-direction: column; align-items: stretch; gap: 0.6rem; }
  .header-actions { justify-content: space-between; }

  .disclaimer { margin: 0.8rem 1rem 0; font-size: 0.8rem; }

  main { padding: 0 1rem; }

  .controls { flex-direction: column; align-items: stretch; }
  .field, .field.tickers { width: 100%; }
  .field input, .field select, .field.tickers input { min-width: 0; width: 100%; }
  .controls button.primary { width: 100%; }

  .ticker-header { flex-direction: column; align-items: flex-start; gap: 0.3rem; }

  .idea-grid { padding: 0.8rem; gap: 0.8rem; }

  /* Wide tables scroll horizontally within their own box instead of
     forcing the whole page to scroll sideways. legs-table is excluded --
     it holds the Trade button, the one thing on this page that must never
     need a horizontal swipe to reach, so it wraps its text instead. */
  table.data-table, table.contracts-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .legs-table th, .legs-table td { white-space: normal; }
  .legs-table .mini-btn { white-space: nowrap; }

  .stat-row { gap: 0.5rem 0.8rem; }

  .panel { padding: 0.9rem; }
  .panel-grid { margin: 1rem 0; }

  .etrade-controls { flex-direction: column; align-items: stretch; }
  .etrade-verifier-row { flex-direction: column; }
  .etrade-verifier-row input { min-width: 0; width: 100%; }
  .etrade-controls button, .etrade-verifier-row button { width: 100%; }

  .login-overlay, .modal-overlay { padding: 1rem; }
  .login-card, .modal-card { width: 100%; max-width: 340px; }

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