/* GridBot — панель владельца. Тёмная тема по макету. */
:root {
  --bg: #0B0E14;
  --surface: #121722;
  --surface-2: #0F141D;
  --surface-3: #1A2232;
  --border: #1F2735;
  --text: #E6EAF2;
  --muted: #97A1B3;
  --accent: #4C8DFF;
  --accent-text: #9DC0FF;
  --green: #2EBD85;
  --red: #F6465D;
  --red-text: #FF8A98;
  --amber: #F5A524;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: #7FAEFF; }
[hidden] { display: none !important; }
button { font-family: var(--sans); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.amber { color: var(--amber); }
.nowrap { white-space: nowrap; }

/* ---------- кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: 600 14px var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3B7BF0; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(246,70,93,.12); }
.btn-danger-solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { height: 36px; padding: 0 12px; font-size: 13px; }
.btn-wide { width: 100%; }

.seg { display: inline-flex; gap: 4px; padding: 4px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { border: 0; border-radius: 8px; padding: 0 16px; height: 36px; font: 600 13px var(--sans); cursor: pointer;
  background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg button.live[aria-pressed="true"] { background: var(--red); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; }
.input-wrap { position: relative; }
.input-wrap .unit { position: absolute; right: 12px; top: 0; height: 44px; display: flex; align-items: center; font-size: 13px; color: var(--muted); pointer-events: none; }
input[type=text], input[type=number], input[type=password], select {
  width: 100%; height: 44px; padding: 0 56px 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 15px; font-family: var(--mono); }
input:disabled { opacity: .6; }
select { padding-right: 12px; font-family: var(--sans); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.form-error { color: var(--red-text); font-size: 13px; min-height: 18px; }

.switch-row { display: flex; align-items: flex-start; gap: 14px; padding: 12px 0; border-top: 1px solid var(--border); }
.switch-row .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.switch-row .title { font-size: 14px; font-weight: 600; }
.switch { border: 0; background: transparent; padding: 0; cursor: pointer; }
.switch .track { display: block; width: 44px; height: 26px; border-radius: 13px; background: var(--border); position: relative; transition: background .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: #fff; transition: left .15s; }
.switch[aria-checked="true"] .track { background: var(--green); }
.switch[aria-checked="true"] .knob { left: 21px; }
.switch:disabled { opacity: .45; cursor: not-allowed; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600;
  background: var(--surface-3); color: var(--muted); vertical-align: middle; }
.badge.blue { background: rgba(76,141,255,.15); color: var(--accent-text); }
.badge.green { background: rgba(46,189,133,.15); color: var(--green); }
.badge.red { background: rgba(246,70,93,.15); color: var(--red-text); }
.badge.amber { background: rgba(245,165,36,.15); color: var(--amber); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 6px 0 4px; font-size: 20px; }
.login-card input { padding-right: 12px; }

/* ---------- раскладка ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { flex: 0 0 248px; padding: 24px 16px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; font-weight: 700; font-size: 17px; }
.brand-icon { width: 34px; height: 34px; border-radius: 10px; background: var(--accent) url("/static/favicon.svg") center/100% no-repeat; flex: none; }
.nav-links { display: flex; flex-direction: column; gap: 6px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px; text-decoration: none; font-size: 14px; color: var(--muted); }
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link[aria-current="page"] { color: var(--text); background: var(--surface-3); }
.nav-link svg { flex: none; }
.server-box { margin: 24px 0 12px; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--muted); }
.server-box b { color: var(--text); font-weight: 400; font-family: var(--mono); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 4px; background: var(--green); flex: none; }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }

.main { flex: 1; min-width: 0; padding: 24px 28px 40px; display: flex; flex-direction: column; gap: 20px; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .sub { font-size: 13px; color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; height: 36px; border-radius: 18px; font-size: 13px; font-weight: 600;
  background: rgba(46,189,133,.12); color: var(--green); }
.status-pill.paused { background: rgba(245,165,36,.12); color: var(--amber); }
.status-pill.paused .dot { background: var(--amber); }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 16px; border-radius: 12px; font-size: 14px; }
.banner.test { background: rgba(76,141,255,.10); border: 1px solid rgba(76,141,255,.35); color: var(--accent-text); }
.banner.live { background: rgba(246,70,93,.12); border: 1px solid rgba(246,70,93,.4); color: var(--red-text); }
.banner.warn { background: rgba(245,165,36,.10); border: 1px solid rgba(245,165,36,.35); color: var(--amber); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card h2, .card-title { margin: 0; font-size: 15px; font-weight: 600; }
.card .card-sub { font-size: 13px; color: var(--muted); margin-top: -8px; }
.section-card h2 { font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 700; font-family: var(--mono); overflow-wrap: anywhere; }
.stat .extra { font-size: 13px; color: var(--muted); font-family: var(--mono); }
.row { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; }
.grow-3 { flex: 3 1 560px; }
.grow-1 { flex: 1 1 300px; }
.grow-half { flex: 1 1 420px; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

/* ---------- график ---------- */
.chart-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button { height: 34px; padding: 0 14px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); font: 600 13px var(--sans); cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.tf { margin-left: auto; display: flex; gap: 4px; }
.tf button { padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: 12px var(--mono); cursor: pointer; }
.tf button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.chart { width: 100%; height: 360px; }
.chart-small { width: 100%; height: 160px; }
.legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; }
.legend .l-base { height: 2px; background: var(--amber); }
.legend .l-buy { border-top: 2px dashed var(--accent); }
.legend .l-filled { border-top: 2px dashed var(--green); }
.legend .l-tp { height: 2px; background: var(--green); }
.legend .l-sl { border-top: 2px dotted var(--red); }
.empty { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; font-size: 13px; line-height: 1.6; }

/* ---------- топ монет ---------- */
.coin { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.coin-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rank { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.rank.dim { background: var(--surface-3); color: var(--muted); }
.coin-name { font-weight: 700; font-size: 15px; }
.trend { margin-left: auto; font-size: 12px; color: var(--muted); }
.trend.up { color: var(--green); }
.trend.down { color: var(--red-text); }
.bar { flex: 1; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.bar > div { height: 6px; background: var(--accent); border-radius: 3px; }
.scoreline { display: flex; align-items: center; gap: 10px; }
.explain { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.explain li::marker { color: var(--border); }

/* ---------- стакан ---------- */
.ob-head, .ob-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 3px 8px; }
.ob-head { font-size: 11px; color: var(--muted); }
.ob-row { position: relative; font-size: 12px; font-family: var(--mono); }
.ob-row .fill { position: absolute; right: 0; top: 0; bottom: 0; border-radius: 3px; opacity: .14; }
.ob-row span { position: relative; }
.ob-row span:last-child { text-align: right; }
.ob-mid { padding: 6px 8px; font-size: 15px; font-weight: 700; color: var(--green); font-family: var(--mono); }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
td { padding: 12px; border-top: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
td.num, th.num { text-align: right; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); font-size: 13px; }
.list-row .right { margin-left: auto; font-family: var(--mono); font-weight: 700; }

/* ---------- модальное окно и уведомления ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(5,7,11,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 18px; }
.modal .buttons { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }
.toast.error { border-color: rgba(246,70,93,.6); color: var(--red-text); }

.bottom-nav { display: none; }
.more-list { display: flex; flex-direction: column; gap: 8px; }
.more-list .nav-link { background: var(--surface); border: 1px solid var(--border); color: var(--text); }

/* ---------- телефон ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); gap: 14px; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; border-top: 1px solid var(--border); background: var(--surface);
    padding-bottom: env(safe-area-inset-bottom); z-index: 40; }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0 10px; text-decoration: none; font-size: 11px; color: var(--muted); min-height: 56px; }
  .bottom-nav a[aria-current="page"] { color: var(--accent); }
  .page-head h1 { font-size: 20px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .stat .value { font-size: 22px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .chart { height: 260px; }
  .card { padding: 16px; }
  .grow-3, .grow-1, .grow-half { flex-basis: 100%; }
  .hide-phone { display: none !important; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) {
  .stat .value { font-size: 18px; }
  .stat .value .small { display: none; }
  .stat .label, .stat .extra { font-size: 12px; }
}

/* ---------- защита (этап 4) ---------- */
.status-pill.halted { background: rgba(246,70,93,.12); color: var(--red-text); }
.status-pill.halted .dot { background: var(--red); }
.risk-card { margin-top: 10px; padding: 14px 18px; }
.risk-row { display: flex; flex-wrap: wrap; gap: 14px 28px; }
.risk-item { flex: 1 1 220px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.legend .l-entry { border-top: 2px solid #4C8DFF; }
.legend .l-trail { border-top: 2px dotted rgba(246,70,93,.6); }
tr.sub-row td { border-top: 0; padding-top: 0; }
.legend .l-liq { border-top: 2px dashed var(--red-text); }
