:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.logo { width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 14px solid var(--green); }
.server-status { color: var(--muted); font-size: 12px; }
.server-status.offline { color: var(--red); }

.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 49px); }
.sidebar { border-right: 1px solid var(--border); padding: 16px; background: var(--panel); }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 16px; }

.account-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.account-item {
  display: block; width: 100%; text-align: left; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; font: inherit;
}
.account-item:hover { border-color: #3a4150; }
.account-item.selected { border-color: var(--blue); }
.account-item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.account-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.account-item .nums { display: flex; justify-content: space-between; margin-top: 6px; font-size: 13px; }

.chip { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.chip.quick { border-color: #7c3aed; color: #c4b5fd; }
.chip.balanced { border-color: #0e7490; color: #67e8f9; }
.chip.gold { border-color: #b45309; color: #fcd34d; }
.chip.scalp { border-color: #0e7490; color: #67e8f9; }
.chip.grid { border-color: #be123c; color: #fda4af; }

.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state-RUNNING .dot { background: var(--green); }
.state-PAUSED .dot, .state-STARTING .dot { background: var(--amber); }
.state-ERROR .dot, .state-NOT_RESPONDING .dot, .state-SAFETY_HALT .dot { background: var(--red); }

.main { padding: 20px 24px 40px; max-width: 1280px; min-width: 0; }
.empty { max-width: 520px; margin: 60px auto; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }

.account-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.risk-field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.risk-field input { width: 64px; }

.btn {
  font: inherit; font-size: 13px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
.btn:hover:not(:disabled) { border-color: #4a5264; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-danger { border-color: #7f1d1d; color: #fca5a5; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { font: inherit; font-size: 13px; padding: 7px 14px; background: transparent; color: var(--muted); border: 0; cursor: pointer; }
.segmented button[aria-checked="true"] { background: var(--panel-2); color: var(--text); font-weight: 600; }

input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 9px;
}
input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.alert { padding: 10px 12px; border-radius: 8px; border: 1px solid; font-size: 13px; }
.alert.error { border-color: #7f1d1d; background: #2a1215; color: #fecaca; }
.alert.warn { border-color: #78350f; background: #2a1d0c; color: #fde68a; }
.alert.info { border-color: #1e3a8a; background: #111a2e; color: #bfdbfe; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 18px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 10px; }
.count { color: var(--muted); font-size: 12px; }

.tabs { display: inline-flex; gap: 4px; }
.tabs button { font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 6px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { border-color: var(--border); background: var(--panel-2); color: var(--text); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.empty-row { color: var(--muted); padding: 10px 0; }

.side-buy { color: var(--green); font-weight: 600; }
.side-sell { color: var(--red); font-weight: 600; }

.perf { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.perf-col { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.perf-col h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 500; }
.perf-row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }

.pair-status { font-size: 12px; }
.logs { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; max-height: 320px; overflow-y: auto; }
.log-line { padding: 2px 0; border-bottom: 1px solid #20242d; white-space: pre-wrap; }
.log-ERROR { color: #fca5a5; }
.log-WARNING { color: #fde68a; }
.log-SUCCESS { color: #86efac; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  padding: 0; width: min(560px, 94vw); max-height: 92vh; overflow-y: auto; margin: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.radio { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); }
dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-pick { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.mode-pick legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.advanced label { margin-top: 8px; }
.form-error { color: #fca5a5; margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Settings Dialog Styling */
.settings-dialog { width: min(840px, 95vw); max-height: 92vh; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.dialog-header h2 { font-size: 18px; margin: 0 0 4px; }
.close-btn { font-size: 22px; line-height: 1; padding: 2px 8px; cursor: pointer; }
.settings-tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin: 4px 0 10px; }
.tab-btn {
  font: inherit; font-size: 13px; font-weight: 500; padding: 6px 14px; border-radius: 6px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--panel-2); }
.tab-btn.active { color: #fff; background: var(--panel-2); border-color: var(--blue); font-weight: 600; }
.settings-container { display: flex; flex-direction: column; gap: 10px; max-height: 56vh; overflow-y: auto; padding-right: 4px; }
.setting-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; transition: border-color 0.15s;
}
.setting-card:hover { border-color: #3b4252; }
.setting-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-title { font-weight: 600; font-size: 13px; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.badge-rec {
  font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.35); color: #86efac;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.setting-body { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.setting-help { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 0; flex: 1; min-width: 240px; }
.setting-input-wrap { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.setting-input-wrap input[type="number"] { width: 90px; text-align: right; }
.setting-input-wrap input[type="text"] { min-width: 140px; }
.setting-input-wrap .unit { color: var(--muted); font-size: 12px; font-weight: 500; }
.setting-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-size: 13px; }
.symbols-selector { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; width: 100%; }
.symbol-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 12px; font-weight: 500;
  user-select: none; transition: all 0.15s;
}
.symbol-pill:hover { border-color: #4a5264; }
.symbol-pill.selected { border-color: var(--blue); background: rgba(59, 130, 246, 0.15); color: #93c5fd; }
.spacer { flex: 1; }
.settings-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.toast.error { border-color: #7f1d1d; color: #fecaca; }

/* Real-Time Chart Styling */
.chart-card { padding: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.chart-title-area { display: flex; flex-direction: column; gap: 3px; }
.chart-title-row { display: flex; align-items: center; gap: 10px; }
.chart-badge-trade {
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 999px;
  background: rgba(34, 197, 94, 0.15); border: 1px solid rgba(34, 197, 94, 0.4); color: #86efac;
  text-transform: uppercase; animation: pulse-badge 2s infinite ease-in-out;
}
@keyframes pulse-badge {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(0.97); }
}
.chart-controls-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.chart-legend { display: inline-flex; align-items: center; gap: 12px; font-size: 11px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { display: inline-block; width: 14px; height: 3px; border-radius: 1px; }
.line-entry { background: #38bdf8; }
.line-sl { background: #ef4444; }
.line-tp { background: #22c55e; }

.chart-container {
  width: 100%; height: 380px; background: #11141a; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; position: relative;
}
.chart-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding: 0 4px; gap: 12px; flex-wrap: wrap; }
.chart-pos-detail { font-weight: 600; color: #38bdf8; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- product: sign-in, billing, admin */
textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 9px; width: 100%; resize: vertical;
}
textarea:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
h4 { margin: 6px 0 0; font-size: 13px; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > * { margin: 0; }
.pre { white-space: pre-wrap; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.form-info { color: #86efac; margin: 0; }

.center-view { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px 16px; }
.auth-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.auth-card.wide { width: min(720px, 100%); }
.auth-card p { margin: 0; }
.brand.big { font-size: 20px; }
.brand.big .logo { border-left-width: 10px; border-right-width: 10px; border-bottom-width: 18px; }
.auth-tabs { width: 100%; }
.auth-tabs button { flex: 1; font-size: 13px; padding: 7px 10px; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form label, .auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-card label.radio, .auth-form label.radio { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); }
.link-btn { background: none; border: 0; padding: 0; color: #93c5fd; cursor: pointer; font: inherit; font-size: 13px; text-align: left; }
.link-btn:hover { text-decoration: underline; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.btn-google { background: #fff; color: #1f2937; border-color: #fff; font-weight: 600; }
.btn-google:hover:not(:disabled) { border-color: #d1d5db; }
.auth-foot { display: flex; justify-content: center; gap: 16px; margin-top: 4px; }
.auth-foot .link-btn { font-size: 12px; color: var(--muted); }
.consent {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 50; max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: space-between;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); font-size: 13px;
}
.consent span { flex: 1; min-width: 220px; }
.consent-actions { display: flex; gap: 8px; }
.terms-box { max-height: 46vh; overflow-y: auto; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 4px 14px; font-size: 13px; }
.terms-box p { margin: 10px 0; }

.topnav { display: flex; gap: 4px; }
.topnav a { color: var(--muted); text-decoration: none; padding: 5px 12px; border-radius: 6px; font-size: 13px; }
.topnav a.active { color: var(--text); background: var(--panel-2); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.banner { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 16px; font-size: 13px; border-bottom: 1px solid; flex-wrap: wrap; }
.banner.warn { border-color: #78350f; background: #2a1d0c; color: #fde68a; }
.banner.info { border-color: #1e3a8a; background: #111a2e; color: #bfdbfe; }

.plan { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.plan-price { font-size: 16px; }
.plan-price b { font-size: 24px; }

dialog .dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
dialog.wide-dialog { width: min(980px, 96vw); }

.admin { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.admin .kpi .small { margin-top: 4px; }
.admin input[type="search"] { min-width: 260px; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover td, table.clickable tbody tr:focus-visible td { background: var(--panel-2); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; display: inline-block; }
.badge.ok { border-color: #166534; color: #86efac; background: rgba(34, 197, 94, 0.1); }
.badge.free { border-color: #1e40af; color: #93c5fd; background: rgba(59, 130, 246, 0.1); }
.badge.bad { border-color: #7f1d1d; color: #fca5a5; background: rgba(239, 68, 68, 0.1); }
.badge.none { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.form-grid label, .card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.card label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.card label.inline input { width: 70px; }
.card .controls { margin: 4px 0; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar-right { flex-wrap: wrap; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .perf { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-dialog { width: 96vw; }
  .setting-body { flex-direction: column; align-items: flex-start; gap: 8px; }
  .setting-input-wrap { width: 100%; justify-content: flex-end; }
}
