:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2230;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --red: #e5534b;
  --green: #3fb950;
  --yellow: #d29922;
  --blue: #58a6ff;
  --tag: #30363d;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 var(--mono); }
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.on { background: var(--red); border-color: var(--red); color: #fff; }
button.on.green { background: var(--green); border-color: var(--green); }
#modeSeg button.on { background: var(--blue); border-color: var(--blue); color: #0d1117; }
button.pill { border-radius: 999px; border-color: var(--blue); color: var(--blue); background: transparent; }
button.danger { border-color: var(--red); color: var(--red); background: transparent; }
select, input {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 1px solid var(--blue); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- вход ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px;
  width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { margin: 0 0 4px; font-size: 20px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-box input { color: var(--text); }
.msg { color: var(--red); min-height: 1.4em; margin: 0; }

/* ---------- шапка ---------- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); }
.top .grow { flex: 1; }
.top .hedge { color: var(--muted); }
.top .hedge b { color: var(--text); }
.seg { display: inline-flex; gap: 4px; }
.updated { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.updated.stale { color: var(--yellow); }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: 110%; z-index: 20; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 190px; }
.menu-list button { text-align: left; background: transparent; border-color: transparent; }
.menu-list button:hover { background: var(--panel2); }

/* ---------- карточки ног ---------- */
.legs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 12px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head .coin { font-weight: 700; font-size: 16px; }
.card-head .exch { margin-left: auto; color: var(--muted); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--tag); color: var(--muted); }
.tag.short { background: var(--red); color: #fff; font-weight: 700; }
.tag.long { background: var(--green); color: #fff; font-weight: 700; }
.tag.warn { background: var(--yellow); color: #000; }
.rows { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.rows .k { color: var(--muted); }
.rows .v { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- график ---------- */
.chart-wrap { margin: 10px 12px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  position: relative; height: calc(100vh - 330px); min-height: 320px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.legend { position: absolute; left: 8px; top: 6px; z-index: 2; display: flex; flex-direction: column; gap: 2px;
  pointer-events: none; font-size: 12px; background: rgba(22,27,34,.8); border-radius: 6px; padding: 3px 6px;
  max-width: calc(100% - 90px); }
.legend .note { color: var(--muted); }
.tip { position: absolute; z-index: 3; pointer-events: none; background: rgba(13,17,23,.92); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted);
  pointer-events: none; }

/* ---------- окна ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 18px;
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
.form { display: grid; grid-template-columns: 140px 1fr; gap: 8px 10px; align-items: center; }
.form label { color: var(--muted); }
.form .full { grid-column: 1 / -1; }
.form .hint { grid-column: 2; color: var(--muted); font-size: 12px; margin-top: -4px; }
.leg-pick { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 6px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list .item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel2); border-radius: 6px;
  flex-wrap: wrap; }
.list .item .name { flex: 1; min-width: 120px; }
.secret { background: var(--bg); border: 1px dashed var(--yellow); border-radius: 6px; padding: 8px; margin: 8px 0;
  word-break: break-all; user-select: all; }
.cal-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--line); }

@media (max-width: 760px) {
  .legs { grid-template-columns: 1fr; }
  .chart-wrap { height: 60vh; }
  .top .hedge { flex-basis: 100%; order: 10; }
  .form { grid-template-columns: 1fr; }
  .form .hint { grid-column: 1; }
}
