/* Курсы P2P: тёплая светлая тема, графитовая тёмная, терракотовый акцент. */
:root {
  --bg: #f1ece4;
  --bg-glow: #f7efe4;
  --panel: #faf7f2;
  --panel-2: #f4efe7;
  --border: #e6ded2;
  --rule: #e6ded2;
  --rule-2: #eee8de;
  --ink: #1d1a16;
  --ink-2: #6f675d;
  --ink-3: #a0978b;
  --accent: #b0532a;
  --accent-ink: #ffffff;
  --accent-soft: #f2e0d2;
  --ref: #b0532a;
  --nav-active: #f3e2d4;
  --info-bg: #e4e8ed;
  --info-ink: #3d5068;
  --up: #2f7d4c;
  --down: #b3402f;
  --warn: #a8761c;
  --shadow: 0 1px 2px rgba(70, 45, 20, .05), 0 6px 24px rgba(70, 45, 20, .04);
  --focus: #b0532a;
  --btn-bg: #ffffff;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121315; --bg-glow: #121315; --panel: #1b1c1f; --panel-2: #222327; --border: #2b2c31; --rule: #2b2c31; --rule-2: #25262a;
  --ink: #ececec; --ink-2: #9d9da3; --ink-3: #6c6c72; --accent: #e08a5a; --accent-ink: #1b1c1f; --accent-soft: #3a2a22;
  --ref: #e0a04a; --nav-active: #2a2b30; --info-bg: #263040; --info-ink: #a9bbd4; --up: #62c58a; --down: #ee7b6c; --warn: #e2b04a;
  --shadow: none; --focus: #e08a5a; --btn-bg: #222327; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315; --bg-glow: #121315; --panel: #1b1c1f; --panel-2: #222327; --border: #2b2c31; --rule: #2b2c31; --rule-2: #25262a;
    --ink: #ececec; --ink-2: #9d9da3; --ink-3: #6c6c72; --accent: #e08a5a; --accent-ink: #1b1c1f; --accent-soft: #3a2a22;
    --ref: #e0a04a; --nav-active: #2a2b30; --info-bg: #263040; --info-ink: #a9bbd4; --up: #62c58a; --down: #ee7b6c; --warn: #e2b04a;
    --shadow: none; --focus: #e08a5a; --btn-bg: #222327; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; color: var(--ink); background: var(--bg); }
body {
  font-family: "Manrope Variable", system-ui, sans-serif; font-size: 14px; line-height: 1.5; font-weight: 500;
  font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased; min-height: 100vh;
  background: radial-gradient(ellipse 70% 60% at 55% 40%, var(--bg-glow), var(--bg) 70%) fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 40px; line-height: 1.1; margin: 0; font-weight: 800; letter-spacing: -.035em; }
h2 { font-size: 19px; margin: 0; font-weight: 750; letter-spacing: -.015em; }
h3 { font-size: 15px; margin: 22px 0 10px; font-weight: 750; }
h3:first-child { margin-top: 0; }
p { margin: 0 0 10px; max-width: 76ch; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
pre { background: var(--panel-2); padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.grow { flex: 1; }
.muted, .sub { color: var(--ink-2); }
.sub { font-size: 12.5px; }
.r { text-align: right; }
.err { color: var(--down); font-size: 13.5px; }
.ok { color: var(--up); }
.up { color: var(--up); }
.down { color: var(--down); }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); gap: 14px; padding: 14px; min-height: 100vh; }
.side {
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding: 18px 12px 12px; position: sticky; top: 14px; height: calc(100vh - 28px);
}
.logo { display: flex; align-items: center; gap: 9px; padding: 0 12px 22px; text-decoration: none; color: var(--ink); }
.logo svg { width: 30px; height: 30px; flex: none; }
.logo b { font-size: 23px; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.logo small { display: block; font-size: 11.5px; color: var(--ink-2); font-weight: 600; letter-spacing: 0; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.nav .sec { font-size: 11px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); padding: 14px 12px 6px; }
.nav .sec:first-child { padding-top: 0; }
.nav button {
  display: flex; align-items: center; gap: 12px; border: 0; background: none; text-align: left; cursor: pointer;
  padding: 9px 12px; border-radius: 10px; color: var(--ink); font-weight: 550; position: relative; white-space: nowrap;
}
.nav button .ico { color: var(--ink-2); }
.nav button:hover { background: var(--panel-2); }
.nav button.on { background: var(--nav-active); color: var(--accent); }
.nav button.on .ico { color: var(--accent); }
.nav button.on::before { content: ""; position: absolute; left: -2px; top: 9px; bottom: 9px; width: 3px; border-radius: 2px; background: var(--accent); }
.nav .count { margin-left: auto; font-size: 11.5px; font-weight: 750; background: var(--accent); color: var(--accent-ink); border-radius: 10px; min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 6px; }
.side-foot { border-top: 1px solid var(--border); margin-top: 10px; padding: 12px 6px 2px; display: flex; align-items: center; gap: 4px; }
.side-foot .who { flex: 1; min-width: 0; font-size: 13px; font-weight: 700; line-height: 1.25; }
.side-foot .who small { display: block; color: var(--ink-2); font-weight: 500; font-size: 11.5px; }
.iconbtn { border: 0; background: none; color: var(--ink-2); cursor: pointer; border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center; }
.iconbtn:hover { background: var(--panel-2); color: var(--ink); }

.main-col { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.topbar {
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 36px; padding: 12px 24px 12px 16px; min-height: 68px;
}
.topbar .status { display: flex; gap: 8px; flex-wrap: wrap; }
.kpis { display: flex; gap: 34px; margin-left: auto; }
.kpi .l { font-size: 10.5px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.kpi .v { font-size: 15.5px; font-weight: 800; letter-spacing: -.01em; }
.kpi .v small { font-size: 11px; font-weight: 600; color: var(--ink-2); margin-left: 3px; letter-spacing: 0; }

main { padding: 18px 8px 40px; }
.view { display: none; }
.view.on { display: block; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .t { flex: 1; min-width: 0; }
.eyebrow { display: flex; align-items: center; gap: 10px; font-size: 11.5px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.eyebrow::before { content: ""; width: 18px; height: 1.5px; background: currentColor; }
.lede { color: var(--ink-2); margin-top: 8px; font-size: 13.5px; }

.sheet { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
.sheet.pad { padding: 22px 24px; margin-bottom: 16px; }
.sheet.scroll { overflow-x: auto; }
.hint { color: var(--ink-2); font-size: 12.5px; margin: 12px 4px 0; max-width: 90ch; }
.empty { padding: 40px 26px; color: var(--ink-2); max-width: 64ch; }
.empty b { color: var(--ink); display: block; font-size: 16px; margin-bottom: 4px; }

/* ---------- плашки ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 7px; background: var(--info-bg); color: var(--info-ink); white-space: nowrap; }
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.ref { background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: color-mix(in srgb, var(--up) 14%, transparent); color: var(--up); }
.pill.bad { background: color-mix(in srgb, var(--down) 14%, transparent); color: var(--down); }
.pill.off { background: var(--panel-2); color: var(--ink-2); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--btn-bg);
  padding: 8px 16px; border-radius: 12px; cursor: pointer; font-weight: 700; white-space: nowrap; min-height: 40px;
  box-shadow: 0 1px 2px rgba(70, 45, 20, .06);
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { border: 0; background: none; padding: 2px 0; cursor: pointer; color: var(--ink-2); font-size: 12.5px; font-weight: 650; }
.link:hover { color: var(--accent); }
.link.danger:hover { color: var(--down); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  border: 1px solid var(--border); background: var(--btn-bg); padding: 6px 13px; min-height: 36px; cursor: pointer;
  color: var(--ink); font-weight: 600; white-space: nowrap; border-radius: 10px;
}
.seg button:hover { border-color: var(--ink-3); }
.seg button.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); color: var(--accent); }
.seg button.on.buy { background: color-mix(in srgb, var(--up) 14%, transparent); border-color: var(--up); color: var(--up); }
.seg button.on.sell { background: color-mix(in srgb, var(--down) 12%, transparent); border-color: var(--down); color: var(--down); }

/* ---------- формы ---------- */
.row { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 16px; }
.row.wrap { flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.field em { font-style: normal; color: var(--ink-3); font-weight: 500; }
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), select {
  border: 1px solid var(--border); background: var(--btn-bg); border-radius: 10px; padding: 7px 12px; min-height: 38px; font-weight: 550;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; border-color: transparent; }
input[type=color] { width: 46px; height: 38px; border: 1px solid var(--border); border-radius: 10px; padding: 3px; background: var(--btn-bg); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 38px; font-weight: 550; }
.check input, .picklist input, .paylist input { width: 16px; height: 16px; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; cursor: pointer; background: var(--btn-bg); user-select: none; font-size: 13px; font-weight: 600; }
.chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); color: var(--accent); }
.chip .x { color: var(--ink-3); }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ---------- табло ---------- */
.board { list-style: none; margin: 0; padding: 6px 24px; }
.board li {
  display: grid; grid-template-columns: minmax(340px, 1fr) 130px 120px 180px 140px 130px;
  align-items: center; gap: 20px; padding: 18px 0; border-top: 1px solid var(--rule-2);
}
.board li:first-child { border-top: 0; }
.board .name { font-weight: 750; font-size: 15px; display: flex; align-items: baseline; gap: 9px; }
.board .name .sw { transform: translateY(-1px); }
.board .params { color: var(--ink-2); font-size: 12.5px; margin-top: 3px; }
.board .acts { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.board .rate { font-size: 28px; font-weight: 800; letter-spacing: -.025em; text-align: right; line-height: 1.1; }
.board li.ref .rate { color: var(--ref); }
.board .rate small { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-2); letter-spacing: 0; margin-top: 4px; }
.board .delta { text-align: right; font-size: 14px; font-weight: 750; }
.board .delta small { display: block; font-size: 11.5px; font-weight: 550; color: var(--ink-2); }
.board .spark { width: 180px; height: 46px; display: block; }
.board .spark path { fill: none; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.board .state { font-size: 12.5px; color: var(--ink-2); }
.board .state .bad { color: var(--down); font-weight: 650; }
.board .rec { justify-self: end; }
.board li.off { opacity: .6; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { width: 32px; height: 19px; background: var(--rule); border-radius: 10px; position: relative; transition: background .15s; flex: none; }
.switch i::before { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--up); }
.switch input:checked + i::before { transform: translateX(13px); }
.switch input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- таблицы ---------- */
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 11px; color: var(--ink-2); font-weight: 750; letter-spacing: .07em; text-transform: uppercase; padding: 14px 16px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.grid th.r { text-align: right; }
.grid td { padding: 13px 16px; border-bottom: 1px solid var(--rule-2); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.big-num { font-size: 18px; font-weight: 800; letter-spacing: -.015em; }

/* ---------- график ---------- */
.chart-layout { display: grid; grid-template-columns: 290px 1fr; gap: 14px; align-items: start; }
.picklist { padding: 8px; max-height: 72vh; overflow: auto; }
.picklist label { display: grid; grid-template-columns: 16px 9px 1fr auto; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.picklist label:hover { background: var(--panel-2); }
.picklist .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.picklist .nm.ref { color: var(--ref); }
.picklist .v { font-size: 12.5px; color: var(--ink-2); font-weight: 700; }
.chart-card { padding: 16px 18px; min-width: 0; }
.custom-range { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.custom-range input { min-height: 34px !important; padding: 3px 10px !important; }
#chart { min-height: 420px; }
.uplot { font-family: inherit; }
.u-legend { font-size: 12.5px; text-align: left; margin-top: 6px; font-weight: 600; }
.u-legend .u-marker { border-radius: 50%; width: 9px !important; height: 9px !important; margin-top: 4px; }
.u-tip {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none; min-width: 220px; max-width: 360px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(20, 12, 4, .18); font-size: 12.5px;
}
.u-tip .t { font-weight: 750; margin-bottom: 6px; }
.u-tip .tr { display: grid; grid-template-columns: 9px 1fr auto; gap: 8px; align-items: center; padding: 2px 0; }
.u-tip .n { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-tip b { font-weight: 800; font-size: 13.5px; }
.u-select { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- «если бы» ---------- */
.wi-table td.ref { background: var(--accent-soft); }
.wi-table td.ref .big-num { color: var(--ref); }
.wi-table .diff { font-size: 12.5px; font-weight: 650; }
.cov { font-size: 12px; color: var(--warn); font-weight: 600; }
.wi-foot { display: flex; gap: 14px; align-items: center; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; padding: 0 4px; }
.note { background: var(--accent-soft); color: var(--ink); border-radius: 12px; padding: 11px 16px; font-size: 13px; margin: 0 0 14px; font-weight: 550; }
.formula { color: var(--ink-2); font-size: 13px; margin: 4px 0 0; max-width: 100ch; }

/* ---------- диалоги ---------- */
dialog { border: 1px solid var(--border); padding: 0; border-radius: 20px; background: var(--panel); color: var(--ink); width: min(940px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 30px 80px rgba(40, 25, 10, .25); }
dialog::backdrop { background: rgba(30, 22, 14, .45); backdrop-filter: blur(2px); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 26px; border-bottom: 1px solid var(--border); }
.dlg-head .x { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--ink-2); padding: 0 4px; }
.dlg-body { padding: 20px 26px; overflow: auto; }
.dlg-foot { display: flex; align-items: center; gap: 10px; padding: 14px 26px; border-top: 1px solid var(--border); }
#snap { width: min(1000px, calc(100vw - 24px)); }
#snap .dlg-body { max-height: 75vh; }
.paybox { border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 10px; background: var(--panel-2); }
.paybox > input { width: 100%; }
.paylist { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1px 10px; max-height: 170px; overflow: auto; }
.paylist label { display: flex; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 550; }
.paylist label:hover { background: var(--panel); }
.preview { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 18px; }
.preview .headline { display: flex; gap: 36px; align-items: baseline; flex-wrap: wrap; margin-bottom: 12px; }
.preview .headline .v { font-size: 32px; font-weight: 800; letter-spacing: -.03em; color: var(--accent); }
.preview .grid td, .preview .grid th, #snap .grid td, #snap .grid th { padding: 7px 10px; font-size: 13px; }
.preview .grid th, #snap .grid th { font-size: 10.5px; }
.preview .grid, #snap .grid { min-width: 720px; }
tr.used td { background: var(--accent-soft); }
tr.used td:first-child { font-weight: 800; color: var(--accent); }
tr.skipped td { color: var(--ink-3); }
tr.skipped td:first-child { text-decoration: line-through; }
.badge { font-size: 11px; font-weight: 650; color: var(--info-ink); background: var(--info-bg); border-radius: 5px; padding: 1px 6px; margin-left: 5px; white-space: nowrap; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 11px 18px; border-radius: 12px; z-index: 50; box-shadow: 0 12px 30px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px); font-weight: 600; }
.toast.bad { background: var(--down); color: #fff; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); }
.login .logo { padding: 0 0 24px; }
.login .field { margin-bottom: 14px; }
.login input { width: 100%; }
.login .btn { width: 100%; justify-content: center; }
.login .err { min-height: 20px; margin: 12px 0 0; }

@media (max-width: 1360px) {
  .board li { grid-template-columns: minmax(300px, 1fr) 120px 110px 150px 130px; }
  .board .spark { width: 150px; }
  .board .state { display: none; }
  .kpis { gap: 24px; }
}
@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: 10px; gap: 10px; }
  .side-foot .who { display: none; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .nav { order: 3; width: 100%; }
  .side-foot { margin-left: auto; }
  .side { position: static; height: auto; padding: 14px 10px 10px; border-radius: 16px; }
  .logo { padding-bottom: 10px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav .sec { display: none; }
  .nav button.on::before { display: none; }
  .side-foot { border-top: 0; margin-top: 0; padding: 0; }
  .topbar { flex-wrap: wrap; gap: 12px 24px; border-radius: 16px; }
  .kpis { margin-left: 0; flex-wrap: wrap; gap: 14px 24px; }
  main { padding: 10px 2px 40px; }
  h1 { font-size: 32px; }
  .board { padding: 4px 16px; }
  .board li { grid-template-columns: 1fr auto; gap: 8px 14px; }
  .board li > div:first-child { grid-column: 1 / -1; }
  .board .delta, .board .spark-wrap, .board .state { display: none; }
  .board .rate { text-align: left; }
  .chart-layout { grid-template-columns: 1fr; }
  .picklist { max-height: 210px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
