:root {
  --bg: #0a0e13;
  --bg-alt: #0d1218;
  --card: #131a22;
  --card-hover: #182028;
  --border: #232c37;
  --text: #e8edf3;
  --text-dim: #8996a6;
  --text-faint: #56626f;
  --brand: #14b8a6;
  --brand-hover: #0d9488;
  --buy: #16c784;
  --buy-bg: rgba(22, 199, 132, .1);
  --sell: #ea3943;
  --sell-bg: rgba(234, 57, 67, .1);
  --warn: #f5a524;
  --warn-bg: rgba(245, 165, 36, .12);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .heading-font { font-family: "Space Grotesk", "Inter", sans-serif; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 18px; }

/* Header */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  position: sticky; top: 0; z-index: 30;
}
.topbar .container { display: flex; align-items: center; gap: 22px; height: 58px; }
.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand img { width: 26px; height: 26px; }
.brand span { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand small { color: var(--text-faint); font-size: 11px; font-weight: 600; margin-left: 4px; }

.tabs-top { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 3px; margin-left: auto; }
.tabs-top button {
  border: none; background: transparent; color: var(--text-dim); cursor: pointer;
  font-size: 13px; font-weight: 600; padding: 7px 16px; border-radius: 6px;
}
.tabs-top button.active { background: var(--brand); color: #06211d; }

.user-pill { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 999px; background: var(--buy); box-shadow: 0 0 0 3px var(--buy-bg); }

/* Asset ticker strip */
.ticker { border-bottom: 1px solid var(--border); background: var(--bg); overflow-x: auto; }
.ticker-row { display: flex; gap: 2px; padding: 0 12px; }
.ticker-item {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 16px;
  border: none; background: transparent; cursor: pointer; border-bottom: 2px solid transparent;
  min-width: 108px; text-align: left;
}
.ticker-item.active { border-bottom-color: var(--brand); background: var(--card); }
.ticker-item .sym { font-size: 12px; font-weight: 700; color: var(--text); }
.ticker-item .px { font-size: 13px; font-weight: 700; font-family: "Space Grotesk", sans-serif; }
.ticker-item .chg { font-size: 11px; font-weight: 700; }
.chg.up { color: var(--buy); }
.chg.down { color: var(--sell); }

/* Layout */
.terminal { display: grid; grid-template-columns: 1fr 340px; gap: 16px; padding: 16px 0 40px; align-items: start; }
@media (max-width: 900px) { .terminal { grid-template-columns: 1fr; } }

.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em;
}

/* Order book: buy left / sell right */
.book-grid { display: grid; grid-template-columns: 1fr 1fr; }
.book-col { padding: 6px 0; }
.book-col + .book-col { border-left: 1px solid var(--border); }
.book-col-head {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 6px 14px;
  font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em;
}
.book-col.buy .book-col-head span:first-child, .book-col.buy .label-title { color: var(--buy); }
.book-col.sell .book-col-head span:first-child, .book-col.sell .label-title { color: var(--sell); }
.label-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 8px 14px 2px; }

.book-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 5px 14px;
  font-size: 12.5px; cursor: pointer; position: relative; border: none; background: transparent; width: 100%; text-align: left; color: var(--text);
}
.book-row:hover { background: var(--card-hover); }
.book-col.buy .book-row .px { color: var(--buy); font-weight: 700; }
.book-col.sell .book-row .px { color: var(--sell); font-weight: 700; }
.book-row .qty, .book-row .tot { color: var(--text-dim); text-align: right; }
.book-row.mine { background: rgba(20,184,166,.08); }
.book-row.mine .px::after { content: "•"; color: var(--brand); margin-left: 5px; }
.book-mid {
  padding: 10px 14px; text-align: center; font-size: 13px; font-weight: 800;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  grid-column: 1 / -1; font-family: "Space Grotesk", sans-serif;
}

/* Order ticket */
.ticket { padding: 16px; }
.side-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.side-toggle button {
  flex: 1; padding: 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-alt); color: var(--text-dim); font-weight: 700; font-size: 13px; cursor: pointer;
}
.side-toggle button.buy.active { background: var(--buy-bg); border-color: var(--buy); color: var(--buy); }
.side-toggle button.sell.active { background: var(--sell-bg); border-color: var(--sell); color: var(--sell); }

.field { margin-bottom: 12px; }
.field label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); font-weight: 600; margin-bottom: 5px; }
.field input, .field select {
  width: 100%; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 7px;
  padding: 10px 11px; color: var(--text); font-size: 13.5px; font-family: inherit;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); }

.summary { background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 12px 0; font-size: 12.5px; }
.summary-row { display: flex; justify-content: space-between; padding: 4px 0; }
.summary-row strong { font-family: "Space Grotesk", sans-serif; }
.summary-row.total { border-top: 1px dashed var(--border); margin-top: 3px; padding-top: 7px; }

.stop-toggle {
  display: flex; align-items: center; gap: 6px; background: none; border: none; color: var(--brand);
  font-size: 12px; font-weight: 700; cursor: pointer; padding: 4px 0; margin-bottom: 8px;
}
.stop-fields { display: none; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.stop-fields.open { display: grid; }
.stop-hint { grid-column: 1 / -1; font-size: 11px; color: var(--text-faint); }

.btn-submit {
  width: 100%; padding: 13px; border-radius: 8px; border: none; font-weight: 800; font-size: 14px; cursor: pointer;
}
.btn-submit.buy { background: var(--buy); color: #06231b; }
.btn-submit.sell { background: var(--sell); color: #2b0507; }
.btn-submit:hover { filter: brightness(1.08); }

.form-error { background: var(--sell-bg); color: var(--sell); border-radius: 7px; padding: 8px 10px; font-size: 12px; font-weight: 600; margin-bottom: 10px; display: none; }

/* My orders */
.orders-wrap { padding: 14px 16px 30px; }
.chip-row { display: flex; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border); background: var(--card); color: var(--text-dim); font-size: 12px; font-weight: 700;
  padding: 6px 13px; border-radius: 999px; cursor: pointer;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #06211d; }

table.orders { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.orders th { text-align: left; color: var(--text-faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.orders td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.orders tr:last-child td { border-bottom: none; }
.side-badge { font-size: 10.5px; font-weight: 800; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; }
.side-badge.compra { background: var(--buy-bg); color: var(--buy); }
.side-badge.venda { background: var(--sell-bg); color: var(--sell); }
.stop-badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px; background: var(--warn-bg); color: var(--warn); margin-right: 4px; display: inline-block; }
.status-badge { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.status-badge.aberta { background: rgba(255,255,255,.08); color: var(--text-dim); }
.status-badge.executada { background: var(--buy-bg); color: var(--buy); }
.status-badge.cancelada { background: rgba(255,255,255,.06); color: var(--text-faint); }
.cancel-link { background: none; border: none; color: var(--sell); font-size: 12px; font-weight: 700; cursor: pointer; }

.empty { text-align: center; padding: 50px 14px; color: var(--text-faint); font-size: 13px; }

.toast-wrap { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast {
  background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  border-radius: 8px; padding: 10px 14px; font-size: 12.5px; max-width: 300px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.buy { border-left-color: var(--buy); }
.toast.sell { border-left-color: var(--sell); }
.toast.warn { border-left-color: var(--warn); }
.toast b { display: block; margin-bottom: 2px; }

.disclaimer { color: var(--text-faint); font-size: 11px; text-align: center; padding: 10px 0 0; }

@media (max-width: 640px) {
  .book-grid { grid-template-columns: 1fr; }
  .book-col + .book-col { border-left: none; border-top: 1px solid var(--border); }
  .brand small { display: none; }
}
