:root {
  --navy: #0b1b2b;
  --navy-soft: #172b40;
  --bg: #f2f5f9;
  --card: #ffffff;
  --ink: #142235;
  --muted: #627083;
  --line: #dde5ee;
  --blue: #2f6bff;
  --blue-soft: #eaf0ff;
  --buy: #1667d9;
  --sell: #d14343;
  --sell-soft: #ffeeee;
  --green: #12805c;
  --green-soft: #e8f7f0;
  --amber: #9a6500;
  --amber-soft: #fff6df;
  --red: #b3261e;
  --red-soft: #ffedea;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: -0.02em; }
h2 { font-size: 17px; }
a { color: var(--blue); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--navy);
  color: #fff;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--blue);
  font-weight: 800;
  font-size: 19px;
  flex: 0 0 auto;
}
.brand-mark.large { width: 58px; height: 58px; font-size: 30px; }
.brand-title { font-size: 19px; font-weight: 750; letter-spacing: -0.01em; }
.brand-sub {
  font-size: 10px;
  color: #9fb3c8;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topmeta { display: flex; align-items: center; gap: 13px; flex-wrap: wrap; justify-content: flex-end; }
.env-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: #173d35;
  color: #c8f4e3;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
body[data-mode="live"] .env-pill { background: #5a2026; color: #ffd3d3; }
.account { color: #dce7f2; font-size: 12px; white-space: nowrap; }
.inline-form { margin: 0; }
.link-button {
  border: 0;
  background: transparent;
  color: #9fb3c8;
  font-size: 12px;
  padding: 4px;
}
.link-button:hover { color: #fff; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 13px 17px 11px;
  font-weight: 650;
  white-space: nowrap;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.container { max-width: 1080px; margin: 0 auto; padding: 22px 18px 44px; }
.view { display: none; }
.view.active { display: block; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.page-head p { margin-top: 3px; }
.grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); gap: 16px; align-items: start; }
.card {
  background: var(--card);
  border: 1px solid #e8edf4;
  border-radius: var(--radius);
  padding: 17px;
  box-shadow: 0 1px 2px rgba(20, 34, 53, 0.04);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { color: var(--muted); font-size: 12px; }
.field.narrow { max-width: 150px; }
.form-row { display: flex; gap: 10px; align-items: flex-start; }
.form-row .field { flex: 1; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9fc;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}
input:focus, select:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.1); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 13px; }
.seg {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px;
  font-weight: 650;
}
.seg.active { background: var(--buy); border-color: var(--buy); color: #fff; }
.seg[data-side="SELL"].active { background: var(--sell); border-color: var(--sell); }
.check-row { display: flex; flex-wrap: wrap; gap: 14px; margin: 5px 0 10px; }
.check { display: inline-flex; align-items: center; gap: 7px; color: var(--ink); font-size: 13px; }
.check input { accent-color: var(--blue); width: 16px; height: 16px; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: #2459dc; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--blue); }
.btn.ghost:hover { border-color: var(--blue); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.wide { width: 100%; padding: 12px; }
.place-area { margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--line); }
#place-hint { margin-bottom: 7px; }
#place-button.sell { background: var(--sell); }
#place-button.buy { background: var(--buy); }

.chip {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
}
.chip.warn { background: var(--amber-soft); color: var(--amber); }
.quote-line { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.quote-line strong { color: var(--ink); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 11px; }
.metrics.strong .metric strong { font-size: 20px; }
.metric { min-width: 0; }
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.formula { color: var(--muted); font-size: 12px; line-height: 1.55; padding: 9px 10px; background: #f7f9fc; border-radius: 9px; }

.notice {
  margin-top: 9px;
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  background: #f7f9fc;
  color: var(--muted);
}
.notice.error { background: var(--red-soft); color: var(--red); }
.notice.warn { background: var(--amber-soft); color: var(--amber); }
.notice.ok { background: var(--green-soft); color: var(--green); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.notice li { margin: 2px 0; }
.empty-state { color: var(--muted); font-size: 13px; padding: 22px 6px; text-align: center; }

.orders-list { display: flex; flex-direction: column; gap: 10px; }
.order-card { background: #fff; border: 1px solid #e8edf4; border-radius: 14px; padding: 13px 15px; }
.order-top { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.badge { border-radius: 6px; padding: 3px 7px; font-size: 10px; font-weight: 750; }
.badge.buy { color: var(--buy); background: var(--blue-soft); }
.badge.sell { color: var(--sell); background: var(--sell-soft); }
.order-title { flex: 1; color: var(--muted); font-size: 12px; }
.order-status { font-size: 11px; font-weight: 700; color: var(--green); }
.order-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.order-metrics span { display: block; color: var(--muted); font-size: 10px; }
.order-metrics strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-id { color: var(--muted); font-size: 10px; margin-top: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kv { display: grid; grid-template-columns: 100px 1fr; gap: 7px 10px; margin: 0 0 13px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.whitelist-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 11px; }
.whitelist-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 9px; background: #f7f9fc; }
.whitelist-row span { font-weight: 650; font-size: 13px; }
.inline-row { display: flex; gap: 8px; }
.inline-row input { flex: 1; }
.note-card { margin-top: 16px; }
.note-card p { color: var(--muted); font-size: 13px; margin-top: 7px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(11, 27, 43, 0.52);
  padding: 18px;
}
.modal-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.28);
}
.modal-card h2 { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 17px; }
.confirm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.confirm-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 5px 0; width: 40%; }
.confirm-table td { text-align: right; font-weight: 650; padding: 5px 0; overflow-wrap: anywhere; }

.login-body { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at top, #17324c 0, var(--navy) 55%, #07111c 100%); }
.login-shell { width: min(410px, 100%); padding: 24px 16px; }
.login-brand { text-align: center; color: #fff; margin-bottom: 22px; }
.login-brand .brand-mark { margin: 0 auto 12px; }
.login-brand h1 { font-size: 25px; }
.login-brand p { color: #9fb3c8; font-size: 12px; margin-top: 5px; }
.login-card { padding: 22px; }
.login-card .field { margin-bottom: 13px; }
.login-card .btn { margin-top: 2px; }
.login-card .notice { margin: 0 0 12px; }
.error-code { font-size: 50px; font-weight: 850; color: var(--blue); line-height: 1; }
.login-card h1 { font-size: 21px; margin: 10px 0 18px; }

@media (max-width: 760px) {
  .topbar { align-items: flex-start; padding: 13px 15px; }
  .brand-sub { max-width: 200px; }
  .topmeta { gap: 8px; justify-content: flex-end; }
  .account { width: 100%; text-align: right; }
  .tabs { padding: 0 10px; }
  .container { padding: 17px 13px 38px; }
  .grid { grid-template-columns: 1fr; }
  .page-head { align-items: center; }
  h1 { font-size: 21px; }
  .form-row { flex-direction: column; }
  .field.narrow { max-width: none; width: 100%; }
  .metrics.strong .metric strong { font-size: 18px; }
  .order-metrics { grid-template-columns: 1fr 1fr; }
  .inline-row { flex-direction: column; }
}


/* Personal single-user mode: keep the order page compact. */
#view-order .page-head p,
#view-order #formula-note,
#view-order #duplicate-note,
#view-order #warnings-box,
#view-order #place-hint,
#result-box,
#orders-caption,
#message.ok,
.modal {
  display: none !important;
}


.positions-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.position-card { background: #fff; border: 1px solid #e8edf4; border-radius: 14px; padding: 14px 15px; }
.position-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; flex-wrap: wrap; }
.position-head strong { font-size: 16px; }
.position-meta { color: var(--muted); font-size: 12px; }
.position-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.position-grid span { display: block; color: var(--muted); font-size: 10px; }
.position-grid strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-editor { margin-top: 4px; }
#stop-result { margin-top: 12px; }
@media (max-width: 760px) {
  .position-grid { grid-template-columns: 1fr 1fr; }
}
