:root {
    --bg: #f3f5f8;
    --card: #ffffff;
    --ink: #142033;
    --ink-2: #44526a;
    --muted: #7a879b;
    --line: #e3e8ef;
    --line-2: #eef1f5;
    --brand: #0f2a44;
    --brand-2: #163a5c;
    --accent: #0e9f8e;
    --accent-ink: #0b7d70;
    --primary: #1f4fd1;
    --primary-ink: #173fae;
    --orange: #c86a05; --orange-bg: #fff3e2;
    --blue: #1f5fd6;   --blue-bg: #e8f0ff;
    --green: #13894a;  --green-bg: #e4f6ec;
    --red: #c8312f;    --red-bg: #fdeceb;
    --grey: #5f6b7d;   --grey-bg: #eef1f5;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 32, 51, .06), 0 1px 1px rgba(16, 32, 51, .03);
    --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 13.5px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; cursor: pointer; }
h1 { font-size: 22px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; letter-spacing: -.005em; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
p { margin: 0 0 10px; }
code { font-family: var(--mono); font-size: 12px; background: var(--line-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .tiny { font-size: 11px; } .big { font-size: 16px; font-weight: 650; }
.pos { color: var(--green); } .neg { color: var(--red); }
.lead { color: var(--ink-2); font-size: 14px; }
.row { display: flex; align-items: center; flex-wrap: wrap; } .gap { gap: 12px; } .gap-s { gap: 8px; } .grow { flex: 1; }
.pad { padding: 20px; } .pad-s { padding: 8px 14px; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- layout */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }
.side { background: var(--brand); color: #c9d6e6; display: flex; flex-direction: column; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; }
.brand b { display: block; color: #fff; font-size: 13.5px; } .brand small { display: block; color: #8ea3bb; font-size: 11px; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, #14b8a6, #0e7c86); color: #fff; font-weight: 800; font-size: 12px; display: grid; place-items: center; letter-spacing: .02em; flex: none; }
.brand.big .logo { width: 44px; height: 44px; font-size: 14px; }
.brand.big b { color: var(--ink); font-size: 16px; } .brand.big small { color: var(--muted); font-size: 12px; }
nav { padding: 4px 10px 14px; flex: 1; }
.nav-group { margin-top: 10px; }
.nav-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #6f86a1; padding: 6px 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 7px; color: #c9d6e6; font-weight: 500; }
.nav-item:hover { background: var(--brand-2); color: #fff; }
.nav-item.active { background: #1e4a73; color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }
.nav-item .ico { width: 18px; text-align: center; opacity: .8; font-size: 13px; }
.nav-badge { margin-left: auto; background: #f59e0b; color: #1b1300; font-size: 10.5px; font-weight: 700; border-radius: 10px; padding: 0 7px; line-height: 18px; }
.side-foot { padding: 14px 16px 18px; border-top: 1px solid #1d3d5e; }
.side-foot select { width: 100%; margin: 4px 0 6px; background: #12324f; color: #fff; border-color: #2a4d70; }
.side-foot .tiny { color: #7f95ae; margin: 0; }
.me b { color: #fff; display: block; } .me small { color: #8ea3bb; display: block; margin-bottom: 8px; }
.side .btn.ghost { color: #c9d6e6; border-color: #2a4d70; background: transparent; }
.main { overflow-y: auto; padding: 24px 28px 60px; }
#page { max-width: 1480px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.page-head p { margin: 0; max-width: 760px; }

/* ---------- cards / kpis */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.card > header { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card > header h2 { display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 18px; }
.grid-2 > .card { margin-bottom: 0; } .grid-2 { margin-bottom: 18px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpis.small { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow); position: relative; }
.kpi::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--line); }
.kpi.tone-orange::before { background: var(--orange); } .kpi.tone-blue::before { background: var(--blue); } .kpi.tone-green::before { background: var(--green); } .kpi.tone-red::before { background: var(--red); }
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; display: flex; align-items: center; gap: 6px; }
.kpis.small .kpi-value { font-size: 18px; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.warn-dot { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--orange-bg); color: var(--orange); font-size: 11px; font-weight: 800; }
.empty-state { text-align: left; max-width: 760px; }

/* ---------- filters / segs */
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin-bottom: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.filters label.check { flex-direction: row; align-items: center; text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--ink-2); gap: 6px; padding-bottom: 6px; }
.filters select, .filters input[type=date] { min-width: 120px; }
.segs { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--line-2); padding: 3px; border-radius: 8px; }
.seg { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; font: inherit; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.seg b { font-weight: 600; color: var(--muted); margin-left: 3px; }
.seg.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.tabs { margin-bottom: 14px; }

/* ---------- alerts / chips / badges */
.alerts { display: grid; gap: 8px; margin-bottom: 16px; }
.alert { padding: 9px 13px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; display: block; color: var(--ink); margin-bottom: 10px; }
.alerts .alert { margin: 0; }
a.alert:hover { filter: brightness(.98); }
.alert.tone-orange { background: var(--orange-bg); border-color: #f6d9b0; } .alert.tone-blue { background: var(--blue-bg); border-color: #c9d9fb; }
.alert.tone-red { background: var(--red-bg); border-color: #f5c6c4; } .alert.tone-green { background: var(--green-bg); } .alert.tone-grey { background: var(--grey-bg); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tone-orange.chip, .badge.tone-orange { color: var(--orange); background: var(--orange-bg); }
.tone-blue.chip, .badge.tone-blue { color: var(--blue); background: var(--blue-bg); }
.tone-green.chip, .badge.tone-green { color: var(--green); background: var(--green-bg); }
.tone-red.chip, .badge.tone-red { color: var(--red); background: var(--red-bg); }
.tone-grey.chip, .badge.tone-grey, .badge.tone-undefined { color: var(--grey); background: var(--grey-bg); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.tone-bg-orange { background: var(--orange); } .tone-bg-blue { background: var(--blue); } .tone-bg-green { background: var(--green); } .tone-bg-red { background: var(--red); } .tone-bg-, .tone-bg-grey { background: var(--grey); }
.sd.buy, .sd.sell { font-weight: 700; font-size: 11.5px; padding: 1px 6px; border-radius: 4px; }
span.buy, .sd.buy { color: var(--green); background: var(--green-bg); } span.sell, .sd.sell { color: var(--red); background: var(--red-bg); }

/* ---------- tables */
.tbl-bar { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line-2); }
.tbl-search { width: 220px; }
.tbl-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 12px; background: #fafbfd; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; position: sticky; top: 0; }
th:hover { color: var(--ink-2); }
td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; vertical-align: top; }
td.wrap { white-space: normal; min-width: 180px; max-width: 360px; }
.num { text-align: right; }
tbody tr:hover { background: #f8fafc; }
tr.click { cursor: pointer; }
tfoot td { font-weight: 700; background: #fafbfd; border-top: 1px solid var(--line); }
td.empty { text-align: center; color: var(--muted); padding: 22px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 8px 14px; }
.lvl { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.lvl-bar { flex: 1; height: 6px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.lvl-bar i { display: block; height: 100%; border-radius: 4px; }
.lvl span { font-weight: 600; width: 46px; text-align: right; }
table.mini { width: auto; margin: 6px 0 14px; }
table.mini.full { width: 100%; }
table.mini th { background: none; position: static; cursor: default; text-transform: none; letter-spacing: 0; font-size: 12px; padding: 5px 10px 5px 0; }
table.mini td { padding: 5px 14px 5px 0; }

/* ---------- forms */
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfd7e2; border-radius: 7px; padding: 6px 9px; min-height: 32px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 79, 209, .14); }
input[readonly] { background: var(--line-2); color: var(--ink-2); }
textarea { resize: vertical; width: 100%; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 7px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; min-height: 34px; }
.btn.sm { padding: 3px 10px; min-height: 28px; font-size: 12.5px; }
.btn.primary { background: var(--primary); color: #fff; } .btn.primary:hover { background: var(--primary-ink); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: #fff; border-color: #cfd7e2; color: var(--ink); } .btn.ghost:hover { background: var(--line-2); }
.btn.danger-text { color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.file { position: relative; }
.icon-btn { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--line-2); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field input, .field select { width: 100%; }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--red); background: #fffafa; }
.ferr { color: var(--red); font-size: 12px; font-weight: 500; }
.req { color: var(--red); font-style: normal; }
.row2 { display: flex; gap: 12px; flex-wrap: wrap; } .row2 > .field { min-width: 140px; } .grow2 { flex: 2; }
.affix { display: flex; } .affix input { border-radius: 7px 0 0 7px; } .affix span { border: 1px solid #cfd7e2; border-left: 0; padding: 6px 9px; border-radius: 0 7px 7px 0; background: var(--line-2); color: var(--muted); }
.form-errors { background: var(--red-bg); border: 1px solid #f5c6c4; color: #8c1d1b; border-radius: 8px; padding: 9px 12px; margin: 4px 0 6px; font-size: 13px; }
.form-errors div + div { margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 4px 0; }
.side-pick { display: flex; gap: 8px; }
.side-pick label { flex: 1; cursor: pointer; }
.side-pick input { position: absolute; opacity: 0; pointer-events: none; }
.side-pick span { display: block; text-align: center; padding: 8px; border-radius: 8px; border: 1.5px solid var(--line); font-weight: 700; background: #fff !important; }
.side-pick input:checked + span.buy { border-color: var(--green); background: var(--green-bg) !important; }
.side-pick input:checked + span.sell { border-color: var(--red); background: var(--red-bg) !important; }
.side-pick input:focus-visible + span { box-shadow: 0 0 0 3px rgba(31, 79, 209, .2); }
.side-pick.wide span { font-weight: 600; }
.fee-box { border: 1px dashed #d6dde8; border-radius: 9px; padding: 12px 12px 0; margin-bottom: 12px; background: #fbfcfe; }

/* ---------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 28, 46, .45); display: grid; place-items: start center; padding: 5vh 16px; z-index: 50; overflow-y: auto; animation: fade .12s ease-out; }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); box-shadow: 0 20px 60px rgba(10, 20, 40, .3); display: flex; flex-direction: column; max-height: 90vh; }
.modal.wide { width: min(960px, 100%); }
.modal > header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.modal > header h2 { font-size: 16px; }
.modal-body { padding: 16px 18px 6px; overflow-y: auto; }
.modal > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line-2); background: #fafbfd; border-radius: 0 0 12px 12px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
.trade-form { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; }
.preview { background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 4px 16px 14px; align-self: start; position: sticky; top: 0; }
.preview h3:first-child { margin-top: 12px; }
.readonly-pair input { background: var(--line-2); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 8px; }
dl.kv dt { color: var(--muted); font-size: 12.5px; } dl.kv dd { margin: 0; }
.detail-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.steps li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 7px; background: var(--line-2); font-size: 12.5px; }
.steps li span { color: var(--muted); }
.steps li.done { background: var(--green-bg); } .steps li.done b::before { content: "✓ "; color: var(--green); }
.steps li.current { background: var(--orange-bg); box-shadow: inset 3px 0 0 var(--orange); }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 220px; overflow-y: auto; }
.history li { border-left: 2px solid var(--line); padding-left: 10px; }
.issues { margin: 6px 0 0; padding-left: 18px; color: #8c1d1b; font-size: 12.5px; }
.issues.long { list-style: none; padding: 0; color: var(--ink); max-height: 300px; overflow-y: auto; display: grid; gap: 4px; }

/* ---------- toast / login */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--brand); color: #fff; padding: 10px 14px; border-radius: 9px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-weight: 500; max-width: 420px; border-left: 4px solid var(--accent); transition: opacity .3s, transform .3s; }
.toast.tone-red { border-left-color: #f87171; } .toast.tone-orange { border-left-color: #fbbf24; } .toast.tone-blue { border-left-color: #60a5fa; }
.toast.out { opacity: 0; transform: translateY(6px); }
.login { grid-column: 1 / -1; display: grid; place-items: center; min-height: 100vh; background: radial-gradient(circle at 20% 10%, #163a5c, var(--brand)); }
.login-card { width: 360px; padding: 26px; }
.login-card .brand { padding: 0 0 18px; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; height: auto; }
    .side { position: static; } nav { display: flex; flex-wrap: wrap; gap: 4px; } .nav-group { margin: 0; } .nav-title { display: none; }
    .main { padding: 16px; overflow: visible; }
    .trade-form { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media print { .side, .filters, .tbl-bar, .page-head .btn { display: none; } .app { display: block; } .card { break-inside: avoid; } }
