:root {
  --bg: #1b1c1e;
  --panel: #232427;
  --row: #202124;
  --line: #3a3b3e;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --go: #3fbf7a;
  --low: #ea9999;
  --bad: #e5736b;
  --accent: #8ab4f8;
  --radius: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 14px; margin-bottom: 10px; color: var(--muted); font-weight: 500; }

/* ---------- Header ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}
.top-right { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sync { color: var(--muted); font-size: 13px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button {
  background: none; border: 0; color: var(--muted); padding: 6px 14px; cursor: pointer; font: inherit;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-selected="true"] { background: #33353a; color: var(--text); }

/* ---------- Controls ---------- */
.btn, select, input[type="text"], input[type="password"], textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px;
}
.btn { cursor: pointer; }
.btn:hover { border-color: #5a5c61; }
.btn.primary { background: #2f4a3b; border-color: #3d6650; }
.btn.primary:hover { background: #366049; }
.btn.ghost { background: none; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 13px; }
select { padding: 5px 8px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
main { padding: 20px 24px 60px; margin: 0 auto;}

.stats { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 2fr); gap: 16px; margin-bottom: 24px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }

table { border-collapse: collapse; width: 100%; }
.mini th, .mini td { text-align: left; padding: 5px 8px 5px 0; font-weight: 400; }
.mini th { color: var(--muted); font-size: 13px; }
.mini td.num, .mini th.num { text-align: right; }
.mini tr + tr td { border-top: 1px solid var(--line); }
.muted { color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 8px 14px; cursor: pointer; font: inherit; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs span { color: var(--muted); margin-left: 4px; }

.add { display: flex; gap: 8px; margin-bottom: 14px; }
.add input { width: 260px; max-width: 100%; }

/* ---------- Main grid ---------- */
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.grid thead th {
  position: sticky; top: 0; background: var(--panel); color: var(--muted);
  font-weight: 500; font-size: 13px; white-space: normal; vertical-align: bottom;
}
.grid tbody tr { background: var(--row); }
.grid tbody tr:hover { background: #26272b; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid td.c, .grid th.c { text-align: center; }
.grid td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid td.actions { text-align: right; }
.grid td.actions .btn + .btn { margin-left: 6px; }

.coin { font-weight: 600; }
.when { color: var(--muted); font-size: 13px; }

.score { font-weight: 600; }
.score.go { color: var(--go); }
.score.low { color: var(--low); font-weight: 400; }

.tag-long { color: var(--go); }
.tag-short { color: var(--bad); }
.result-ok { color: var(--go); }
.result-bad { color: var(--bad); }
.dot-on { color: var(--go); }
.dot-off { color: #55575c; }

input[type="checkbox"] { width: 16px; height: 16px; accent-color: #3fbf7a; cursor: pointer; }

.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.link.empty { color: var(--muted); }

.empty-state { padding: 28px; text-align: center; color: var(--muted); }
.more { margin-top: 12px; }

/* ---------- Dialog & toasts ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 20px; width: min(440px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin-bottom: 8px; }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog textarea, dialog input { width: 100%; margin-bottom: 4px; resize: vertical; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; }
.toast {
  background: #33353a; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; max-width: 360px;
}
.toast.error { border-color: var(--bad); }

[hidden] { display: none !important; }

@media (max-width: 860px) {
  .stats { grid-template-columns: 1fr; }
  .top, main { padding-left: 14px; padding-right: 14px; }
  .top-right { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Вход и регистрация ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(380px, 100%); display: grid; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 24px;
}
.auth-card .seg { justify-self: start; }
.field { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.field input { width: 100%; font-size: 14px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.form-error { margin: 0; color: var(--bad); font-size: 13px; }
.btn.wide { width: 100%; padding: 8px 12px; }
.user { color: var(--muted); font-size: 13px; padding: 0 4px; }

/* ---------- Вкладки в шапке ---------- */
.top { padding-top: 0; padding-bottom: 0; }
.top h1 { padding: 14px 0; }
.top .tabs { margin: 0; border-bottom: 0; align-self: stretch; }
.top .tabs button { padding: 0 14px; }

/* ---------- Панель управления во вкладке «Статистика» ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 16px; }
.toolbar .right { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 860px) { .toolbar .right { margin-left: 0; } }

/* ---------- Меню пользователя ---------- */
.usermenu { position: relative; }
.user-btn { display: inline-flex; align-items: center; gap: 6px; }
#userName { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text);
  padding: 8px 10px; border-radius: 4px; cursor: pointer; font: inherit;
}
.menu button:hover, .menu button:focus-visible { background: #2d2f33; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- Профиль и админ панель ---------- */
.page { max-width: 520px; display: grid; gap: 16px; }
.form { display: grid; gap: 14px; }
.form h2 { margin-bottom: 0; }
.form h2:not(:first-child) { margin-top: 8px; }
.field input:disabled { opacity: .6; cursor: not-allowed; }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }

/* ---------- Поиск монеты ---------- */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 15; min-width: 100%; width: max-content; max-width: 360px;
  margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.combo-list li { display: flex; justify-content: space-between; gap: 16px; padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.combo-list li[aria-selected="true"] { background: #2d2f33; }
.combo-list .sym { font-weight: 600; }
.combo-list .ex { color: var(--muted); font-size: 12px; align-self: center; }
.combo-list .combo-note { color: var(--muted); cursor: default; }

/* ---------- Биржи ---------- */
.ex-icons { display: inline-flex; gap: 6px; align-items: center; vertical-align: middle; }
.ex-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0;
  background: none; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  opacity: .35; filter: grayscale(1); transition: opacity .15s, filter .15s;
}
.ex-btn:hover { opacity: .7; }
.ex-btn[aria-pressed="true"] { opacity: 1; filter: none; border-color: #5a5c61; background: #2a2b2f; }
.ex-btn svg, .ex-ico svg { width: 16px; height: 16px; display: block; }
.ex-ico { display: inline-grid; place-items: center; width: 22px; height: 22px; }
.auto { white-space: nowrap; cursor: pointer; }

.wr { color: var(--muted); font-size: 13px; margin-left: 4px; }

/* ---------- Заявки на регистрацию ---------- */
.form-ok { margin: 0; color: var(--go); font-size: 13px; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; text-align: center;
  background: var(--go); color: #10231a; font-size: 12px; font-weight: 600; line-height: 18px;
}
.menu .badge { margin-left: 6px; }
#appsTable td.num { white-space: nowrap; }
#appsTable .btn + .btn { margin-left: 6px; }

/* ---------- Направление: Long зелёный, Short красный ---------- */
select.dir { font-weight: 600; }
select.dir option { background: var(--panel); color: var(--text); font-weight: 400; }
select.dir.long, .dir-tag.long { background: rgba(63, 191, 122, .25); border-color: var(--go); color: #7fe0a9; }
select.dir.short, .dir-tag.short { background: rgba(229, 115, 107, .25); border-color: var(--bad); color: #f0908a; }
.dir-tag { display: inline-block; padding: 3px 12px; border: 1px solid; border-radius: var(--radius); font-weight: 600; }

/* ---------- Сортировка по заголовкам ---------- */
.sort-btn { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; white-space: nowrap; }
.sort-btn:hover, .sort-btn.on { color: var(--text); }
.sort-btn .arr { font-size: 10px; opacity: .45; }
.sort-btn.on .arr { opacity: 1; color: var(--accent); }

/* ---------- Пользователи в админ панели ---------- */
#adminView .page { max-width: 980px; }
#adminView .page > .form { width: min(520px, 100%); }
.tscroll { overflow-x: auto; }
#usersTable th, #usersTable td { white-space: nowrap; padding-right: 14px; }
#usersTable td.num { text-align: right; }
#usersTable .btn + .btn { margin-left: 6px; }
