:root {
  /* Binance's own dark + gold palette - fitting since this is literally
     a Binance bot, and recognizable rather than an arbitrary scheme. */
  --bg: #0b0e11;
  --panel: #181a20;
  --border: #2b3139;
  --text: #eaecef;
  --muted: #848e9c;
  --green: #0ecb81;
  --red: #f6465d;
  --amber: #f59e0b;
  --accent: #f0b90b;
  --accent-contrast: #0b0e11;
}

* { box-sizing: border-box; }

/* Without this, iOS Safari auto-inflates text size unpredictably based on
   the device's accessibility text-size setting and viewport heuristics -
   different elements scale by different amounts, making font sizes look
   inconsistent/"unusual" rather than matching what the CSS specifies. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Safari doesn't reliably stretch inputs to fill a flex-column label the
   way Chrome does - they default to an intrinsic width instead, visually
   disconnected from the label around them. Explicit width is the standard
   fix; inline styles (the fixed-width number inputs in Risk/Backtest)
   still win over this since inline always beats an external stylesheet. */
label input[type="text"], label input[type="password"], label input[type="number"] {
  width: 100%;
}

html, body {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), var(--bg));
}

header h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--border);
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }
.dot.warn { background: var(--amber); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  max-width: 1200px;
  margin: 0 auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab-btn:hover { filter: none; color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel {
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}
.tab-panel.hide { display: none; }

@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 10px; padding: 16px; }
  header h1 { font-size: 26px; }
  .header-badges { flex-wrap: wrap; gap: 6px !important; }
  .badge { font-size: 11px; padding: 3px 8px; }
  .tabs {
    padding: 8px 12px;
    overflow-x: visible;
    flex-wrap: wrap;
    gap: 6px;
    border-bottom: 1px solid var(--border);
  }
  .tab-btn {
    flex: 1 1 calc(33% - 6px);
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 6px;
  }
  .tab-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
  .tab-panel { grid-template-columns: 1fr; padding: 16px; gap: 14px; }
  .modal-card { width: 100%; padding: 18px; }
  /* Recent Orders has 7 columns - still wider than a phone screen even in
     single-column mode. Scroll horizontally within the table itself
     instead of blowing out the page's own layout. */
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

.panel {
  /* Grid items default to min-width:auto, meaning a panel with an
     unwrapped-width child (Risk & Sizing's 4-input row, a long single-line
     summary) can force the *whole grid* wider than the viewport instead of
     actually wrapping - min-width:0 lets it shrink to the grid track's
     real available width so flex-wrap inside it works as intended. */
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 12px 0;
}

.panel.full { grid-column: 1 / -1; }

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row .label { color: var(--muted); }

.controls { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
button.secondary { background: var(--border); color: var(--text); }
button.danger { background: var(--red); color: white; }
button:hover { filter: brightness(1.1); }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

.status-pill { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-FILLED { background: #14532d; color: var(--green); }
.status-SUBMITTED { background: #1e3a5f; color: #60a5fa; }
.status-PENDING { background: #3f2d0f; color: var(--amber); }
.status-UNKNOWN { background: #3f2d0f; color: var(--amber); }
.status-FAILED, .status-CANCELED { background: #3f1414; color: var(--red); }

#log { max-height: 260px; overflow-y: auto; font-family: ui-monospace, monospace; font-size: 12px; }
.log-line { padding: 3px 0; border-bottom: 1px solid var(--border); }
.log-INFO { color: var(--text); }
.log-WARN { color: var(--amber); }
.log-ERROR { color: var(--red); }
.log-ts { color: var(--muted); margin-right: 8px; }

.empty { color: var(--muted); font-size: 12px; padding: 8px 0; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#mode-badge { cursor: pointer; }
#mode-badge:hover { filter: brightness(1.2); }

.welcome-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-overlay.hide { display: none; }
.welcome-content { width: 560px; max-width: 90vw; }
.welcome-card {
  flex: 1;
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.welcome-card:hover { border-color: var(--accent); }
