/* Панель копитрейдера — тёмная тема, без внешних зависимостей. */

/* Палитра снята с Polymarket: фирменный синий #1652f0, тёмные поверхности
   с синим подтоном, красный #c41c35. Для текста на тёмном зелёный и красный
   взяты светлее оригинальных — иначе не читаются. */
:root {
  --bg: #0a0e17;
  --panel: #111827;
  --panel-2: #172033;
  --panel-3: #1e2941;
  --border: #24304a;
  --border-soft: #1b2438;
  --text: #e9eefb;
  --muted: #8794b0;
  --accent: #1652f0;
  --accent-hover: #2f66ff;
  --accent-soft: rgba(22, 82, 240, .15);
  --green: #17c964;
  --green-soft: rgba(23, 201, 100, .13);
  --red: #f0455f;
  --red-soft: rgba(240, 69, 95, .13);
  --amber: #f5a524;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── шапка ─────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; letter-spacing: .2px; color: var(--text); text-decoration: none; }
.brand span { color: var(--accent); }
/* Меню страниц живёт не здесь, а внутри рамки контура (.pane-head):
   оно относится к выбранному контуру, а не ко всей панели. */
.topbar .who { color: var(--muted); font-size: 13px; }
.topbar .who a.active { color: var(--text); }

/* ─── вкладки контуров ──────────────────────────────────────────── */
/* Настоящие вкладки, а не ссылки: активная срастается с рамкой ниже,
   и всё содержимое буквально лежит внутри неё. Боевая красная, тестовая
   синяя — понятно без чтения. */
.tabwrap { max-width: 1100px; margin: 0 auto; padding: 20px 24px 32px; }

.contour-tabs { display: flex; gap: 4px; position: relative; z-index: 2; }
.contour-tabs .tab {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 12px 22px; font-size: 14.5px; font-weight: 650;
  color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 10px 10px 0 0;
  /* Неактивная вкладка утоплена: активная должна читаться как «передняя». */
  margin-top: 4px; transition: color .12s, background .12s;
}
.contour-tabs .tab:hover { text-decoration: none; color: var(--text); }
.contour-tabs .tab .dot { width: 8px; height: 8px; background: var(--border); }
.contour-tabs .tab .dot.on { background: var(--green); animation: pulse 1.8s ease-in-out infinite; }

.contour-tabs .tab.active {
  margin-top: 0; padding-bottom: 13px; margin-bottom: -1px;
  background: var(--panel-2); color: var(--text);
  border-width: 2px; border-bottom: none;
}
.contour-tabs .tab.live.active { border-color: var(--red); color: #ffb3be; }
.contour-tabs .tab.test.active { border-color: var(--accent); color: #b9cdff; }

/* Рамка содержимого — продолжение активной вкладки. */
.contour-pane {
  border: 2px solid; border-radius: 0 12px 12px 12px;
  background: var(--panel-2); position: relative; z-index: 1;
}
body.mode-live .contour-pane { border-color: var(--red); }
body.mode-test .contour-pane { border-color: var(--accent); }

.pane-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
}
body.mode-live .pane-head { background: rgba(240, 69, 95, .08); }
body.mode-test .pane-head { background: rgba(22, 82, 240, .08); }
.pane-head nav { display: flex; gap: 4px; }
.pane-head nav a {
  color: var(--muted); padding: 6px 12px; border-radius: 6px; font-size: 14px;
}
.pane-head nav a:hover { background: var(--panel-3); color: var(--text); text-decoration: none; }
.pane-head nav a.active { background: var(--panel-3); color: var(--text); }
.pane-note { font-size: 12px; font-weight: 600; }
body.mode-live .pane-note { color: #ffb0bc; }
body.mode-test .pane-note { color: #a8c2ff; }

.contour-pane main { max-width: none; margin: 0; padding: 20px 18px; }

/* Страница вне контуров (реквизиты) — намеренно без рамки и без вкладок. */
main.outside { max-width: 1100px; margin: 0 auto; padding: 24px; }
.outside-note {
  color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .6px;
}
/* Возврат к контурам. Страница вне вкладок, поэтому выход с неё должен быть
   виден сразу — иначе она читается как тупик. */
.outside-head {
  display: flex; align-items: center; gap: 14px; margin-bottom: 14px;
}
.outside-head .back { font-size: 13px; font-weight: 600; }

/* Тестовый контур в админской таблице — приписка к строке пользователя,
   а не самостоятельная запись. Приглушаем, чтобы бой читался первым. */
tr.sub-row > td { background: rgba(0, 0, 0, .16); font-size: 13px; }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ─── карточки ──────────────────────────────────────────────────── */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.card > h2 {
  margin: 0 0 4px; font-size: 15px; font-weight: 600; letter-spacing: .2px;
}
.card > .hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.card > h2 + .grid, .card > h2 + .row, .card > h2 + table { margin-top: 16px; }

/* ─── статус-строка ─────────────────────────────────────────────── */
.statusbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: 999px;
  font-size: 13px; font-weight: 600; border: 1px solid transparent;
}
.pill.on   { background: var(--green-soft); color: var(--green); border-color: rgba(23,201,100,.3); }
.pill.off  { background: var(--panel-2); color: var(--muted); border-color: var(--border); }
.pill.dry  { background: var(--accent-soft); color: #6f9bff; border-color: rgba(22,82,240,.4); }
.pill.live { background: var(--red-soft); color: var(--red); border-color: rgba(240,69,95,.35); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.on .dot { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ─── плитки метрик ─────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
}
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.tile .value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .value.sm { font-size: 15px; font-weight: 500; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 5px; font-variant-numeric: tabular-nums; }

/* Главные показатели: крупнее и заметнее второстепенных. */
.tiles.hero { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.tiles.hero .tile { padding: 18px 20px; background: var(--panel-2); }
.tiles.hero .value { font-size: 30px; margin-top: 6px; letter-spacing: -.5px; }

/* Плитка-ссылка: ведёт на страницу с подробностями. */
a.tile {
  display: block; color: inherit; text-decoration: none;
  transition: border-color .14s, background .14s, transform .14s;
}
a.tile:hover {
  text-decoration: none; border-color: var(--accent);
  background: var(--panel-3); transform: translateY(-1px);
}
a.tile .label::after {
  content: " →"; color: var(--accent); font-weight: 700;
}

/* Диагностика: та же сетка, но приглушена — это не то, на что смотрят каждый день. */
.tiles.diag { grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 10px; }
.tiles.diag .tile { padding: 10px 12px; background: transparent; border-color: var(--border-soft); }
.tiles.diag .label { font-size: 10.5px; }
.tiles.diag .value { font-size: 16px; font-weight: 600; color: var(--muted); }

/* ─── формы ─────────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
.field .note { font-size: 12px; color: var(--muted); opacity: .85; }

input[type=text], input[type=password], input[type=number], input[type=email], select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 11px; font-size: 14px; font-family: inherit; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input.mono { font-family: var(--mono); font-size: 13px; }
input:disabled { opacity: .5; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 16px; font-size: 14px; font-family: inherit; font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: var(--panel-3); border-color: #31406a; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--red); border-color: rgba(240,69,95,.35); }
button.danger:hover:not(:disabled) { background: var(--red-soft); }
button.sm { padding: 5px 10px; font-size: 13px; }

/* переключатель */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .track {
  width: 40px; height: 22px; border-radius: 999px;
  background: var(--border); position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch .text { font-size: 14px; }

/* ─── предупреждения ────────────────────────────────────────────── */
.warn {
  border-radius: 8px; padding: 12px 14px; font-size: 13px; line-height: 1.5;
  border: 1px solid; margin-bottom: 16px;
}
.warn.red   { background: var(--red-soft); border-color: rgba(240,69,95,.3); color: #ffb0bc; }
.warn.amber { background: rgba(245,165,36,.1); border-color: rgba(245,165,36,.32); color: #f2cb84; }
.warn.blue  { background: rgba(76,141,255,.09); border-color: rgba(22,82,240,.35); color: #a8c2ff; }
.warn b { color: inherit; }

/* ─── таблицы ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: .4px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid rgba(36,48,74,.5); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 4px; font-weight: 600; }
.tag.buy  { background: var(--green-soft); color: var(--green); }
.tag.sell { background: var(--red-soft); color: var(--red); }
.tag.ok   { background: var(--green-soft); color: var(--green); }
.tag.skip { background: var(--panel-3); color: var(--muted); }
.tag.err  { background: var(--red-soft); color: var(--red); }
.tag.wait { background: var(--accent-soft); color: #6f9bff; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 28px 0; }
.pnl-up   { color: var(--green); font-variant-numeric: tabular-nums; }
.pnl-down { color: var(--red);   font-variant-numeric: tabular-nums; }

/* ─── журнал ────────────────────────────────────────────────────── */
.log {
  background: #070b13; border: 1px solid var(--border); border-radius: 8px;
  height: 320px; overflow-y: auto; padding: 12px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
}
.log .line { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.log .t { color: #5a6885; flex: none; }
.log .m { flex: 1; }
.log .INFO .m { color: #cfd9ee; }
.log .WARNING .m { color: var(--amber); }
.log .ERROR .m { color: var(--red); }

/* ─── вход ──────────────────────────────────────────────────────── */
.auth-wrap { max-width: 380px; margin: 9vh auto; padding: 0 20px; }
.auth-wrap .brand { font-size: 20px; text-align: center; margin-bottom: 6px; }
.auth-wrap .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.auth-wrap .card { padding: 24px; }
.auth-wrap .field { margin-bottom: 14px; }
.auth-wrap button { width: 100%; margin-top: 6px; }
.auth-wrap .alt { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }

/* ─── тост ──────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 8px; font-size: 14px; max-width: 520px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: rgba(240,69,95,.5); color: #ffb0bc; }
#toast.ok  { border-color: rgba(23,201,100,.5); color: #8ef0bb; }

.section-sep { height: 1px; background: var(--border); margin: 20px 0; border: 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

@media (max-width: 640px) {
  main, main.outside { padding: 16px; }
  .tabwrap { padding: 14px 12px 24px; }
  .contour-pane main { padding: 14px 12px; }
  .contour-tabs .tab { padding: 10px 14px; font-size: 13px; }
  .pane-head { padding: 8px 10px; gap: 8px; }
  .pane-head nav { flex-wrap: wrap; }
  .pane-head nav a { padding: 5px 9px; font-size: 13px; }
  .pane-note { display: none; }
  .topbar { padding: 0 14px; gap: 12px; }
  .topbar .who { font-size: 12px; }
  .topbar .brand { font-size: 14px; }
}
