/* TradeSam — тёмная тема по умолчанию, светлая по кнопке. Все размеры в rem: масштаб задаёт html. */
:root {
  --bg: #0b0f14; --bg-2: #0f141b; --side: #0d1218; --panel: #131a22; --panel-2: #1a2330; --line: #233042;
  --text: #e8eef5; --muted: #8a99ab; --faint: #5d6b7c;
  --accent: #19c3a3; --accent-ink: #04211b; --accent-soft: rgba(25, 195, 163, .14);
  --green: #2fd17f; --green-bg: rgba(47, 209, 127, .13); --red: #ff5d68; --red-bg: rgba(255, 93, 104, .13);
  --yellow: #f2b544; --yellow-bg: rgba(242, 181, 68, .14); --blue: #5aa9ff;
  --log-bg: #0a0e13; --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 8px 24px rgba(0, 0, 0, .25);
  --radius: 14px; color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5f8; --bg-2: #eef1f5; --side: #ffffff; --panel: #ffffff; --panel-2: #f1f4f8; --line: #dfe5ec;
  --text: #121a24; --muted: #5f6e80; --faint: #98a4b3;
  --accent: #0a9e84; --accent-ink: #ffffff; --accent-soft: rgba(10, 158, 132, .1);
  --green: #149c5a; --green-bg: rgba(20, 156, 90, .1); --red: #d63a46; --red-bg: rgba(214, 58, 70, .09);
  --yellow: #b07b0c; --yellow-bg: rgba(176, 123, 12, .11); --blue: #1e6fd9;
  --log-bg: #f7f9fb; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 18px rgba(16, 24, 40, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { font-size: 17px; }
@media (min-width: 1500px) { html { font-size: 18px; } }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 1rem/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .7rem; font-weight: 650; }
.muted { color: var(--muted); font-size: .88rem; }
.small { font-size: .85rem; margin: -.35rem 0 .7rem; }
.sub { color: var(--muted); margin: .3rem 0 0; font-size: .95rem; max-width: 60rem; }
svg.i { width: 1.15rem; height: 1.15rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 16.5rem minmax(0, 1fr); min-height: 100vh; }
.side, .nav, .content > * { min-width: 0; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 1.1rem .8rem;
  position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 800; font-size: 1.2rem; padding: .2rem .5rem 1.2rem; letter-spacing: -.01em; }
.brand.big { font-size: 1.6rem; justify-content: center; padding: 0 0 1.4rem; }
.logo { display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: .65rem;
  background: linear-gradient(135deg, var(--accent), #0e7f9a); color: #fff; font-size: .8rem; font-weight: 800; }
.brand.big .logo { width: 2.8rem; height: 2.8rem; font-size: 1rem; }
.live { width: .6rem; height: .6rem; border-radius: 50%; background: var(--faint); margin-left: auto; }
.live.on { background: var(--green); box-shadow: 0 0 0 .3rem var(--green-bg); } .live.off { background: var(--red); }
.nav { display: flex; flex-direction: column; gap: .15rem; }
.nav-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: .9rem .75rem .35rem; }
.nav button { display: flex; align-items: center; gap: .75rem; background: none; border: 0; color: var(--muted); padding: .62rem .75rem;
  border-radius: .7rem; font: inherit; font-size: .97rem; cursor: pointer; text-align: left; }
.nav button:hover { background: var(--panel-2); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav button.active svg.i { color: var(--accent); }
.badge { margin-left: auto; font-size: .75rem; font-weight: 600; background: var(--panel-2); border-radius: 999px; padding: .05rem .5rem; color: var(--text); }
.badge:empty { display: none; }
.side-foot { margin-top: auto; display: flex; gap: .5rem; padding: .5rem; }
.side-foot form { margin: 0; flex: 1; display: flex; }
.foot-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: .45rem; height: 2.4rem; border-radius: .7rem;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; font: inherit; font-size: .88rem; }
.foot-btn:hover { color: var(--text); }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 1.4rem; padding: .7rem 2rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tb-item { display: flex; flex-direction: column; line-height: 1.2; }
.tb-item .k { font-size: .74rem; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.tb-item .v { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tb-spacer { flex: 1; }
.content { padding: 1.6rem 2rem 3rem; max-width: 84rem; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.3rem; }
.tab { display: none; } .tab.active { display: block; }

.pill { font-size: .82rem; font-weight: 600; padding: .25rem .75rem; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--green-bg); color: var(--green); } .pill.bad { background: var(--red-bg); color: var(--red); }
.pill.warn { background: var(--yellow-bg); color: var(--yellow); }

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr)); align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.grid > .card { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .55rem; gap: .8rem; }
.card-head h2 { margin: 0; }

.status-line { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.dot { width: .85rem; height: .85rem; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 .35rem var(--green-bg); } .dot.off { background: var(--red); } .dot.wait { background: var(--yellow); }
.state { font-size: 1.3rem; font-weight: 700; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }

.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: .65rem 1rem; border-radius: .7rem;
  font: inherit; font-weight: 600; cursor: pointer; transition: filter .12s; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--red); }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); }
.kpi .k { color: var(--muted); font-size: .85rem; } .kpi .v { font-size: 1.55rem; font-weight: 750; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); } .neg { color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: .55rem; }
.chip { background: var(--panel-2); border-radius: 999px; padding: .32rem .85rem; font-size: .88rem; }
.chip.good { background: var(--green-bg); color: var(--green); } .chip.warn { background: var(--yellow-bg); color: var(--yellow); }

.side-tag { display: inline-block; font-size: .76rem; font-weight: 750; padding: .1rem .5rem; border-radius: .4rem; letter-spacing: .02em; }
.side-tag.long { background: var(--green-bg); color: var(--green); } .side-tag.short { background: var(--red-bg); color: var(--red); }

.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 1fr auto; gap: .3rem 1rem; padding: .85rem 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; padding-top: .1rem; }
.row .title { font-weight: 650; display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
.row .meta { color: var(--muted); font-size: .88rem; }
.row .right { text-align: right; font-variant-numeric: tabular-nums; }
.plan { grid-column: 1 / -1; font-size: .9rem; color: var(--text); background: var(--panel-2); border-radius: .6rem; padding: .45rem .75rem;
  border-left: 3px solid var(--accent); }
.empty { color: var(--muted); padding: .4rem 0; }
.bars { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.bar { height: .35rem; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.bar.near i { background: var(--faint); } .bar.near.hot i { background: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: .95rem; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-weight: 550; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
td { padding: .65rem .6rem; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:hover td { background: color-mix(in srgb, var(--panel-2) 55%, transparent); }
.tbl { overflow-x: auto; }

.rule { display: flex; gap: .7rem; padding: .45rem 0; } .rule b { color: var(--accent); }
.ev { padding: .7rem 0; border-top: 1px solid var(--line); white-space: pre-wrap; font-size: .95rem; }
.ev:first-child { border-top: 0; padding-top: 0; } .ev .t { color: var(--faint); font-size: .8rem; display: block; }

.log { font: .84rem/1.55 ui-monospace, "JetBrains Mono", Consolas, monospace; background: var(--log-bg); border: 1px solid var(--line); border-radius: .8rem;
  padding: .8rem 1rem; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.log.full { height: calc(100vh - 15rem); min-height: 20rem; }
.log .row { display: block; padding: 1px 0; border: 0; } .log .t { color: var(--faint); margin-right: .6rem; }
.log .row.err { color: var(--red); } .log .row.warn { color: var(--yellow); }
.log-tools { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; margin-bottom: .8rem; }
.log-tools input[type=search] { flex: 1 1 16rem; }
.check { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .95rem; cursor: pointer; white-space: nowrap; }
.check input { width: 1rem; height: 1rem; accent-color: var(--accent); }

input[type=text], input[type=password], input[type=search] { width: 100%; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: .65rem; padding: .65rem .85rem; font: inherit; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.section h2 { margin-bottom: .9rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 0 1.6rem; }
.field { padding: .8rem 0; border-top: 1px solid var(--line); }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field .key { color: var(--faint); font: .75rem ui-monospace, Consolas, monospace; margin-left: .45rem; font-weight: 400; }
.field .help { color: var(--muted); font-size: .86rem; margin-bottom: .4rem; }
.field.changed input { border-color: var(--yellow); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.switch { position: relative; width: 2.9rem; height: 1.65rem; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 1.15rem; height: 1.15rem; left: .2rem; top: .2rem; background: var(--faint); border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(1.22rem); background: #fff; }
.save-bar { position: sticky; bottom: 0; display: flex; gap: .6rem; justify-content: flex-end; padding: .9rem 0; background: linear-gradient(transparent, var(--bg) 35%); }

.coin-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--accent); cursor: pointer;
  text-decoration: underline dotted; text-underline-offset: 3px; }
.modal { position: fixed; inset: 0; background: rgba(4, 7, 11, .62); display: grid; place-items: center; z-index: 30; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-box { width: min(72rem, 100%); max-height: calc(100vh - 2rem); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 1rem; padding: 1.2rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .8rem; margin-bottom: .7rem; }
.modal-head h2 { margin: 0; font-size: 1.3rem; display: flex; gap: .6rem; align-items: center; }
.icon-btn { width: 2.3rem; height: 2.3rem; border-radius: .65rem; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 1rem; }
#chart { height: 30rem; border-radius: .8rem; overflow: hidden; background: var(--log-bg); }
#chart .loading { display: grid; place-items: center; height: 100%; color: var(--muted); }
.fills { margin-top: .9rem; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .7rem; font-size: .88rem; color: var(--muted); }
.legend i { display: inline-block; width: 1.2rem; height: 0; border-top: 2px dashed; vertical-align: middle; margin-right: .4rem; }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--line);
  padding: .7rem 1.1rem; border-radius: .8rem; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 2rem); z-index: 40; }
.toast.show { opacity: 1; transform: translateX(-50%); } .toast.bad { border-color: var(--red); color: var(--red); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(60rem 30rem at 50% -10%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 24rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1.1rem; padding: 2rem 1.6rem;
  display: grid; gap: .7rem; box-shadow: var(--shadow); }
.login-card label { color: var(--muted); font-size: .95rem; } .login-card .btn { margin-top: .4rem; } .err { color: var(--red); font-size: .95rem; }

/* ---------- телефон ---------- */
@media (max-width: 860px) {
  html { font-size: 16px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .grid.two > * { min-width: 0; }
  .side { position: sticky; top: 0; z-index: 7; height: auto; flex-direction: row; align-items: center; gap: .5rem; padding: .5rem .6rem;
    padding-top: calc(.5rem + env(safe-area-inset-top)); border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 .2rem; font-size: 0; gap: 0; } .brand .logo { font-size: .75rem; } .live { margin-left: .4rem; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; scrollbar-width: none; } .nav::-webkit-scrollbar { display: none; }
  .nav-label { display: none; }
  .nav button { white-space: nowrap; padding: .5rem .7rem; } .nav svg.i { display: none; }
  .side-foot { margin: 0; padding: 0; } .foot-btn span { display: none; } .foot-btn { width: 2.3rem; flex: none; }
  .topbar { position: static; padding: .6rem 1rem; gap: .9rem; }
  .content { padding: 1rem 1rem 3rem; }
  h1 { font-size: 1.45rem; }
  .grid.two { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .actions { grid-template-columns: 1fr 1fr; } .actions .btn.primary { grid-column: 1 / -1; }
  .save-bar { flex-direction: column-reverse; } .save-bar .btn { width: 100%; }
  .modal { padding: 0; } .modal-box { max-height: 100vh; height: 100vh; border-radius: 0; } #chart { height: 55vh; }
  .fields { grid-template-columns: 1fr; }
}
