:root {
  --bg: #050505;
  --panel: #0c0c0c;
  --inner: #080808;
  --btn: #141414;
  --btn-hover: #1e1e1e;
  --border: #2a2a2a;
  --border-strong: #3a3a3a;
  --row: #1c1c1c;
  --text: #f4f4f4;
  --text-2: #d6d6d6;
  --muted: #8c8c8c;
  --caption: #7a7a7a;
  --accent: #ff5c1a;
  --accent-hover: #ff7a3d;
  --link: #ff8a5b;
  --ok: #6fe3bf;
  --warn: #f5c26b;
  --err: #ff9b8a;
  --lighter: #9cc3ff;
  --vario: #d3b7ff;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--mono); font-size: 13px; line-height: 1.45; }
a { color: var(--link); }
button, input, select, textarea { font-family: inherit; font-size: 13px; color: var(--text); }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--inner); border-right: 2px solid var(--border); padding: 24px 16px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.brand-title { font-size: 14px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 44px; font-size: 14px; font-weight: 500; color: var(--text-2); text-decoration: none; }
.nav a:hover { background: var(--btn); }
.nav a.active { background: var(--accent); color: #050505; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-status { margin-top: auto; padding: 14px; background: var(--panel); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.running { background: var(--ok); }
.dot.error { background: var(--err); }
.dot.stopping { background: var(--warn); }
.sidebar-foot { padding: 0 8px; }

.main { flex-grow: 1; min-width: 0; }
.view { padding: 24px 28px; display: flex; flex-direction: column; gap: 16px; max-width: 1600px; }

.tabbar { display: none; }
.mobile-status { display: none; }

.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 20px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.head .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.head .actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--border); padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card.accent { border-color: var(--accent); }
.card-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #bfbfbf; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inner { background: var(--inner); border: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 16px; }
.split-3-1 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: 16px; }
.split-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.kpi { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--border); }
.kpi .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 22px; font-weight: 500; }
.kpi .value small { font-size: 12px; color: var(--muted); }
.kpi .hint { font-size: 12px; color: var(--muted); }

table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 11px; font-weight: 500; color: var(--muted); padding: 10px 10px; border-bottom: 1px solid var(--border); letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
td { font-size: 13px; padding: 9px 10px; border-bottom: 1px solid var(--row); vertical-align: middle; }
td.mono { white-space: nowrap; }
.account-position { white-space: nowrap; }
tr.dim { opacity: .45; }
tr.picked { background: #120c08; }
.table-wrap { overflow-x: auto; }
.account-actions { gap: 6px; width: 170px; }
.account-actions > .btn { width: 100%; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
@media (min-width: 601px) {
  #accounts-table .account-actions-cell,
  #accounts-table th:last-child { position: sticky; right: 0; z-index: 1; width: 190px; min-width: 190px; background: var(--panel); box-shadow: -1px 0 var(--border); }
  #accounts-table .account-actions-cell { padding: 9px 10px; }
  #accounts-table .account-actions > .btn { padding: 6px 10px; }
}

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; border: 1px solid var(--border-strong); background: #000; color: #bdbdbd; white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: #1f5c4c; }
.chip.warn { color: var(--warn); border-color: #6b4a14; }
.chip.err { color: var(--err); border-color: #6d2c2c; }
.chip.lighter { color: var(--lighter); border-color: #27406e; }
.chip.variational, .chip.vario { color: var(--vario); border-color: #4a3470; }
.chip.mixed { color: var(--warn); border-color: #6b4a14; }

.btn { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 0 16px; min-height: 44px; border: 1px solid var(--border-strong); background: var(--btn); color: var(--text); cursor: pointer; }
.btn:hover { background: var(--btn-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #050505; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--bg); border-color: var(--err); color: var(--err); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 11px; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #050505; }

input[type=text], input[type=number], input[type=password], input[type=search], select, textarea { background: var(--inner); border: 1px solid var(--border-strong); padding: 0 12px; min-height: 44px; width: 100%; }
textarea { padding: 10px 12px; min-height: 120px; resize: vertical; }
label { font-size: 12px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; color: var(--text); font-size: 13px; }
input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin: 0; border: 1px solid var(--border-strong); background: var(--inner); position: relative; cursor: pointer; flex-shrink: 0; }
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked::after { content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid #050505; border-width: 0 2px 2px 0; transform: rotate(45deg); }
input[type=checkbox]:focus-visible, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.progress { height: 8px; background: var(--btn); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

.pos { color: var(--ok); } .neg { color: var(--err); } .muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); }
.warn-text { color: var(--warn); font-size: 12px; }
.err-text { color: var(--err); font-size: 12px; }

.log { background: #000; border: 1px solid var(--border); padding: 10px 14px; height: calc(100vh - 260px); min-height: 300px; overflow: auto; }
.log .line { display: flex; gap: 12px; padding: 4px 0; border-bottom: 1px solid #181818; font-size: 12.5px; line-height: 1.5; }
.log .ts { color: var(--caption); flex-shrink: 0; width: 64px; }
.log .lvl { flex-shrink: 0; width: 20px; text-align: center; font-weight: 600; }
.log .INFO, .log .DEBUG { color: var(--text-2); } .log .SUCCESS { color: var(--ok); } .log .WARNING { color: var(--warn); } .log .ERROR, .log .CRITICAL { color: var(--err); }
pre.out { background: #000; border: 1px solid var(--border); padding: 12px; margin: 0; max-height: 420px; overflow: auto; font-size: 12px; white-space: pre-wrap; color: var(--text-2); }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .82); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { width: 560px; max-width: 100%; background: var(--panel); border: 1px solid var(--border-strong); padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal h2 { margin: 0; font-size: 18px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel); border: 1px solid var(--border-strong); padding: 10px 14px; max-width: 420px; font-size: 12px; }
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok { border-color: #1f5c4c; color: var(--ok); }

.mode-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--panel); border: 1px solid var(--border); min-height: 118px; }
.mode-card .title { font-size: 14px; font-weight: 600; }
.mode-card .text { font-size: 12px; color: var(--muted); flex-grow: 1; }
.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-section .key { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #bfbfbf; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .view { padding: 14px 16px 110px; gap: 12px; }
  .grid-3, .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split-3-1, .split-2-1, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .head h1 { font-size: 16px; }
  .kpi .value { font-size: 18px; }
  .log { height: calc(100vh - 300px); }
  .mobile-status { display: block; position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); padding: 4px 16px; background: var(--inner); border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 40; }
  .mobile-status.running { color: var(--ok); }
  .mobile-status.error { color: var(--err); }
  .mobile-status.stopping { color: var(--warn); }
  .toast-root { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .modal { max-height: calc(100vh - 32px); overflow: auto; }
  .view { padding-bottom: 130px; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 2px solid var(--border); z-index: 40; }
  .tabbar a { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 9px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); text-decoration: none; min-height: 56px; padding: 0 2px; overflow: hidden; }
  .tabbar a.active { color: var(--accent); border-top: 2px solid var(--accent); margin-top: -2px; }
  .tabbar svg { width: 20px; height: 20px; }
  td, th { padding: 8px 6px; }
}

/* Settings: explanations stay readable at every viewport width. */
.settings-cards { align-items: start; grid-template-columns: minmax(0, 1fr); }
details.settings-card { display: block; min-width: 0; }
.settings-card > summary { cursor: pointer; margin: 0; display: list-item; line-height: 1.5; }
.settings-card-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 22px; padding-top: 18px; }
.settings-card-body > .settings-section, .settings-card-body > .settings-grid, .settings-card-body > .setting-help, .settings-card-body > .setting-code { grid-column: 1 / -1; }
.settings-grid { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 20px 16px; align-items: start; }
.settings-grid > .settings-section { grid-column: 1 / -1; }
.setting-label { color: var(--text); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.setting-help { color: var(--muted); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.setting-code { display: none; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.show-setting-keys .setting-code { display: block; }
.setting-time { color: var(--accent); font-size: 12px; line-height: 1.5; }
.range-bound { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.setting-field .field.inline { align-items: flex-start; min-height: 24px; line-height: 1.5; }
.setting-field input[type=checkbox] { margin-top: 2px; }
.settings-section { padding-top: 4px; }
.settings-card-body > .settings-section + .settings-section { border-top: 1px solid var(--border); padding-top: 20px; }
.settings-scenario, .settings-advanced { border: 1px solid var(--border); padding: 12px; min-width: 0; }
.settings-scenario > summary, .settings-advanced > summary { cursor: pointer; font-size: 13px; line-height: 1.6; }
.settings-scenario summary .chip { margin-left: 10px; }
.settings-advanced > .settings-grid { margin-top: 16px; }
.settings-guide { padding: 16px; border: 1px solid var(--border); background: var(--panel); }
.settings-guide > summary { cursor: pointer; font-size: 14px; }
.settings-guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 8px 24px; font-size: 12px; line-height: 1.65; }
.settings-guide-grid strong { color: var(--accent); }
@media (max-width: 600px) {
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-guide-grid { grid-template-columns: minmax(0, 1fr); }
}

.copy-address { background: transparent; border: 0; padding: 6px 0; color: inherit; cursor: copy; text-align: left; white-space: nowrap; }
.copy-address:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.copy-address:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.head .statistics-actions { align-items: flex-end; }

.mobile-savebar { display: none; }
.mobile-menu { display: grid; gap: 12px; }
.mobile-menu a { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.mobile-menu svg { width: 22px; height: 22px; }
.account-summary > summary { color: var(--muted); cursor: pointer; padding-bottom: 10px; }

@media (max-width: 900px) {
  .tabbar button { appearance: none; border: 0; border-top: 2px solid transparent; background: transparent; font: inherit; cursor: pointer; }
  .tabbar a, .tabbar button { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--muted); min-height: 56px; padding: 0 3px; text-decoration: none; }
  .tabbar button svg { width: 22px; height: 22px; }
  .tabbar button.active { color: var(--accent); border-top-color: var(--accent); }
}

@media (max-width: 600px) {
  .view { padding: 16px 12px calc(120px + env(safe-area-inset-bottom)); }
  .view > *, .head > *, .row > *, .grid > *, .stack > * { min-width: 0; max-width: 100%; }
  .head { gap: 12px; }
  .head .sub, .card, .inner, .kpi, .mode-card { overflow-wrap: anywhere; }
  .head .actions, .head .statistics-actions { width: 100%; margin-left: 0 !important; gap: 8px; }
  .head .actions > .btn { flex: 1 1 auto; }
  .statistics-actions > .field { width: 100%; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px 12px; }
  .card-title { align-items: flex-start; flex-wrap: wrap; line-height: 1.5; }
  .chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 18px; }
  .btn, .btn.small, .copy-address { min-height: 44px; }
  .btn, .btn.small { padding: 10px 12px; line-height: 1.45; font-size: 12px; }
  .copy-address { padding: 10px 0; max-width: 100%; }
  input[type=text], input[type=number], input[type=password], input[type=search], select, textarea { font-size: 16px; min-height: 48px; }
  input[type=checkbox] { width: 24px; height: 24px; }
  input[type=checkbox]:checked::after { left: 8px; top: 3px; }
  .field.inline, .setting-field .field.inline { min-height: 44px; align-items: center; }
  summary { min-height: 44px; padding-block: 10px; }
  .table-wrap { width: 100%; }
  table.mobile-table, .mobile-table tbody { display: block; width: 100%; }
  .mobile-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .mobile-table tbody { display: grid; gap: 12px; }
  .mobile-table tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; padding: 10px; border: 1px solid var(--border-strong); background: var(--inner); }
  .mobile-table td { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; padding: 8px 0; white-space: normal; overflow-wrap: anywhere; }
  .mobile-table td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
  .mobile-table td[data-label=""]::before { display: none; }
  .mobile-table td.mobile-wide { grid-column: 1 / -1; }
  [data-scroll-key="accounts"] .mobile-table td { order: 3; }
  [data-scroll-key="accounts"] .mobile-table td:nth-child(-n+2) { order: 0; }
  [data-scroll-key="accounts"] .mobile-table td:nth-child(3),
  [data-scroll-key="accounts"] .mobile-table td:nth-child(4) { order: 1; }
  [data-scroll-key="accounts"] .mobile-table td[data-label="Действия"] { order: 2; }
  .mobile-table td[data-label="Действия"] > .stack { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; min-width: 0 !important; }
  .mobile-table td[data-label="Действия"] > .stack > :first-child,
  .mobile-table td[data-label="Действия"] > .stack > span { grid-column: 1 / -1; }
  .account-position { white-space: normal; overflow-wrap: anywhere; }
  .account-position > span { white-space: nowrap; }
  .log { height: calc(100dvh - 370px); min-height: 240px; padding: 10px; }
  .log .line { display: grid; grid-template-columns: 64px 20px minmax(0,1fr); gap: 6px; }
  .log .line > :last-child { overflow-wrap: anywhere; white-space: pre-wrap; }
  pre.out { overflow-wrap: anywhere; }
  .modal-back { align-items: flex-end; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal { padding: 16px; width: 100%; max-height: calc(var(--visible-height, 100dvh) - 24px - env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
  .modal h2 { font-size: 16px; }
  .modal .actions { position: sticky; bottom: -16px; margin: 0 -16px -16px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--border); }
  .modal .actions .btn { flex: 1 1 120px; }
  .toast-root { left: 12px; right: 12px; bottom: calc(100px + env(safe-area-inset-bottom)); pointer-events: none; }
  .toast { max-width: 100%; overflow-wrap: anywhere; }
  .tabbar { height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a, .tabbar button { min-height: 62px; }
  .mobile-status { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .mobile-savebar { display: flex; gap: 8px; position: fixed; z-index: 35; left: 0; right: 0; bottom: calc(88px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border-strong); padding: 10px 12px; }
  .mobile-savebar .primary { flex: 1; }
  .view.with-mobile-savebar { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }
  .with-mobile-savebar > .head .actions > button { display: none; }
}
