:root {
  color-scheme: dark;
  --bg: #0a0f18;
  --surface: #111827;
  --surface-2: #162033;
  --surface-3: #1c283d;
  --line: #243149;
  --text: #e7edf6;
  --muted: #8a99b0;
  --accent: #38bdf8;
  --long: #34d399;
  --short: #fb7185;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 14px;
  --shadow: 0 16px 40px rgba(0, 0, 0, .25);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
body { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
code { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; color: #c7d2fe; }
h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .01em; }
h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 20px 10px;
  background: rgba(10, 15, 24, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }
.logo {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(52, 211, 153, .25), rgba(251, 113, 133, .25));
  font-size: 18px;
}
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; }
.tabs a {
  padding: 8px 12px; border-radius: 9px; color: var(--muted); white-space: nowrap; font-weight: 550;
}
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a.active { color: var(--text); background: var(--surface-3); }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.ws-dot { width: 9px; height: 9px; border-radius: 50%; background: #475569; }
.ws-dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, .15); }
.state-pill, .mode-badge {
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; border: 1px solid var(--line);
}
.state-pill.running { color: var(--ok); border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .08); }
.state-pill.paused { color: var(--warn); border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .08); }
.state-pill.degraded { color: var(--short); border-color: rgba(251, 113, 133, .4); background: rgba(251, 113, 133, .08); }
.mode-badge.paper { color: #c4b5fd; border-color: rgba(196, 181, 253, .4); background: rgba(196, 181, 253, .08); }
.mode-badge.observer { color: var(--accent); border-color: rgba(56, 189, 248, .4); background: rgba(56, 189, 248, .08); }

/* ---------- layout ---------- */
.shell { max-width: 1440px; margin: 0 auto; padding: 18px 20px calc(40px + env(safe-area-inset-bottom, 0px)); }
.tab { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.pad { margin: -4px 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 18px !important; }
.muted { color: var(--muted); }
.pos { color: var(--long); }
.neg { color: var(--short); }
.warn { margin: 10px 0 0; padding: 8px 10px; border-radius: 9px; background: rgba(251, 191, 36, .08); color: var(--warn); font-size: 12px; }
.link { font-size: 13px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { display: block; font-size: 26px; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 12px; }

/* ---------- quick trigger ---------- */
.quick-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.quick-title { flex: 1 1 220px; min-width: 0; }
.quick-title h2 { margin-bottom: 4px; }
.quick-form label { display: grid; gap: 6px; width: 150px; color: var(--muted); font-size: 12px; }
.quick-form input { color: var(--text); font-size: 16px; font-weight: 650; }
.quick-form.wide .quick-title { flex-basis: 100%; }
.quick-form label.span2 { width: 312px; }
.quick-form label.span2 input { font-size: 14px; font-weight: 500; }
.quick-form label.check.inline { display: inline-flex; width: auto; align-self: center; font-size: 13px; }
.quick-form label.check.inline input { width: auto; }
.patterns { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.patterns .card { background: var(--surface-3); border-radius: 8px; padding: 12px; }
.patterns .card h3 { margin: 0 0 8px; font-size: 13px; }
.patterns table td { padding: 3px 6px; }
.wallet-closed { color: var(--short); font-weight: 650; }
.wallet-partial { color: var(--warn); }
@media (max-width: 640px) { .quick-form label, .quick-form label.span2 { width: 100%; } }
.presets { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 4px; }
.presets .btn.active { border-color: var(--accent); color: var(--accent); }
.quick-trigger > .hint { margin: 10px 0 0; }

/* ---------- exchanges ---------- */
.exchange-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px; }
.exchange { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.exchange header { display: flex; align-items: center; gap: 10px; }
.exchange header div { flex: 1; min-width: 0; }
.exchange header small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; font-weight: 800; background: var(--surface-3); }
.ex-logo.mexc { color: #60a5fa; }
.ex-logo.gate { color: #34d399; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #64748b; }
.state-connected .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, .15); }
.state-reconnecting .dot, .state-degraded .dot, .state-waiting .dot { background: var(--warn); }
.exchange dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0 0; }
.exchange dt { color: var(--muted); font-size: 11px; }
.exchange dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.exchange dd small { color: var(--muted); font-weight: 400; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
th.group { text-align: center; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.clickable { cursor: pointer; }
.clickable:hover td { background: var(--surface-2); }
.sub { display: block; color: var(--muted); font-size: 11px; }
.pair b { display: block; }
.pair small { color: var(--muted); font-size: 11px; }
.actions { text-align: right; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 650; background: var(--surface-3); }
.tag.long { color: var(--long); background: rgba(52, 211, 153, .12); }
.tag.short { color: var(--short); background: rgba(251, 113, 133, .12); }
.tag.ok { color: var(--ok); background: rgba(52, 211, 153, .1); }
.tag.blocked { color: var(--warn); background: rgba(251, 191, 36, .1); }
.tag.cat { color: #c7d2fe; }
.tag.muted-tag { color: var(--muted, #94a3b8); background: rgba(148, 163, 184, .12); }
.tag.sev-warning { color: var(--warn); }
.tag.sev-error, .tag.sev-critical { color: var(--short); }

/* ---------- bars ---------- */
.bars { display: grid; gap: 8px; }
.bar { position: relative; display: flex; justify-content: space-between; padding: 7px 10px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.bar span, .bar b { position: relative; z-index: 1; font-size: 13px; }
.bar i { position: absolute; inset: 0 auto 0 0; background: rgba(251, 191, 36, .14); }

/* ---------- controls ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-3); }
.btn-primary { background: #0e7490; border-color: #0891b2; }
.btn-primary:hover { background: #0891b2; }
.btn-danger { background: rgba(251, 113, 133, .12); border-color: rgba(251, 113, 133, .45); color: #fecdd3; }
.btn-danger:hover { background: rgba(251, 113, 133, .22); }
.btn-short { color: var(--short); border-color: rgba(251, 113, 133, .45); }
.btn-long { color: var(--long); border-color: rgba(52, 211, 153, .45); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-small { padding: 4px 10px; font-size: 12px; }

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
select, input[type=number], input[type=search], input[type=password], input[type=text] {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font: inherit; min-width: 0;
}
input:focus-visible, select:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

.demo { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.demo p { margin: 6px 0 0; }
.demo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- settings ---------- */
.settings { display: grid; gap: 16px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 12px; }
.fields label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.fields input, .fields select { color: var(--text); font-size: 14px; }
.segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 8px; margin-bottom: 14px; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 650; }
.segmented small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.segmented input:checked + span { border-color: var(--accent); background: rgba(56, 189, 248, .08); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.segmented .disabled { opacity: .45; cursor: not-allowed; }
.rules { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 14px; color: var(--muted); font-size: 12px; }
.rules b.short { color: var(--short); }
.rules b.long { color: var(--long); }
.margin-box { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); }
.margin-box span { color: var(--muted); font-size: 12px; }
.margin-box strong { display: block; font-size: 22px; margin: 2px 0; }
.margin-box small { color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); font-weight: 600; }
.chip input:checked + span { border-color: var(--long); color: var(--long); background: rgba(52, 211, 153, .08); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.report {
  margin: 0; padding: 14px; border-radius: 10px; background: var(--surface-2);
  font-family: inherit; font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-x: auto;
}

/* ---------- картка активу (пара бірж) ---------- */
.asset { font-weight: 650; }
.asset-view {
  position: fixed; inset: 0; z-index: 45; padding: 16px;
  display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-items: start;
  overflow-y: auto;
  background: rgba(4, 8, 14, .72); backdrop-filter: blur(4px);
}
.asset-card {
  width: min(1120px, 100%); display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.asset-top { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.asset-top h2 { font-size: 22px; letter-spacing: .02em; }
.asset-top h2 small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: .06em; }
.asset-top > div:nth-child(2) { flex: 1; }
.asset-actions { margin-left: auto; display: flex; gap: 6px; }
.asset-metrics { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: flex-end; }
.asset-metrics div { display: grid; justify-items: end; }
.asset-metrics span { font-size: 11px; color: var(--muted); }
.asset-metrics b { font-size: 17px; font-variant-numeric: tabular-nums; }
.asset-metrics small { font-size: 10px; color: var(--muted); }

.asset-venues { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.venue-card { padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.venue-card.buy { border-color: rgba(52, 211, 153, .45); }
.venue-card.sell { border-color: rgba(251, 113, 133, .45); }
.venue-card header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.venue-card header b { font-size: 15px; }
.venue-card .out { font-size: 13px; }
.role { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; }
.role.buy { background: rgba(52, 211, 153, .16); color: var(--long); }
.role.sell { background: rgba(251, 113, 133, .16); color: var(--short); }
.venue-rows { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px 12px; margin: 0; }
.venue-rows dt { font-size: 11px; color: var(--muted); }
.venue-rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: "JetBrains Mono", Consolas, monospace; }

.asset-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }
.asset-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.asset-tabs button {
  padding: 6px 12px; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-size: 13px;
}
.asset-tabs button:hover { color: var(--text); background: var(--surface-2); }
.asset-tabs button.active { color: var(--text); background: var(--surface-3); border-color: var(--line); }
#asset-live { margin-left: auto; padding: 4px 10px; }
#asset-live.active { color: var(--long); }
.asset-toolbar select { margin-left: 0; }
.asset-summary { margin: 0 0 8px; font-size: 13px; }
.asset-body { min-height: 220px; }
.asset-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.asset-info .wide { grid-column: 1 / -1; }

.chart-wrap { overflow-x: auto; min-width: 0; }
.asset-body, .asset-venues, .venue-card, .asset-info { min-width: 0; }
.chart { width: 100%; min-width: 620px; height: auto; display: block; background: var(--surface-2); border-radius: 10px; }
.chart .series { fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .zero { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .cursor-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .tick { fill: var(--muted); font-size: 10px; stroke: none; }
.chart .pane-title { fill: var(--muted); font-size: 11px; stroke: none; }
.chart .value { font-size: 11px; font-weight: 650; stroke: none; }
.chart .band { stroke: none; opacity: .22; }
.chart .mark { stroke: none; }
.chart .mark-label { font-size: 9px; font-weight: 600; stroke: none; }
.chart { cursor: crosshair; touch-action: none; }
.chart path.s-in, .chart .legend-line.s-in { stroke: var(--long); }
.chart path.s-out { stroke: var(--short); }
.chart path.v-a { stroke: var(--accent); }
.chart path.v-b { stroke: #c084fc; }
.chart text.s-in { fill: var(--long); }
.chart text.s-out { fill: var(--short); }
.chart text.v-a { fill: var(--accent); }
.chart text.v-b { fill: #c084fc; }
.chart .band.s-in, .chart circle.s-in, .chart text.mark-label.s-in { fill: var(--long); }
.chart .band.s-out, .chart circle.s-out, .chart text.mark-label.s-out { fill: var(--short); }
.chart .band.v-a, .chart circle.v-a, .chart text.mark-label.v-a { fill: var(--accent); }
.chart .band.v-b, .chart circle.v-b, .chart text.mark-label.v-b { fill: #c084fc; }
.chart-hint { margin: 6px 0 0; font-size: 11px; color: var(--muted); }

.chart-readout { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-bottom: 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-readout .readout-time { color: var(--muted); }
.chart-readout .readout { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.chart-readout b { color: var(--text); }
.chart-readout b.s-in, .legend.s-in { color: var(--long); }
.chart-readout b.s-out { color: var(--short); }
.chart-readout b.v-a { color: var(--accent); }
.chart-readout b.v-b { color: #c084fc; }
.legend { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; background: var(--muted); }
.legend.s-in { background: var(--long); }
.legend.s-out { background: var(--short); }
.legend.v-a { background: var(--accent); }
.legend.v-b { background: #c084fc; }

@media (max-width: 860px) {
  .asset-venues, .asset-info { grid-template-columns: minmax(0, 1fr); }
  .asset-metrics { justify-content: flex-start; }
  .asset-metrics div { justify-items: start; }
}

.live-bar {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 44;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 14px; padding: 8px 12px 8px 16px;
  border-radius: 999px; background: var(--surface-3); border: 1px solid var(--short);
  box-shadow: var(--shadow); font-size: 13px; font-variant-numeric: tabular-nums;
}
.live-bar.dry { border-color: var(--warn); }
.live-bar b { color: var(--short); }
.btn-danger { background: var(--short); color: #1a0a0f; border-color: var(--short); font-weight: 650; }

/* ---------- drawer & modal ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(560px, 100%);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { display: flex; align-items: center; gap: 8px; }
.drawer-body { overflow-y: auto; padding: 16px; display: grid; gap: 18px; }
.details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); font-size: 11px; }
.details dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; word-break: break-word; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .6); }
.modal-card { display: grid; gap: 12px; width: min(380px, 100%); padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.modal-card p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(251, 113, 133, .5); color: #fecdd3; }

@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tabs { order: 3; flex-basis: 100%; }
}
@media (max-width: 520px) {
  .topbar { padding-left: 16px; padding-right: 16px; }
  .shell { padding-left: 16px; padding-right: 16px; }
  .exchange dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .details { grid-template-columns: 1fr; }
  .kpi strong { font-size: 22px; }
}

/* окрема сторінка міжбіржі (/cross): лише ця вкладка, без решти термінала */
body.solo #tabs, body.solo #pause-btn, body.solo .solo-link { display: none; }
.mute-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.modal-card input { width: 100%; min-width: 0; }
.chart polyline.s-in { stroke: var(--long); }
.chart polyline.s-out { stroke: var(--short); }
.chart polyline.v-a { stroke: var(--accent); }
.chart polyline.v-b { stroke: #c084fc; }
