/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-5);
  border: 1px solid transparent; border-radius: var(--radius-pill);
  background: var(--surface-3); color: var(--text);
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: transform .12s var(--ease), background .15s, opacity .15s;
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary); opacity: .9; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--down-soft); color: var(--down); }
.btn-lg { min-height: 56px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 44px; min-height: 44px; padding: 0; border-radius: 50%;
}
.btn-icon.btn-lg { width: 56px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; }
.field > label { font-size: 14px; font-weight: 550; color: var(--text); }
.field .hint { font-size: 13px; color: var(--muted); }
.input, .select {
  width: 100%; min-height: 46px; padding: 0 var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  transition: border-color .15s, background .15s;
}
.input::placeholder { color: var(--muted); }
.input:hover, .select:hover { border-color: var(--surface-3); }
.input:focus, .select:focus { outline: none; border-color: var(--purple); background: var(--surface); }
.form-grid { display: grid; gap: var(--space-4); }
.form-row { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-error { color: var(--down); font-size: 14px; min-height: 20px; }

/* ---------- OTP input (6 boxes) ---------- */
st-otp-input { display: block; }
.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.otp input {
  width: 100%; aspect-ratio: 3 / 4; min-width: 0;
  border: 2px solid transparent; border-radius: var(--radius);
  background: var(--surface-3); color: var(--text);
  text-align: center; font-size: clamp(24px, 7vw, 40px); font-weight: 500;
  font-variant-numeric: tabular-nums; caret-color: var(--purple);
  transition: border-color .15s, background .15s;
}
.otp input:focus { outline: none; border-color: var(--purple); background: var(--surface-2); }
.otp.invalid input { border-color: var(--down); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  box-shadow: var(--shadow);
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-title { font-size: 15px; font-weight: 600; color: var(--text-2); }

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 12px; border-radius: var(--radius-pill); white-space: nowrap;
  font-size: 13px; font-weight: 600; background: var(--surface-3); color: var(--text-2);
}
.pill-up { background: var(--up-soft); color: var(--up); }
.pill-down { background: var(--down-soft); color: var(--down); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-purple { background: color-mix(in srgb, var(--purple) 16%, transparent); color: var(--purple); }

/* ---------- Segmented control / tabs ---------- */
.segmented {
  display: inline-flex; padding: 4px; gap: 4px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: none; white-space: nowrap;
  min-height: 36px; padding: 0 16px; border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--muted); font-weight: 600; cursor: pointer;
}
.segmented button[aria-selected="true"] { background: var(--surface-3); color: var(--text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 550; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 100; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 8px; width: min(360px, calc(100vw - 32px));
}
.toast {
  padding: 14px 16px; border-radius: var(--radius); background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 14px;
  animation: toast-in .2s var(--ease);
}
.toast.error { border-color: color-mix(in srgb, var(--down) 50%, transparent); }
.toast.success { border-color: color-mix(in srgb, var(--up) 50%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 860px) {
  .toasts { bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom)); }
}

.table .right { text-align: right; }
.table-hover tbody tr { cursor: pointer; transition: background .15s; }
.table-hover tbody tr:hover, .table tr.selected { background: var(--surface-2); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.flash-up { animation: flash-up 1.2s var(--ease); }
.flash-down { animation: flash-down 1.2s var(--ease); }
@keyframes flash-up { from { background: var(--up-soft); } }
@keyframes flash-down { from { background: var(--down-soft); } }
.specs { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.spec { display: grid; gap: 2px; }
.spec .muted { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.spec .num { font-size: 16px; font-weight: 600; word-break: break-all; }

/* ---------- Chart ---------- */
.chart { position: relative; height: clamp(320px, 58vh, 640px); border-radius: var(--radius); overflow: hidden; }
.chart canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; outline: none; }
.chart canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.chart-tooltip {
  position: absolute; top: 8px; left: 10px; right: 80px; display: flex; flex-wrap: wrap; gap: 4px 12px;
  font-size: 12px; color: var(--muted); pointer-events: none; font-variant-numeric: tabular-nums;
}
.chart-tooltip b { color: var(--text); font-weight: 600; }
.chart-tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.sparkline { width: 100%; height: 56px; display: block; }

/* ---------- Spread cards / detail ---------- */
.spread-card { display: grid; gap: var(--space-3); text-decoration: none; transition: border-color .15s, transform .15s; }
.spread-card:hover { border-color: var(--surface-3); transform: translateY(-1px); }
.spread-value { font-size: 28px; font-weight: 600; letter-spacing: -.03em; }
.formula { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); background: var(--surface-2);
  padding: 6px 10px; border-radius: var(--radius-sm); overflow-x: auto; white-space: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px 0 12px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; cursor: pointer;
}
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; }
.chip button:hover { background: var(--surface-3); color: var(--text); }
.popover {
  position: absolute; z-index: 40; min-width: 260px; max-width: min(360px, calc(100vw - 32px)); max-height: 60vh; overflow: auto;
  padding: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.popover button.item { display: grid; width: 100%; text-align: left; gap: 2px; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: none; cursor: pointer; }
.popover button.item:hover { background: var(--surface-2); }
.popover .item small { color: var(--muted); font-size: 12px; }
.price-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-5); }
.price-head .big { font-size: 40px; font-weight: 650; letter-spacing: -.035em; line-height: 1; }
.bidask { display: flex; gap: var(--space-3); }
.bidask div { display: grid; padding: 8px 14px; border-radius: var(--radius); min-width: 110px; }
.bidask .sell { background: var(--down-soft); }
.bidask .buy { background: var(--up-soft); }
.bidask small { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.bidask strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.leg-row {
  display: grid; grid-template-columns: 100px minmax(0, 2fr) 170px 100px 64px 44px; gap: var(--space-3); align-items: start;
  padding-bottom: var(--space-3); border-bottom: 1px solid var(--border);
}
.leg-row > :last-child { padding-top: 26px; }
@media (max-width: 1100px) { .leg-row { grid-template-columns: 90px minmax(0, 1fr) 150px 90px; } }
.picker { position: relative; }
.picker .popover { top: calc(100% + 4px); left: 0; right: 0; max-width: none; }
.formula-input { font-family: var(--font-mono); }
.formula-status { font-size: 13px; min-height: 20px; }
@media (max-width: 860px) {
  .leg-row { grid-template-columns: 1fr 1fr; }
  .price-head .big { font-size: 32px; }
}

/* ---------- Order ticket ---------- */
.spread-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--space-5); align-items: start; }
.ticket-col { position: sticky; top: calc(var(--topbar-h) + var(--space-4)); }
@media (max-width: 1280px) { .spread-layout { grid-template-columns: minmax(0, 1fr); } .ticket-col { position: static; } }
.ticket-sides { display: grid; grid-template-columns: 1fr 1fr; width: 100%; border-radius: var(--radius); }
.ticket-sides button { display: grid; gap: 2px; min-height: 58px; border-radius: calc(var(--radius) - 4px); }
.ticket-sides button strong { font-size: 17px; color: var(--text); }
.ticket-sides button.buy[aria-selected="true"] { background: var(--up-soft); color: var(--up); }
.ticket-sides button.sell[aria-selected="true"] { background: var(--down-soft); color: var(--down); }
.ticket .segmented { width: 100%; }
.ticket .segmented button { flex: 1; }
.btn-buy { background: var(--up); color: #04150e; }
.btn-sell { background: var(--down); color: #1a0606; }
.btn-buy:hover, .btn-sell:hover { opacity: .9; }
.leg-orders summary { cursor: pointer; font-size: 13px; color: var(--text-2); }
.leg-order { display: grid; grid-template-columns: 56px 1fr 96px; gap: 8px; align-items: center; margin-top: 6px; }
.leg-order .select, .leg-order .input { min-height: 38px; }
.ticket-legs td, .ticket-legs th { padding: 8px 6px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.kv { display: grid; gap: 2px; font-size: 13px; }
.kv strong { font-size: 15px; }

.table tr.clickable { cursor: pointer; }
.legs-detail > td { background: var(--surface-2); padding: 4px 12px 12px; }
.legs-detail .table td, .legs-detail .table th { padding: 8px; }

/* ---------- Condition builder ---------- */
.condition-row { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.condition-main { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.operand { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px; padding: 6px; border-radius: var(--radius-sm); background: var(--surface); }
.operand .select, .operand .input, .condition-main > .select { min-height: 38px; width: auto; }
.operand .input.num { width: 110px; }
.operand .input.param { width: 74px; }
.operand .select.tf { width: 72px; }
.condition-main > .select.op { min-width: 150px; align-self: center; }
.param-field { display: grid; gap: 2px; }
.param-field > span { font-size: 11px; color: var(--muted); padding-left: 4px; }
.field > .label { font-size: 14px; font-weight: 550; }
@media (max-width: 860px) { .operand { width: 100%; } }

/* ---------- Account rows / choices ---------- */
.account-row {
  display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
}
.account-row > .dot { width: 10px; height: 10px; }
.inline-form { padding: var(--space-4); border-radius: var(--radius); border: 1px dashed var(--border); }
.choice {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--purple); background: color-mix(in srgb, var(--purple) 8%, transparent); }
.choice.disabled { opacity: .5; cursor: not-allowed; }
.choice input { accent-color: var(--purple); width: 18px; height: 18px; }
@media (max-width: 860px) {
  .account-row { flex-wrap: wrap; }
  .account-row > .row { width: 100%; justify-content: flex-start !important; }
}

/* ---------- Misc ---------- */
.empty {
  display: grid; place-items: center; gap: var(--space-3); text-align: center;
  padding: var(--space-7) var(--space-5); color: var(--muted);
}
.empty svg { width: 40px; height: 40px; opacity: .6; }
.stack { display: grid; gap: var(--space-4); }
.stack > * { min-width: 0; }
.table td.alert-name { min-width: 200px; }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--space-4) 0; }
.icon { width: 20px; height: 20px; flex: none; }
.banner {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4); border-radius: var(--radius); background: var(--warn-soft); color: var(--text);
}
.banner .icon { color: var(--warn); }

/* Automations */
.tranche { display: grid; gap: 10px; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); }
.tranche-head { gap: var(--space-3); align-items: center; }
.tranche .condition-row { background: var(--surface); }
.leg-order-row { gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.leg-order-row .select, .leg-order-row .input { width: auto; min-width: 110px; }
.banner-danger { background: color-mix(in srgb, var(--down) 14%, transparent); }

/* Backtests */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--space-3); }
.metric { display: grid; gap: 4px; padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--surface-2); }
.metric > strong, .metric > .num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.notes { margin: 0; padding-left: 18px; font-size: 13px; display: grid; gap: 2px; }
.hbar { display: grid; grid-template-columns: 56px 1fr 40px; gap: 8px; align-items: center; font-size: 13px; }
.hbar-track { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.hbar-fill { height: 100%; background: var(--purple); border-radius: 5px; }
.progress { flex: 1; min-width: 120px; max-width: 320px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--purple); transition: width .3s; }
.heatmap td.heat { text-align: center; font-size: 12px; min-width: 56px; }
.heatmap th { font-size: 12px; }
.stats-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.table td.num { white-space: nowrap; }

/* Performance */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-4); align-items: start; }
.up-bg { background: var(--up); }
.down-bg { background: var(--down); }
.vbars { display: flex; align-items: stretch; gap: 6px; height: 220px; overflow-x: auto; padding-bottom: 4px; }
.vbar { flex: 1 0 28px; max-width: 64px; display: grid; grid-template-rows: 1fr auto; gap: 4px; text-align: center; font-size: 11px; }
.vbar-area { position: relative; border-bottom: 1px dashed var(--border); border-top: 1px dashed transparent; }
.vbar-area::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--border); }
.vbar-fill { position: absolute; left: 15%; right: 15%; border-radius: 4px; min-height: 2px; }
.pnl-row { display: grid; gap: 6px; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.filters { gap: var(--space-3); flex-wrap: wrap; }
.filters .select, .filters .input { width: auto; min-width: 170px; }
.btn-sm.btn-icon { width: 30px; height: 30px; min-height: 30px; padding: 0; }
