:root {
  --bg-0: #0b0f17;
  --bg-1: #111827;
  --bg-2: #1a2233;
  --line: #233045;
  --text: #e6edf7;
  --muted: #8a97ad;
  --accent: #4cc9f0;
  --accent-2: #7c3aed;
  --green: #2ecc71;
  --red: #ef4444;
  --yellow: #f5a524;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1100px 600px at 20% -10%, rgba(76, 201, 240, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(124, 58, 237, 0.10), transparent 60%),
    var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overflow-x: hidden;
}

body {
  width: 100%;
  max-width: 100vw;
}

/* iOS Safari при focus на input <16px зумит viewport — запрещаем */
input, select, textarea, button {
  font-size: 16px;
  font-family: inherit;
}

.app {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom) 14px;
  overflow-x: hidden;
}

@media (max-width: 480px) {
  .app { padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom) 10px; }
}

/* ─── topbar ───────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 8px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  font-size: 18px;
}
.logo-mark {
  width: 22px;
  height: 22px;
  background: conic-gradient(from 220deg, var(--accent), var(--accent-2), var(--accent));
  border-radius: 6px;
  box-shadow: 0 0 12px rgba(76, 201, 240, 0.45);
}
.env-badge {
  font-size: 11px;
  letter-spacing: 1px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  text-transform: uppercase;
  color: var(--muted);
}
.env-badge.demo { color: var(--yellow); border-color: rgba(245, 165, 36, 0.4); }
.env-badge.live { color: var(--red);    border-color: rgba(239, 68, 68, 0.5);  }

/* ─── content ──────────────────────────────────────────── */
.content {
  display: grid;
  gap: 14px;
  padding-top: 12px;
  min-width: 0;
  max-width: 100%;
}

.card {
  background: linear-gradient(180deg, var(--bg-1), rgba(17, 24, 39, 0.7));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.card-title {
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.hero { display: grid; gap: 14px; }
.hero-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-width: 0;
}
.muted { color: var(--muted); font-size: 12px; }
.big   {
  font-size: clamp(20px, 6.5vw, 28px);
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-top: 2px;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.mid   { font-size: 18px; font-weight: 600; margin-top: 2px; }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.kv:last-child { border-bottom: none; }

.mono { font-family: "SF Mono", "Cascadia Mono", Menlo, monospace; }

.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.pill.ok    { color: var(--green); border-color: rgba(46, 204, 113, 0.4); }
.pill.fail  { color: var(--red);   border-color: rgba(239, 68, 68, 0.5);  }

.positions { display: grid; gap: 10px; }
.empty { padding: 12px 0; }

.pos {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.pos .sym { font-weight: 700; }
.pos .side-LONG  { color: var(--green); }
.pos .side-SHORT { color: var(--red); }

.up   { color: var(--green); }
.down { color: var(--red); }

.small { font-size: 12px; }

.bt-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 14px;
  padding: 10px 0 6px;
}
@media (min-width: 520px) {
  .bt-grid { grid-template-columns: repeat(4, 1fr); }
}

.chart-wrap {
  margin-top: 10px;
  padding: 8px 6px 4px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.chart-wrap svg {
  width: 100%;
  height: 160px;
  display: block;
}
.chart-legend { padding: 6px 4px 0; }

.pill.pass { color: var(--green); border-color: rgba(46, 204, 113, 0.4); }
.pill.weak { color: var(--yellow); border-color: rgba(245, 165, 36, 0.5); }
.pill.fail { color: var(--red); border-color: rgba(239, 68, 68, 0.5); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 12px; }
.btn {
  flex: 1 1 140px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, border-color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, rgba(76, 201, 240, 0.22), rgba(124, 58, 237, 0.28));
  border-color: rgba(76, 201, 240, 0.55);
}
.btn.ghost { background: transparent; }
.btn.warn {
  border-color: rgba(245, 165, 36, 0.4);
  color: #f3b969;
}
.btn.warn:hover:not(:disabled) { border-color: var(--red); color: var(--red); }
.btn.big {
  font-size: 17px;
  padding: 14px 18px;
  min-height: 52px;
}
.btn.busy { opacity: 0.6; cursor: progress; }

/* ─── Статус-карточка ─────────────────────────────────────── */
.status-card {
  background: linear-gradient(135deg, rgba(76, 201, 240, 0.06), rgba(124, 58, 237, 0.08));
  border-color: rgba(76, 201, 240, 0.25);
}
.status-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 12px;
}
.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(138, 151, 173, 0.15);
  flex-shrink: 0;
}
.status-dot.running {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.18);
  animation: pulse 1.6s ease-in-out infinite;
}
.status-dot.idle    { background: var(--muted); }
.status-dot.busy    { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.status-dot.error   { background: var(--red); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.20); }
  50%      { box-shadow: 0 0 0 10px rgba(46, 204, 113, 0.0); }
}
.status-label {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}
.status-sub {
  margin-top: 2px;
  word-break: break-word;
  max-width: 100%;
  white-space: pre-wrap;
}
.status-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.status-actions .btn { flex: 1 1 100%; }

/* ─── Сетка кнопок Действий ──────────────────────────────── */
.actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.actions-grid .btn { flex: 1 1 auto; min-width: 0; }
@media (max-width: 360px) {
  .actions-grid { grid-template-columns: 1fr; }
}

.action-result {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.action-result.ok   { border-color: rgba(46, 204, 113, 0.4); color: #b2f5cf; }
.action-result.fail { border-color: rgba(239, 68, 68, 0.45); color: #fcaeae; }

/* ─── Лента событий бота ─────────────────────────────────── */
.timeline {
  display: grid;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 2px;
}
.timeline-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  font-size: 13px;
  word-break: break-word;
}
.timeline-row .t { color: var(--muted); font-size: 11px; font-family: "SF Mono", monospace; }
.timeline-row.fail { background: rgba(239, 68, 68, 0.10); color: #fcaeae; }
.timeline-row .k {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.6px;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(76, 201, 240, 0.18);
  margin-right: 6px;
  color: var(--accent);
  text-transform: uppercase;
}

/* ─── collapse details ───────────────────────────────────── */
.card.collapse {
  padding: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}
.card.collapse > summary {
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin: 0;
  user-select: none;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.card.collapse > summary .pill {
  margin-left: auto;
  flex-shrink: 0;
}
.card.collapse > summary .muted.small {
  flex: 1 1 100%;
  min-width: 0;
}
.card.collapse > summary::-webkit-details-marker { display: none; }
.card.collapse > summary::after {
  content: "▾";
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.card.collapse[open] > summary::after { transform: rotate(180deg); }
.card.collapse > *:not(summary) {
  padding: 0 14px;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}
.card.collapse > *:last-child { padding-bottom: 16px; }

.footer-note { text-align: center; padding: 18px 0 26px; font-size: 12px; }

.universe-table {
  margin-top: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.universe-table table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 12px;
}
.universe-table th,
.universe-table td {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px dashed var(--line);
  white-space: nowrap;
  font-family: "SF Mono", "Cascadia Mono", Menlo, monospace;
}
.universe-table th {
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
}
.universe-table th:nth-child(2),
.universe-table td:nth-child(2) { text-align: left; }
.universe-table tbody tr:last-child td { border-bottom: none; }
.universe-table .v-pass { color: var(--green); }
.universe-table .v-weak { color: var(--yellow); }
.universe-table .v-fail { color: var(--red); }

/* ─── Логи (real-time) ─────────────────────────────────────── */
.logs-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding: 4px 0;
}
.logs-toolbar select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}
.logs-toolbar .btn.small {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 12px;
}
.logs-view {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  height: 220px;
  overflow-y: auto;
  font-family: "SF Mono", "Cascadia Mono", Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
}
.logs-view .log-row {
  padding: 1px 0;
  white-space: pre-wrap;
  word-break: break-word;
  border-bottom: 1px dashed rgba(35, 48, 69, 0.4);
}
.logs-view .log-row:last-child { border-bottom: none; }
.logs-view .log-time { color: var(--muted); }
.logs-view .log-name { color: var(--accent); }
.logs-view .lvl-DEBUG    { color: #6b7280; }
.logs-view .lvl-INFO     { color: var(--text); }
.logs-view .lvl-SUCCESS  { color: var(--green); }
.logs-view .lvl-WARNING  { color: var(--yellow); }
.logs-view .lvl-ERROR    { color: var(--red); }
.logs-view .lvl-CRITICAL { color: #fff; background: rgba(239, 68, 68, 0.4); }
