:root {
  --bg: #E8ECEF;
  --surface: #FFFFFF;
  --surface-2: #F4F6F8;
  --ink: #13202B;
  --muted: #5B6873;
  --line: #D3DAE0;
  --accent: #1F45FF;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3E8FF;
  --buy: #0B7F57;
  --buy-soft: #DDF3EA;
  --sell: #B8430F;
  --sell-soft: #FBE7DC;
  --signal: #FFB800;
  --signal-soft: #FFF4D6;
  --danger: #C62B2B;
  --ok: #12A36B;
  --warn: #D98A00;
  --shadow: 0 1px 2px rgba(19, 32, 43, .06), 0 6px 18px rgba(19, 32, 43, .06);
  --radius-s: 8px;
  --radius: 14px;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Unbounded", "Onest", system-ui, sans-serif;
  color-scheme: light;
}

/* Тёмная тема: выбрана вручную или «Авто» при тёмной системе */
:root[data-theme="dark"] {
  --bg: #0F1720;
  --surface: #17222D;
  --surface-2: #1D2A37;
  --ink: #E6EDF3;
  --muted: #93A1AE;
  --line: #2A3A4A;
  --accent: #6F86FF;
  --accent-ink: #0F1720;
  --accent-soft: #232F5A;
  --buy: #3DD39A;
  --buy-soft: #12342A;
  --sell: #FF9466;
  --sell-soft: #3A2318;
  --signal: #FFC83D;
  --signal-soft: #3A2F12;
  --danger: #FF6B6B;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1720;
    --surface: #17222D;
    --surface-2: #1D2A37;
    --ink: #E6EDF3;
    --muted: #93A1AE;
    --line: #2A3A4A;
    --accent: #6F86FF;
    --accent-ink: #0F1720;
    --accent-soft: #232F5A;
    --buy: #3DD39A;
    --buy-soft: #12342A;
    --sell: #FF9466;
    --sell-soft: #3A2318;
    --signal: #FFC83D;
    --signal-soft: #3A2F12;
    --danger: #FF6B6B;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

/* переключатель темы в шапке */
.theme-btn svg { width: 19px; height: 19px; }
.theme-btn .i-sun, .theme-btn .i-moon, .theme-btn .i-auto { display: none; }
:root[data-theme="light"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: block; }
:root:not([data-theme]) .theme-btn .i-auto { display: block; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── кнопки ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover, .btn-quiet:hover { background: var(--surface-2); }
.btn-quiet { background: var(--surface); border-color: var(--line); }
.btn-danger-quiet { background: transparent; border-color: var(--line); color: var(--danger); }
.btn-wide { width: 100%; min-height: 46px; font-size: 15px; }
.btn.is-on { background: var(--signal-soft); border-color: var(--signal); }
.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.is-muted { color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; }

/* ── вход ─────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border-radius: 18px; padding: 28px 24px;
  box-shadow: var(--shadow); display: grid; gap: 16px;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  -webkit-mask: none; position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 5px 8px 5px;
  border-left: 3px solid var(--accent-ink); border-bottom: 3px solid var(--accent-ink);
  transform: skewX(-12deg); opacity: .95;
}

/* ── поля ─────────────────────────────── */
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
input:not([type=checkbox]):not([type=radio]):not([type=range]), select {
  width: 100%; min-height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.form-error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 500; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 12px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span { display: block; text-align: center; padding: 8px 0; border-radius: 9px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.segmented:not(.segmented-3) label:first-child input:checked + span { color: var(--buy); }
.segmented:not(.segmented-3) label:last-child input:checked + span { color: var(--sell); }
.segmented-3 { grid-template-columns: 1fr 1fr 1fr; }
.segmented-3 span { font-size: 14px; }

.group { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
.group legend { font-weight: 600; padding: 0; margin-bottom: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
}
.chip small { color: var(--muted); }
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed=true] small { color: inherit; opacity: .8; }

/* ── шапка ─────────────────────────────── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.is-running { background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: breathe 2.4s infinite; }
.dot.is-paused { background: var(--warn); }
.dot.is-error { background: var(--danger); }
@keyframes breathe { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.market { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-left: auto; }
.market b { color: var(--ink); font-weight: 600; font-size: 14px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
#btn-pause.is-paused { background: var(--signal-soft); border-color: var(--signal); }

.banner {
  background: var(--signal-soft); border-bottom: 1px solid var(--signal); padding: 10px 24px; font-size: 14px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}

/* ── раскладка ─────────────────────────────── */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px;
  padding: 24px; max-width: 1380px; width: 100%; margin: 0 auto; align-items: start;
}
.panel-col { min-width: 0; }
.col-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 12px; margin-bottom: 14px; min-height: 40px; }
.col-tools { display: flex; gap: 8px; align-items: center; }
.col-tools select { width: auto; min-height: 38px; max-width: 220px; }
.filters { position: sticky; top: 88px; }

/* ── лента ─────────────────────────────── */
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.alert {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 22px; padding: 18px 20px;
  grid-template-areas: "price main actions" "price meta actions";
  border-left: 5px solid var(--line); position: relative;
}
.alert-price { grid-area: price; }
.alert-main { grid-area: main; }
.alert-meta { grid-area: meta; }
.alert-actions { grid-area: actions; }
.alert.side-BUY { border-left-color: var(--buy); }
.alert.side-SELL { border-left-color: var(--sell); }
.alert.is-fresh { animation: arrive 1.2s ease-out; }
.alert.is-unseen { background: linear-gradient(0deg, var(--surface), var(--surface)) padding-box; box-shadow: 0 0 0 2px var(--signal), var(--shadow); }
@keyframes arrive {
  0% { transform: translateY(-10px) scale(.985); opacity: 0; background: var(--signal-soft); }
  25% { transform: none; opacity: 1; background: var(--signal-soft); }
  100% { background: var(--surface); }
}
.alert-price { display: grid; align-content: center; min-width: 150px; }
.alert-price .num { font-family: var(--display); font-weight: 700; font-size: 34px; line-height: 1.05; letter-spacing: -.02em; }
.alert-price .cur { color: var(--muted); font-size: 13px; margin-top: 4px; }
.alert-main { display: grid; gap: 4px; min-width: 0; }
.alert-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; }
.side-tag { font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.side-tag.BUY { background: var(--buy-soft); color: var(--buy); }
.side-tag.SELL { background: var(--sell-soft); color: var(--sell); }
.alert-filter { color: var(--muted); }
.alert-limits { font-size: 17px; font-weight: 600; }
.alert-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.alert-meta .merchant { color: var(--accent); font-weight: 600; }
.bank-list { display: flex; flex-wrap: wrap; gap: 4px; }
.bank { background: var(--surface-2); border-radius: 6px; padding: 1px 8px; font-size: 12px; color: var(--ink); }
.alert-actions { display: grid; gap: 8px; align-content: center; justify-items: stretch; min-width: 190px; }
.alert-actions .btn-primary { min-height: 46px; font-size: 15px; }
.alert-sub { display: flex; gap: 6px; }
.alert-sub .btn { flex: 1; min-height: 32px; padding: 0 10px; font-size: 13px; font-weight: 500; }
.alert-time { position: absolute; top: 12px; right: 16px; font-size: 12px; color: var(--muted); }
.alert-actions { padding-top: 14px; }

.empty { background: var(--surface); border-radius: var(--radius); padding: 28px 24px; color: var(--muted); border: 1px dashed var(--line); }
.empty p { margin: 0; }
.empty-title { color: var(--ink); font-weight: 600; font-size: 16px; margin-bottom: 4px !important; }

/* ── фильтры ─────────────────────────────── */
.filter-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.filter-item { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.filter-item.is-off { opacity: .62; box-shadow: none; border: 1px solid var(--line); }
.filter-top { display: flex; align-items: center; gap: 10px; }
.filter-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-name small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.filter-facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; margin: 0; }
.filter-facts dt { color: var(--muted); }
.filter-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.filter-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-actions .btn { min-height: 32px; padding: 0 12px; font-size: 13px; font-weight: 500; }

.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── диалоги ─────────────────────────────── */
dialog.sheet {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet > form { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
dialog::backdrop { background: rgba(10, 18, 26, .45); backdrop-filter: blur(2px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.sheet-body { padding: 18px 20px; display: grid; gap: 20px; overflow-y: auto; min-height: 0; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
dialog.sheet-side { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; border-radius: 18px 0 0 18px; width: min(440px, 100vw); }
.set-block { display: grid; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.set-block:last-child { border-bottom: 0; }
.blocklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.blocklist li { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface-2); border-radius: 8px; padding: 6px 6px 6px 12px; font-size: 14px; }
.blocklist .btn { min-height: 30px; padding: 0 10px; font-size: 13px; }

.test-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.test-row:last-child { border-bottom: 0; }
.test-row .num { font-family: var(--display); font-weight: 700; font-size: 20px; min-width: 84px; }
.test-row .meta { font-size: 13px; color: var(--muted); }
.test-row .btn { min-height: 34px; font-size: 13px; }

/* ── уведомления ─────────────────────────────── */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.is-error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.tabbar { display: none; }

/* ── телефон ─────────────────────────────── */
@media (max-width: 900px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .brand-text { display: none; }
  .market { order: 5; width: 100%; margin-left: 0; gap: 12px; overflow-x: auto; }
  .topbar-actions { margin-left: auto; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 96px; gap: 16px; }
  .col-tools { width: 100%; }
  .col-tools select { flex: 1; max-width: none; }
  .test-row { grid-template-columns: auto minmax(0, 1fr); }
  .test-row .btn { grid-column: 1 / -1; }
  .filters { position: static; }
  .panel-col { display: none; }
  .panel-col.is-active { display: block; }
  .alert { grid-template-columns: minmax(0, 1fr); grid-template-areas: "price" "main" "meta" "actions"; padding: 16px; gap: 10px; }
  .alert-price, .alert-actions { min-width: 0; }
  .alert-price .num { font-size: 30px; }
  .alert-actions { padding-top: 0; }
  .tabbar {
    display: grid; grid-template-columns: 1fr 1fr; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  }
  .tab { border: 0; background: none; padding: 10px; font-weight: 600; color: var(--muted); border-radius: 10px; cursor: pointer; position: relative; }
  .tab.is-active { color: var(--accent); background: var(--accent-soft); }
  .tab-badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--signal); color: #1b1300; font-size: 12px; line-height: 20px; }
  dialog.sheet { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  dialog.sheet-side { height: 92vh; max-height: 92vh; }
}
@media (max-width: 420px) {
  #btn-pause { padding: 0 12px; }
  .row-2 { gap: 8px; }
}

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