@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #030712;
  --bg2: #0a0f1e;
  --surface: rgba(10, 16, 32, 0.88);
  --surface2: rgba(14, 22, 42, 0.95);
  --surface3: rgba(20, 28, 50, 0.9);
  --border: rgba(212, 175, 55, 0.12);
  --border2: rgba(0, 229, 255, 0.14);
  --gold: #d4af37;
  --gold2: #f0d060;
  --gold-dim: rgba(212, 175, 55, 0.1);
  --cyan: #00e5ff;
  --cyan-dim: rgba(0, 229, 255, 0.08);
  --purple: #8b5cf6;
  --green: #22c55e;
  --red: #ef4444;
  --magenta: #e94560;
  --text: #eef2fb;
  --muted: #7a8ba8;
  --nav-h: 62px;
  --header-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --radius: 16px;
  --rsm: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --ease: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: 'Kanit', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 50% at 80% -10%, rgba(212, 175, 55, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 10% 100%, rgba(0, 229, 255, 0.06), transparent),
    linear-gradient(rgba(212, 175, 55, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 175, 55, 0.02) 1px, transparent 1px);
  background-size: auto, auto, 48px 48px, 48px 48px;
}

#app { height: 100%; display: flex; flex-direction: column; position: relative; z-index: 1; }

#main-app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.screen-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.screen {
  display: none;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(var(--nav-h) + var(--safe-b) + 16px);
  scroll-behavior: smooth;
}
.screen.active { display: block; }

/* ── Header ── */
.top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: rgba(3, 7, 18, 0.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand img, .brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.15), 0 0 12px rgba(212, 175, 55, 0.12);
}
.header-meta { display: flex; align-items: center; gap: 6px; }
.chip {
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: var(--cyan-dim);
  color: var(--cyan);
  font-weight: 500;
}
.chip.gold {
  border-color: var(--border);
  background: var(--gold-dim);
  color: var(--gold2);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card.glass {
  background: linear-gradient(145deg, rgba(14, 22, 42, 0.95), rgba(10, 16, 32, 0.85));
}
.compact-card { padding: 12px 14px; }

.card-title, .section-title {
  font-size: 11px;
  color: var(--gold2);
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title::before {
  content: '';
  width: 3px;
  height: 12px;
  background: linear-gradient(180deg, var(--gold), var(--cyan));
  border-radius: 2px;
}

/* ── Stats ── */
.hero-profit {
  text-align: center;
  padding: 18px 14px;
  margin-bottom: 10px;
  background: linear-gradient(145deg, rgba(14, 22, 42, 0.98), rgba(20, 28, 50, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-profit .stat-val { font-size: 36px; font-weight: 700; line-height: 1.1; }
.hero-profit .stat-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; letter-spacing: 0.3px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.stat-box {
  background: var(--surface2);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--rsm);
  padding: 10px 6px;
  text-align: center;
}
.stat-val { font-size: 17px; font-weight: 700; }
.stat-lbl { font-size: 9px; color: var(--muted); margin-top: 2px; letter-spacing: 0.2px; }
.profit-pos { color: var(--green); }
.profit-neg { color: var(--red); }

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 500;
  background: var(--surface3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--muted);
}
.pill.ok { border-color: rgba(34, 197, 94, 0.25); color: var(--green); background: rgba(34, 197, 94, 0.08); }
.pill.warn { border-color: rgba(239, 68, 68, 0.25); color: var(--red); background: rgba(239, 68, 68, 0.08); }
.pill.info { border-color: var(--border2); color: var(--cyan); background: var(--cyan-dim); }

.balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.balance-item {
  background: var(--surface2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--rsm);
  padding: 10px;
  text-align: center;
  transition: border-color var(--ease), background var(--ease);
}
.balance-item.active {
  border-color: var(--cyan);
  background: var(--cyan-dim);
}
.balance-item.active.real-active {
  border-color: var(--gold);
  background: var(--gold-dim);
}
.balance-lbl {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
  letter-spacing: 0.2px;
}
.balance-val {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.balance-item.active .balance-val { color: var(--cyan); }
.balance-item.active.real-active .balance-val { color: var(--gold2); }
.settings-balances { margin-top: 10px; }

.selectable-balances .balance-item {
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: transform var(--ease), border-color var(--ease), background var(--ease);
}
.selectable-balances .balance-item:not(.active):active {
  border-color: rgba(255, 255, 255, 0.2);
  background: var(--surface3);
}
.selectable-balances .balance-item:active { transform: scale(0.97); }
.balance-hint { text-align: center; margin-top: 8px; font-size: 10px; }

.account-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.account-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  border-radius: var(--rsm);
  border: 1px solid var(--border2);
  background: var(--surface2);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: all var(--ease);
}
.account-tab:not(.active):hover,
.account-tab:not(.active):active {
  border-color: rgba(255, 255, 255, 0.2);
  background: var(--surface3);
}
.account-tab-title { font-size: 14px; font-weight: 700; }
.account-tab-sub { font-size: 10px; opacity: 0.85; }
.account-tab.active {
  border-color: var(--cyan);
  background: var(--cyan-dim);
  color: var(--cyan);
}
.account-tab.active[data-account="real"] {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold2);
}

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: var(--rsm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: transform var(--ease), opacity var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-sm { padding: 10px 14px; font-size: 14px; margin-top: 8px; }
.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #00e5ff 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 229, 255, 0.2);
}
.btn-gold {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold2) 100%);
  color: #1a1200;
  box-shadow: 0 4px 20px rgba(212, 175, 55, 0.25);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--muted);
}
.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--red);
}

/* ── Form ── */
.field { margin-bottom: 12px; }
.field.half { flex: 1; min-width: 0; }
.field-row { display: flex; gap: 10px; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 500;
}
.field input, .field select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color var(--ease);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--cyan);
}

/* ── Broker tabs ── */
.broker-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.broker-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: var(--rsm);
  border: 1px solid var(--border2);
  background: var(--surface2);
  cursor: pointer;
  transition: all var(--ease);
  font-family: inherit;
  color: var(--muted);
}
.broker-tab img { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; }
.broker-tab span { font-size: 12px; font-weight: 600; }
.broker-tab.active {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold2);
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.12);
}
.broker-tab.locked { opacity: 0.45; pointer-events: none; }
.broker-tab .lock-hint { font-size: 9px; color: var(--muted); }

/* ── Assets ── */
.asset-selected {
  text-align: center;
  padding: 10px;
  margin-bottom: 10px;
  background: var(--cyan-dim);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--cyan);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
}
.asset-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 8px;
  padding: 6px;
  border-radius: var(--rsm);
  border: 1px solid var(--border2);
  background: #111827;
}
.asset-results.hidden { display: none; }
.asset-result-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
}
.asset-result-item:active,
.asset-result-item:hover {
  background: var(--cyan-dim);
  color: var(--cyan);
}
.asset-result-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 16px 8px;
}

/* ── Login ── */
.login-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
}
.login-logo { text-align: center; margin-bottom: 22px; }
.login-logo .logo-hero {
  display: inline-block;
  width: min(220px, 72vw);
  margin-bottom: 12px;
  border-radius: 28px;
  overflow: hidden;
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 48px rgba(0, 229, 255, 0.12),
    0 0 32px rgba(212, 175, 55, 0.1);
  border: 1px solid rgba(0, 229, 255, 0.15);
}
.login-logo .logo-hero img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 28px;
}
.login-sub {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.3px;
}
.login-card { margin-top: 4px; }

.input-password {
  position: relative;
  display: flex;
  align-items: center;
}
.input-password input {
  width: 100%;
  padding: 11px 44px 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
.input-password input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.12);
}
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--muted);
  font-size: 18px;
  z-index: 3;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  transition: color var(--ease), background var(--ease);
}
.pw-toggle:active { background: rgba(0, 229, 255, 0.08); }
.pw-toggle.active { color: var(--cyan); }
.pw-icon { line-height: 1; }

.remember-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
}
.remember-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.remember-box {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ease);
}
.remember-box::after {
  content: '✓';
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan);
  opacity: 0;
  transform: scale(0.6);
  transition: all var(--ease);
}
.remember-row input:checked + .remember-box {
  border-color: var(--cyan);
  background: var(--cyan-dim);
}
.remember-row input:checked + .remember-box::after {
  opacity: 1;
  transform: scale(1);
}

/* ── Bottom nav ── */
.bottom-nav {
  flex-shrink: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(3, 7, 18, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  border: none;
  background: none;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--ease);
  position: relative;
}
.nav-item.active { color: var(--gold2); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), var(--cyan));
  border-radius: 0 0 2px 2px;
}
.nav-icon { font-size: 20px; line-height: 1; }

/* ── Trade Log (PC style) ── */
.trade-log-card { padding-bottom: 12px; }
.trade-log-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--rsm);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: #111827;
  margin-bottom: 10px;
}
.trade-log-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 11px;
}
.trade-log-table thead th {
  background: #0f1520;
  color: #8b9cb3;
  font-weight: 600;
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid #1e2d42;
  white-space: nowrap;
}
.trade-log-table tbody td {
  padding: 8px 6px;
  border-bottom: 1px solid #1e2d42;
  color: var(--text);
  vertical-align: middle;
}
.trade-log-table tbody tr:last-child td { border-bottom: none; }
.trade-log-empty td {
  text-align: center;
  color: var(--muted);
  padding: 24px 8px !important;
}
.dir-call { color: #00b894; font-weight: 600; }
.dir-put { color: #e94560; font-weight: 600; }
.result-win { color: #00b894; font-weight: 600; }
.result-loss { color: #e94560; font-weight: 600; }
.result-pending { color: #888888; font-weight: 500; }
.result-even { color: #888888; font-weight: 600; }

.bot-activity {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--rsm);
  background: rgba(0, 229, 255, 0.06);
  border: 1px solid rgba(0, 229, 255, 0.12);
  color: var(--cyan);
  font-size: 11px;
  line-height: 1.4;
}
.bot-activity.error {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}
.bot-activity.active {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

/* legacy rows (removed) */
.trade-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 12px;
}
.trade-row:last-child { border-bottom: none; }

/* ── Notice / Update banner ── */
.notice {
  background: var(--gold-dim);
  border: 1px solid var(--border);
  border-radius: var(--rsm);
  padding: 10px 12px;
  font-size: 11px;
  color: var(--gold2);
  line-height: 1.5;
  margin-bottom: 10px;
}
.notice.compact { padding: 8px 12px; font-size: 10px; }
.notice.cyan {
  background: var(--cyan-dim);
  border-color: var(--border2);
  color: var(--cyan);
}

.update-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--rsm);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(0, 229, 255, 0.1));
  border: 1px solid var(--border2);
}
.update-banner.show { display: flex; }
.update-banner p { font-size: 11px; line-height: 1.4; flex: 1; }
.update-banner strong { color: var(--cyan); }
.update-banner .btn { width: auto; padding: 8px 14px; font-size: 12px; flex-shrink: 0; }

/* ── Toggle ── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle-row.tight { padding: 0; }
.toggle-switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 28px;
  cursor: pointer;
  transition: background var(--ease);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 2px;
  top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform var(--ease), background var(--ease);
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--cyan-dim);
  border-color: var(--cyan);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--cyan);
}

/* ── Settings groups ── */
.settings-group { margin-bottom: 4px; }
.settings-group .card { margin-bottom: 10px; }

.version-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 11px;
  color: var(--muted);
}
.version-bar span:last-child { color: var(--cyan); font-weight: 500; }

/* ── Toast ── */
.toast {
  position: fixed;
  top: calc(12px + var(--safe-t));
  left: 14px;
  right: 14px;
  padding: 12px 16px;
  border-radius: var(--rsm);
  background: var(--surface2);
  border: 1px solid var(--border2);
  z-index: 200;
  font-size: 13px;
  transform: translateY(-120%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
}
.toast.show { transform: translateY(0); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; font-size: 13px; }
.hint { font-size: 11px; color: var(--muted); line-height: 1.5; }
.hidden { display: none !important; }
