/* Algo Trading — ธีมหมึกน้ำเงิน + ทอง (dark) / กระดาษ + ทองเข้ม (light) */
:root {
  --bg: #0F1B2D;
  --surface: #16253B;
  --surface-2: #1D2F49;
  --line: #2A3F5E;
  --text: #E8EDF4;
  --muted: #93A3BA;
  --gold: #D4AF37;
  --gold-ink: #1A1300;
  --gold-soft: rgba(212, 175, 55, .14);
  --up: #34C28A;
  --down: #F0676A;
  --warn: #E9B44C;
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-2: #EEF1F5;
  --line: #D9DFE7;
  --text: #13213A;
  --muted: #5D6B80;
  --gold: #A67C00;
  --gold-ink: #FFFFFF;
  --gold-soft: rgba(166, 124, 0, .10);
  --up: #13875B;
  --down: #C9363A;
  --warn: #9A6A00;
  --shadow: 0 6px 22px rgba(19, 33, 58, .10);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Thai", "Leelawadee UI", "Tahoma", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--gold); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--gold) 0 50%, transparent 50%), var(--surface-2);
  border: 1.5px solid var(--gold);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { color: var(--text); }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ws-dot.on { background: var(--up); }

/* ---------- layout ---------- */
.app { max-width: 720px; margin: 0 auto; padding: 18px 16px 24px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
h1 { font-size: 26px; line-height: 1.25; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 26px 0 10px; font-weight: 600; }
h3 { font-size: 16px; margin: 0 0 6px; font-weight: 600; }
.lead { color: var(--muted); margin: 4px 0 0; max-width: 60ch; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); text-decoration: none; font-size: 15px; margin-bottom: 8px; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; }
.panel + .panel { margin-top: 14px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.list-item { display: block; padding: 16px 18px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.list-item:first-child { border-top: 0; }
a.list-item:hover { background: var(--surface-2); }

/* ---------- account row ---------- */
.acc-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.acc-login { font-size: 20px; font-weight: 700; }
.acc-sub { color: var(--muted); font-size: 14px; }
.acc-money { display: flex; gap: 22px; margin-top: 10px; }
.acc-money div span { display: block; color: var(--muted); font-size: 13px; }
.acc-money div strong { font-size: 17px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.run { color: var(--up); background: color-mix(in srgb, var(--up) 14%, transparent); }
.badge.wait { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.err { color: var(--down); background: color-mix(in srgb, var(--down) 14%, transparent); }
.badge.gold { color: var(--gold); background: var(--gold-soft); }

/* ---------- progress (จุดเด่นของระบบ) ---------- */
.progress-card { border: 1px solid var(--gold); background: var(--gold-soft); border-radius: var(--radius-lg); padding: 18px; }
.progress-pct { font-size: 40px; font-weight: 700; line-height: 1; color: var(--gold); }
.rail { position: relative; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 14px 0 10px; }
.rail > i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--gold); border-radius: 999px; transition: width .6s ease; }
.rail.mini { height: 6px; margin: 10px 0 4px; }
.steps { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.steps li { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.steps li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.steps li.done { color: var(--text); }
.steps li.done::before { background: var(--gold); border-color: var(--gold); }
.steps li.now::before { border-color: var(--gold); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px var(--gold-soft); } }
@media (prefers-reduced-motion: reduce) { .rail > i { transition: none; } .steps li.now::before { animation: none; } }

/* ---------- equity hero ---------- */
.hero-money { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.hero-money .big { grid-column: 1 / -1; }
.hero-money .big strong { font-size: 34px; line-height: 1.1; font-weight: 700; }
.hero-money span { display: block; color: var(--muted); font-size: 13px; }
.hero-money strong { font-size: 18px; }
.up { color: var(--up); } .down { color: var(--down); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 45%, var(--line)); background: color-mix(in srgb, var(--down) 8%, transparent); }
.btn.good { color: var(--up); border-color: color-mix(in srgb, var(--up) 45%, var(--line)); background: color-mix(in srgb, var(--up) 8%, transparent); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-grid .wide { grid-column: 1 / -1; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
textarea { min-height: 110px; font-family: ui-monospace, Consolas, monospace; font-size: 14px; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); margin-bottom: 14px; }
.switch input { width: 22px; height: 22px; accent-color: var(--gold); }
.form-error { color: var(--down); font-size: 14px; min-height: 1em; margin: 4px 0 10px; }

/* ---------- callouts ---------- */
.note { border-left: 3px solid var(--gold); background: var(--gold-soft); padding: 12px 14px; border-radius: 0 var(--radius) var(--radius) 0; font-size: 15px; }
.note.err { border-color: var(--down); background: color-mix(in srgb, var(--down) 10%, transparent); }
.note.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 20px 0 16px; scrollbar-width: none; }
.tabs button, .tabs a { background: none; border: 0; padding: 10px 12px; color: var(--muted); cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; font-weight: 500; text-decoration: none; }
.tabs .on { color: var(--text); border-bottom-color: var(--gold); }

/* ---------- tables (key/value) ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }

/* ---------- order card ---------- */
.order { padding: 14px 16px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.order:first-child { border-top: 0; }
.order .side { font-weight: 700; }
.order .side.buy { color: var(--up); } .order .side.sell { color: var(--down); }

/* ---------- chart ---------- */
.chart { width: 100%; height: 170px; display: block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 14px; }
.stats span { display: block; color: var(--muted); font-size: 13px; }
.stats strong { font-size: 16px; }

/* ---------- EA card ---------- */
.ea { display: grid; gap: 6px; }
.ea-name { font-size: 18px; font-weight: 700; }
.ea-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; font-size: 14px; }
.ea-meta dt { color: var(--muted); } .ea-meta dd { margin: 0; }
.ea.selected { outline: 2px solid var(--gold); }

/* ---------- auth ---------- */
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth h1 { font-size: 30px; }
.auth .panel { margin-top: 22px; }

/* ---------- bottom nav ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.bottom-nav a { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 6px 0; color: var(--muted); text-decoration: none; font-size: 12px; }
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a.on { color: var(--gold); }

/* ---------- toast / modal ---------- */
.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; transition: .25s; max-width: 90vw; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--down); color: #fff; }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(5, 10, 20, .6); display: grid; align-items: end; justify-items: center; padding: 16px; }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; padding: 20px; box-shadow: var(--shadow); }
@media (min-width: 640px) { .modal { align-items: center; } }

.empty { text-align: center; padding: 34px 18px; color: var(--muted); }
.empty .btn { margin-top: 12px; }
.loading { color: var(--muted); padding: 30px 0; text-align: center; }
.token-box { word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 12px; border-radius: var(--radius); border: 1px dashed var(--gold); }

@media (min-width: 900px) {
  .app { max-width: 880px; }
  .acc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .acc-grid .panel + .panel { margin-top: 0; }
}
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; word-break: break-all; }

/* ---------- avatar / topbar ---------- */
.me-btn { display: grid; place-items: center; border-radius: 50%; line-height: 0; }
.avatar { display: inline-grid; place-items: center; border-radius: 50%; object-fit: cover; background: var(--gold-soft); color: var(--gold); font-weight: 700; border: 1px solid var(--line); flex: none; }

/* ---------- auth extras ---------- */
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.g-btn { display: flex; justify-content: center; min-height: 44px; }
.code-input { text-align: center; font-size: 30px; letter-spacing: .4em; font-weight: 700; padding-left: calc(14px + .4em); min-height: 60px; }

/* ---------- password eye ---------- */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 48px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; display: grid; place-items: center; background: none; border: 0; color: var(--muted); cursor: pointer; border-radius: 10px; }
.pw-eye:hover { color: var(--text); }

/* ---------- picker (เลือกโบรก/เซิร์ฟเวอร์) ---------- */
.picker { width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; cursor: pointer; }
.picker:hover:not(:disabled) { border-color: var(--muted); }
.picker:disabled { opacity: .55; cursor: not-allowed; }
.picker .ph { color: var(--muted); }
.picker svg { flex: none; color: var(--muted); }
.pk-search { margin-bottom: 10px; }
.pk-list { display: grid; gap: 4px; max-height: 50vh; overflow: auto; }
.pk-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; width: 100%; padding: 12px 14px; border-radius: var(--radius); border: 1px solid transparent; background: var(--surface-2); cursor: pointer; }
.pk-item:hover { border-color: var(--line); }
.pk-item.on { border-color: var(--gold); background: var(--gold-soft); }
.pk-item small { color: var(--muted); }

/* ---------- toggle switch (เปิด/ซ่อน) ---------- */
.tg { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.tg input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; z-index: 1; }
.tg i { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); transition: background .2s; }
.tg i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.tg input:checked + i { background: var(--gold-soft); border-color: var(--gold); }
.tg input:checked + i::after { transform: translateX(20px); background: var(--gold); }
.tg input:focus-visible + i { outline: 2px solid var(--gold); outline-offset: 2px; }
.dim { opacity: .6; }

/* ---------- first setup / currency rows ---------- */
.code-input-sm { text-transform: uppercase; letter-spacing: .15em; font-weight: 700; text-align: center; }
.cr-rows { display: grid; gap: 8px; }
.cr-row { display: grid; grid-template-columns: 70px 1fr; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); position: relative; }
.cr-row input, .cr-row select { min-height: 40px; background: var(--surface); }
.cr-row input[name=sym], .cr-row input[name=mb] { grid-column: 1 / -1; }
.cr-row .icon-btn { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border: 0; font-size: 20px; line-height: 1; }
.cr-row input[name=cur] { text-transform: uppercase; }
.cr-row select { grid-column: auto; }
