/* ============================================================
   HYPER ANALYTICS — дизайн-система «Ink & Amber»
   Терминальный янтарь на глубоком инке: моноширинные данные,
   плавающий док (мобайл) / вертикальный рейл (десктоп),
   bottom-sheets, карточные списки.
   Мобайл-first: базовые правила — телефон, ≥1000px — надстройка.
   Типографика: Archivo (UI) · IBM Plex Mono (данные) · Inter (текст).
   ============================================================ */

:root {
    --bg: #0B0D12;
    --bg-soft: #0E1118;
    --srf: #141824;
    --srf-2: #1B2130;
    --srf-3: #232B3D;
    --line: rgba(233, 238, 255, .08);
    --line-strong: rgba(233, 238, 255, .14);
    --text: #EEF1F8;
    --mut: #8B93A8;
    --mut-2: #5C6478;

    --brand: #F5B942;
    --brand-soft: rgba(245, 185, 66, .14);
    --brand-ink: #191104;

    --up: #3DDBA5;
    --up-soft: rgba(61, 219, 165, .13);
    --down: #FF6B7A;
    --down-soft: rgba(255, 107, 122, .12);
    --info: #7AA5FF;
    --info-soft: rgba(122, 165, 255, .13);
    --warn: #F5B942;

    /* Алиасы для legacy inline-стилей страниц */
    --border: var(--line);
    --surface: var(--srf);
    --surface-2: var(--srf-2);
    --surface-3: var(--srf-3);
    --text-dim: var(--mut);
    --text-faint: var(--mut-2);
    --accent: var(--info);
    --pos: var(--up);
    --pos-text: var(--up);
    --neg: var(--down);
    --neg-text: var(--down);
    --warn-text: var(--warn);
    --mono: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, monospace;

    --r-s: 10px;
    --r-m: 16px;
    --r-l: 22px;

    --font-ui: "Archivo", -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-body: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-data: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, monospace;

    --dock-h: 76px;
    --shadow: 0 18px 50px -12px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14.5px;
    line-height: 1.45;
    overscroll-behavior-y: none;
}
body::before { /* атмосфера: тёплое свечение сверху */
    content: "";
    position: fixed; inset: -30% -20% auto -20%; height: 55vh;
    background: radial-gradient(60% 90% at 50% 0%, rgba(245, 185, 66, .07), transparent 70%);
    pointer-events: none; z-index: 0;
}

a { color: var(--info); text-decoration: none; }
button { font-family: inherit; }
code { font-family: var(--font-data); font-size: .92em; background: var(--srf-2); border-radius: 5px; padding: 1px 5px; }
::selection { background: var(--brand); color: var(--brand-ink); }

h1, h2, h3 { font-family: var(--font-ui); letter-spacing: -.01em; }

/* -------- каркас -------- */
.app { position: relative; z-index: 1; max-width: 680px; margin: 0 auto; padding: 0 14px calc(var(--dock-h) + 28px); }

.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 10px;
    padding: 14px 2px 10px;
    background: linear-gradient(180deg, rgba(11, 13, 18, .92) 70%, rgba(11, 13, 18, 0));
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.topbar .tb-title {
    font-family: var(--font-ui); font-weight: 800; font-size: 21px;
    letter-spacing: -.02em; margin: 0; flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-sub { display: block; font-family: var(--font-data); font-size: 11px; font-weight: 400; color: var(--mut); letter-spacing: .02em; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub a { color: var(--mut); }
.tb-sub a:hover { color: var(--brand); }
.icon-btn {
    flex: none; width: 40px; height: 40px; border-radius: 13px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--srf); border: 1px solid var(--line); color: var(--text);
    cursor: pointer; transition: transform .12s ease, background .15s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 19px; height: 19px; }
.brand-dot {
    width: 34px; height: 34px; border-radius: 11px; flex: none;
    background: linear-gradient(135deg, var(--brand), #E08A1E);
    color: var(--brand-ink); font-family: var(--font-ui); font-weight: 800;
    display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
    box-shadow: 0 4px 18px rgba(245, 185, 66, .35);
}

/* статус бота в топбаре */
.tb-status {
    display: inline-flex; align-items: center; gap: 7px; flex: none;
    font-family: var(--font-data); font-size: 11.5px; font-weight: 500;
    padding: 6px 12px; border-radius: 999px;
    background: var(--srf-2); border: 1px solid var(--line); color: var(--mut);
    white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
.tb-status .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--mut); }
.tb-status.ok { background: var(--up-soft); color: var(--up); border-color: transparent; }
.tb-status.ok .dot { background: var(--up); box-shadow: 0 0 0 0 rgba(61,219,165,.5); animation: pulse 2s infinite; }
.tb-status.warn { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.tb-status.warn .dot { background: var(--brand); }
.tb-status.fail { background: var(--down-soft); color: var(--down); border-color: transparent; }
.tb-status.fail .dot { background: var(--down); }
@media (max-width: 620px) { .tb-status .lbl { display: none; } .tb-status { padding: 6px 9px; } }

/* -------- док / рейл -------- */
.dock {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 60; width: min(560px, calc(100% - 24px));
    display: flex; padding: 8px;
    background: rgba(24, 28, 40, .82);
    border: 1px solid var(--line-strong); border-radius: 24px;
    backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
    box-shadow: var(--shadow);
}
.dock a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 0 6px; border-radius: 16px; color: var(--mut);
    font-family: var(--font-ui); font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
    transition: color .15s, background .15s, transform .1s;
    position: relative;
}
.dock a:active { transform: scale(.93); }
.dock a svg { width: 21px; height: 21px; flex: none; }
.dock a.on { color: var(--brand); background: var(--brand-soft); }
.dock .d-extra, .dock .dock-brand { display: none; }
.dock .nav-badge {
    position: absolute; top: 2px; right: 50%; margin-right: -22px;
    font-family: var(--font-data); font-size: 9px; font-weight: 600;
    background: var(--brand); color: var(--brand-ink);
    border-radius: 999px; padding: 1px 5px; line-height: 1.3;
}

/* -------- карточки -------- */
.card {
    background: linear-gradient(180deg, var(--srf) 0%, var(--bg-soft) 130%);
    border: 1px solid var(--line);
    border-radius: var(--r-l);
    padding: 16px;
    margin-bottom: 12px;
    position: relative; overflow: hidden;
}
.card-title {
    font-family: var(--font-ui); font-size: 12px; font-weight: 700;
    letter-spacing: .12em; text-transform: uppercase; color: var(--mut);
    margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card-title .spacer { flex: 1; }
.card-sub { font-size: 12.5px; color: var(--mut); margin: -6px 0 12px; }
.card.flat { background: transparent; border: none; padding: 0; overflow: visible; }
.section { margin-top: 14px; }
.link-all { margin-left: auto; font-size: 12px; font-weight: 500; text-transform: none; letter-spacing: 0; }

/* -------- герой (капитал) -------- */
.hero {
    border-radius: var(--r-l); border: 1px solid var(--line);
    background: linear-gradient(160deg, #161B29, #0D1017 70%);
    position: relative; overflow: hidden; margin-bottom: 12px;
    padding: 18px 16px 0;
}
.hero .h-label { font-family: var(--font-data); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--mut); }
.hero .h-value {
    font-family: var(--font-data); font-weight: 600; font-size: 38px; letter-spacing: -.03em;
    margin: 4px 0 2px; line-height: 1;
}
.hero .h-value small { font-size: 21px; color: var(--mut); font-weight: 500; }
.hero .h-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 6px; position: relative; z-index: 2; }
.hero .h-chart { margin: 6px -16px 0; display: block; }
.hero .h-chart svg { display: block; width: 100%; height: auto; }
.hero::after {
    content: ""; position: absolute; inset: 0 0 auto; height: 1px;
    background: linear-gradient(90deg, transparent, rgba(245,185,66,.6), transparent);
}

/* -------- KPI -------- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.kpi {
    background: var(--srf); border: 1px solid var(--line); border-radius: var(--r-m);
    padding: 12px 13px; min-width: 0;
}
.kpi .k-label { font-family: var(--font-ui); font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--mut); }
.kpi .k-value { font-family: var(--font-data); font-size: 19px; font-weight: 600; margin-top: 5px; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-sub { font-family: var(--font-data); font-size: 11px; color: var(--mut); margin-top: 2px; }
.kpi .k-spark { margin-top: 6px; }
.kpi-strip {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(128px, 1fr);
    gap: 10px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px;
    scroll-snap-type: x proximity; scrollbar-width: none;
}
.kpi-strip::-webkit-scrollbar { display: none; }
.kpi-strip .kpi { scroll-snap-align: start; margin: 0; }

/* -------- чипы, сегменты, тулбар -------- */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: var(--font-data); font-size: 12px; font-weight: 500;
    padding: 5px 11px; border-radius: 999px;
    background: var(--srf-2); border: 1px solid var(--line); color: var(--mut);
    cursor: pointer; user-select: none; transition: all .15s; white-space: nowrap;
}
.chip.on { background: var(--brand-soft); border-color: rgba(245,185,66,.4); color: var(--brand); }
.chip.up { background: var(--up-soft); color: var(--up); border-color: transparent; }
.chip.down { background: var(--down-soft); color: var(--down); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

.seg {
    display: inline-flex; padding: 3px; gap: 2px;
    background: var(--srf-2); border: 1px solid var(--line); border-radius: 12px;
}
.seg button, .seg a {
    border: none; background: transparent; color: var(--mut); cursor: pointer;
    font-family: var(--font-ui); font-size: 12px; font-weight: 700; letter-spacing: .02em;
    padding: 6px 12px; border-radius: 9px; transition: all .15s; text-decoration: none;
}
.seg button.active, .seg a.active { background: var(--brand); color: var(--brand-ink); box-shadow: 0 2px 10px rgba(245,185,66,.35); }

.toolbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-bottom: 14px;
}
.toolbar select { width: auto; flex: 1; min-width: 130px; max-width: 240px; }
.toolbar .count, .count { font-size: 12px; color: var(--mut); font-family: var(--font-data); }
.check-group { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.search-box { position: relative; flex: 1; min-width: 170px; }
.search-box input { padding-left: 38px !important; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--mut); pointer-events: none; }

.mobile-sort { display: none; font-size: 12px; color: var(--mut); align-items: center; gap: 8px; }
.mobile-sort select { width: auto; flex: 1; }

/* -------- вкладки -------- */
.tabs {
    display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
    margin: 2px -14px 14px; padding: 0 14px 2px;
    position: sticky; top: 60px; z-index: 30;
    background: linear-gradient(180deg, var(--bg) 75%, transparent);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs .tab-btn {
    flex: none; border: none; cursor: pointer;
    background: transparent; color: var(--mut);
    font-family: var(--font-ui); font-size: 13.5px; font-weight: 700;
    padding: 9px 13px; border-radius: 12px; transition: all .15s; position: relative;
}
.tabs .tab-btn.active { color: var(--text); background: var(--srf-2); }
.tabs .tab-btn.active::after {
    content: ""; position: absolute; left: 14px; right: 14px; bottom: 3px; height: 2px;
    border-radius: 2px; background: var(--brand);
}
.tabs .cnt { font-family: var(--font-data); font-size: 10.5px; font-weight: 600; color: var(--mut-2); margin-left: 3px; }
.tabs .tab-btn.active .cnt { color: var(--brand); }
.tab-panel { display: none; animation: fadeUp .25s ease; }
.tab-panel.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* -------- бейджи -------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-family: var(--font-data); font-size: 10px; font-weight: 600; letter-spacing: .06em;
    padding: 2.5px 7px; border-radius: 7px; text-transform: uppercase;
    background: var(--srf-3); color: var(--mut); vertical-align: middle;
}
.badge.st-ACTIVE { background: var(--up-soft); color: var(--up); }
.badge.st-TEST { background: var(--info-soft); color: var(--info); }
.badge.st-WATCH { background: var(--brand-soft); color: var(--brand); }
.badge.st-ARCHIVE { background: rgba(139, 147, 168, .15); color: var(--mut); }
.badge.long { background: var(--up-soft); color: var(--up); }
.badge.short { background: var(--down-soft); color: var(--down); }
.badge.liq { background: var(--down); color: #1c0508; }
.badge.part { background: var(--info-soft); color: var(--info); }
.badge.mode { background: var(--info-soft); color: var(--info); text-transform: none; }
.badge.on { background: var(--up-soft); color: var(--up); }
.badge.off { background: rgba(139,147,168,.15); color: var(--mut); }
.badge.grade-A { background: var(--up); color: #04120c; }
.badge.grade-B { background: var(--up-soft); color: var(--up); }
.badge.grade-C { background: var(--brand-soft); color: var(--brand); }
.badge.grade-D { background: var(--down-soft); color: var(--down); }
.badge.grade-F { background: var(--down); color: #1c0508; }

.tag-pill {
    display: inline-flex; font-family: var(--font-data); font-size: 10.5px;
    padding: 2px 8px; border-radius: 999px;
    border: 1px solid hsla(var(--tag-h, 40), 60%, 65%, .45);
    color: hsl(var(--tag-h, 40), 70%, 72%);
    background: hsla(var(--tag-h, 40), 60%, 55%, .1);
    white-space: nowrap;
}
.star-badge { color: var(--brand); font-size: 11px; white-space: nowrap; }
.star-badge .sb-n { font-family: var(--font-data); font-size: 10px; margin-left: 1px; }
.stars { color: var(--brand); font-size: 12px; letter-spacing: 1.5px; white-space: nowrap; }

.hd-link, .tv-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 5px; flex: none;
    color: var(--info); background: var(--info-soft); vertical-align: middle;
}
.hd-link svg, .tv-link svg { width: 11px; height: 11px; }
.hd-link:hover, .tv-link:hover { color: var(--brand); background: var(--brand-soft); }

.pos { color: var(--up); }
.neg { color: var(--down); }
.dim { color: var(--mut); }
.num, .mono { font-family: var(--font-data); }
.addr { font-family: var(--font-data); font-size: 11.5px; color: var(--mut); word-break: break-all; }
.small { font-size: 12px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; border: none; }

@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(61,219,165,0); } 100% { box-shadow: 0 0 0 0 rgba(61,219,165,0); } }

/* -------- кнопки -------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font-family: var(--font-ui); font-weight: 700; font-size: 13.5px;
    border-radius: 13px; padding: 10px 16px; border: 1px solid transparent;
    background: var(--brand); color: var(--brand-ink); cursor: pointer;
    transition: transform .12s, filter .15s; user-select: none; text-decoration: none;
    box-shadow: 0 6px 22px rgba(245,185,66,.25);
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--srf-2); color: var(--text); border-color: var(--line-strong); box-shadow: none; }
.btn.danger { background: var(--down-soft); color: var(--down); border-color: rgba(255,107,122,.35); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--mut); border-color: var(--line); box-shadow: none; }
.btn.small { padding: 7px 12px; font-size: 12.5px; border-radius: 11px; }
.btn.icon { width: 40px; height: 40px; padding: 0; flex: none; }
.btn.icon svg { width: 18px; height: 18px; }

.fab {
    position: fixed; right: max(16px, calc(50% - 288px)); bottom: calc(var(--dock-h) + 22px); z-index: 55;
    width: 54px; height: 54px; border-radius: 18px; border: none; cursor: pointer;
    background: var(--brand); color: var(--brand-ink);
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 10px 30px rgba(245,185,66,.4); transition: transform .15s;
}
.fab:active { transform: scale(.9) rotate(90deg); }
.fab svg { width: 24px; height: 24px; }

/* -------- формы -------- */
.field { margin-bottom: 13px; min-width: 0; }
.field label {
    display: block; font-family: var(--font-ui); font-size: 11.5px; font-weight: 600;
    color: var(--mut); margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase;
}
.hint { font-size: 11.5px; color: var(--mut-2); margin-top: 5px; line-height: 1.4; }
input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
    width: 100%; background: var(--bg-soft); border: 1px solid var(--line-strong);
    border-radius: 12px; color: var(--text); padding: 10px 13px;
    font-family: var(--font-data); font-size: 13.5px; outline: none;
    transition: border-color .15s, box-shadow .15s; appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238B93A8' stroke-width='2' viewBox='0 0 16 16'%3E%3Cpath d='M2 5l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea { min-height: 88px; resize: vertical; font-family: var(--font-body); }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input:disabled, select:disabled, textarea:disabled { opacity: .45; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
input[type=file] { padding: 8px 10px; font-size: 12px; }

.row, .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.check { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; cursor: pointer; padding: 3px 0; color: var(--text); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { text-transform: none !important; letter-spacing: 0 !important; }
/* --- Поля каталога настроек (settings_schema/settings_render) --- */
.set-field {
    position: relative; padding: 12px 13px; margin-bottom: 8px;
    background: var(--bg-soft); border: 1px solid var(--line);
    border-left: 2px solid transparent; border-radius: var(--r-m);
}
.set-field.is-overridden { border-left-color: var(--brand); }
.set-field.dep-hidden { display: none; }
.set-head { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; flex-wrap: wrap; }
.set-head label {
    display: inline; margin: 0; font-size: 13px; font-weight: 500;
    color: var(--text); text-transform: none; letter-spacing: 0;
}
.set-unit {
    font-family: var(--font-data); font-size: 10px; font-weight: 500; color: var(--mut);
    background: var(--srf-2); border-radius: 5px; padding: 2px 6px; white-space: nowrap;
}
.set-ovr-flag {
    font-size: 9.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
    color: var(--brand); background: var(--brand-soft); border-radius: 5px;
    padding: 2px 6px; margin-left: auto;
}
.set-toggle { margin-bottom: 7px; font-size: 12px; color: var(--mut); }
.set-what { font-size: 12px; color: var(--mut); margin-top: 7px; line-height: 1.4; }

/* Детали свёрнуты по умолчанию — иначе страница превращается в простыню. */
.set-more { margin-top: 6px; }
.set-more > summary {
    cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; color: var(--mut-2); padding: 2px 0; user-select: none;
}
.set-more > summary::-webkit-details-marker { display: none; }
.set-more > summary::before { content: "▸"; font-size: 9px; transition: transform .15s; }
.set-more[open] > summary::before { transform: rotate(90deg); }
.set-more > summary:hover { color: var(--brand); }
.set-more[data-has-warn] > summary { color: var(--warn); opacity: .75; }
.set-example {
    font-size: 11.5px; color: var(--mut); margin-top: 6px; line-height: 1.45;
    padding-left: 9px; border-left: 1px solid var(--line-strong);
}
.set-warn {
    font-size: 11.5px; color: var(--warn); margin-top: 6px; line-height: 1.45;
    padding-left: 9px; border-left: 1px solid currentColor; opacity: .85;
}
.set-tools { display: flex; justify-content: flex-end; margin: -4px 0 10px; }

/* --- Калькулятор размера позиции --- */
.calc { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--r-m); padding: 14px; }
.calc-row {
    display: flex; align-items: baseline; gap: 10px; padding: 9px 0;
    border-bottom: 1px dashed var(--line);
}
.calc-row:last-child { border-bottom: none; }
.calc-step {
    font-family: var(--font-data); font-size: 10.5px; font-weight: 700; color: var(--mut-2);
    background: var(--srf-3); border-radius: 5px; padding: 2px 6px; flex: none; min-width: 22px; text-align: center;
}
.calc-label { font-size: 12.5px; color: var(--mut); flex: 1; min-width: 0; line-height: 1.35; }
.calc-value { font-family: var(--font-data); font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; }
.calc-row.total .calc-value { color: var(--brand); font-size: 16px; }
.calc-row.muted .calc-label, .calc-row.muted .calc-value { opacity: .45; }
.calc-note { font-size: 12px; color: var(--mut); margin-top: 10px; line-height: 1.45; }
.calc-note.bad { color: var(--down); }
.calc-inputs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; margin-bottom: 4px; }
@media (max-width: 560px) { .calc-inputs { grid-template-columns: 1fr 1fr; } }

.form-group-title {
    font-family: var(--font-ui); font-size: 11px; font-weight: 700;
    letter-spacing: .12em; text-transform: uppercase; color: var(--brand);
    margin: 16px 0 10px; padding-top: 12px; border-top: 1px dashed var(--line);
}
.overrides-hint {
    font-size: 12px; color: var(--mut); background: var(--brand-soft);
    border: 1px solid rgba(245,185,66,.25); border-radius: var(--r-s);
    padding: 8px 12px; margin: 12px 0;
}
.tag-checkbox-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.tag-checkbox-item { display: inline-flex; align-items: center; gap: 6px; }
.tag-checkbox-item label { margin: 0; text-transform: none; letter-spacing: 0; cursor: pointer; }
.webhook-slot { background: var(--bg-soft) !important; border: 1px solid var(--line) !important; border-radius: var(--r-m) !important; padding: 13px !important; margin-bottom: 10px !important; }
.webhook-slot textarea { background: var(--srf) !important; border-color: var(--line-strong) !important; border-radius: 10px !important; }

/* тумблер */
.switch { position: relative; display: inline-flex; flex: none; width: 46px; height: 27px; vertical-align: middle; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 2; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--srf-3); transition: background .2s; }
.switch .track::after { content: ""; position: absolute; width: 21px; height: 21px; border-radius: 50%; top: 3px; left: 3px; background: #fff; transition: transform .2s cubic-bezier(.4, 1.6, .6, 1); }
.switch input:checked + .track { background: var(--up); }
.switch input:checked + .track::after { transform: translateX(19px); }

/* -------- уведомления -------- */
.alert {
    border-radius: var(--r-m); border: 1px solid var(--line);
    background: var(--srf); color: var(--mut);
    padding: 11px 14px; font-size: 12.5px; margin-bottom: 14px;
    border-left: 3px solid var(--info);
}
.alert.warn { border-left-color: var(--warn); }
.alert.danger { border-left-color: var(--down); color: var(--down); }
.alert b { color: var(--text); }
.alert.danger b { color: var(--down); }
.alert a { font-weight: 600; }

.message {
    border-radius: var(--r-m); padding: 11px 14px; font-size: 13px; margin-bottom: 14px;
    border: 1px solid transparent; background: var(--info-soft); color: var(--info);
}
.message.success { color: var(--up); background: var(--up-soft); }
.message.error { color: var(--down); background: var(--down-soft); }

.empty { text-align: center; color: var(--mut); padding: 34px 16px; font-size: 13px; }

/* -------- таблицы -------- */
.table-wrap {
    background: linear-gradient(180deg, var(--srf) 0%, var(--bg-soft) 130%);
    border: 1px solid var(--line); border-radius: var(--r-l);
    padding: 6px 4px; overflow-x: auto; margin-bottom: 12px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th {
    font-family: var(--font-ui); font-size: 10.5px; font-weight: 700;
    letter-spacing: .09em; text-transform: uppercase; color: var(--mut);
    text-align: left; padding: 10px 11px; white-space: nowrap;
    border-bottom: 1px solid var(--line-strong); user-select: none;
}
table td { padding: 10px 11px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table tbody tr:last-child td { border-bottom: none; }
table tbody tr { transition: background .12s; }
table tbody tr:hover { background: var(--srf-2); }
table tfoot td { font-family: var(--font-data); font-size: 12px; color: var(--mut); border-top: 1px solid var(--line-strong); border-bottom: none; padding: 10px 11px; }
th.num, td.num { text-align: right; white-space: nowrap; }
.sortable-th { cursor: pointer; }
.sortable-th:hover { color: var(--text); }
th.sort-desc, th.sort-asc { color: var(--brand); }
th.sort-desc::after { content: " ↓"; }
th.sort-asc::after { content: " ↑"; }
tr.row-link { cursor: pointer; }
table b { font-family: var(--font-ui); font-weight: 700; }

/* -------- тепловая таблица позиций -------- */
.pos-heat .sym { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-data); }
.side-ico { font-size: 10px; }
.side-ico.long { color: var(--up); }
.side-ico.short { color: var(--down); }
tr.tint-pos td:first-child { box-shadow: inset 3px 0 0 var(--up); }
tr.tint-neg td:first-child { box-shadow: inset 3px 0 0 var(--down); }
.e-in { color: var(--mut); }
.upnl-cell { display: flex; flex-direction: column; gap: 4px; min-width: 110px; }
.upnl-cell .nums { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.u-pct { font-weight: 600; }
.u-usd { font-size: 11px; }
.pnl-bar { height: 5px; border-radius: 5px; background: var(--srf-3); overflow: hidden; }
.pnl-bar span { display: block; height: 100%; border-radius: 5px; }
.pnl-bar.pos span { background: var(--up); }
.pnl-bar.neg span { background: var(--down); }

/* -------- карточки позиций (мобайл) -------- */
.pos-cards { display: none; grid-template-columns: 1fr 1fr; gap: 10px; }
.pos-card {
    background: linear-gradient(180deg, var(--srf) 0%, var(--bg-soft) 130%);
    border: 1px solid var(--line); border-radius: var(--r-m);
    padding: 12px; position: relative; overflow: hidden; cursor: pointer;
}
.pos-card.long { box-shadow: inset 3px 0 0 var(--up); }
.pos-card.short { box-shadow: inset 3px 0 0 var(--down); }
.pc-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.pc-coin-wrap { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.pc-coin { font-weight: 700; font-size: 15px; }
.pc-side { font-family: var(--font-data); font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 7px; flex: none; }
.pc-side.long { background: var(--up-soft); color: var(--up); }
.pc-side.short { background: var(--down-soft); color: var(--down); }
.pc-pct { font-size: 19px; font-weight: 600; }
.pc-usd { font-size: 12px; margin-bottom: 6px; }
.pc-meta { margin-top: 8px; }
/* Узкие карточки (2 колонки на телефоне): подпись и значение в две строки,
   иначе пары вида «Вход → тек.» не помещаются и ломают строку посередине */
.pc-row { font-size: 11.5px; padding: 3px 0; }
.pc-row .k { display: block; color: var(--mut-2); margin-bottom: 1px; }
.pc-row .v { display: block; font-family: var(--font-data); color: var(--mut); min-width: 0; overflow-wrap: break-word; }
.pc-row .v.txt { font-family: var(--font-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-open { font-size: 10.5px; color: var(--mut-2); margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line); }
.pc-open .lbl { display: block; margin-bottom: 1px; }
.pc-open .v { font-family: var(--font-data); }

/* -------- строки-карточки (ленты) -------- */
.row-card {
    display: flex; align-items: center; gap: 12px;
    background: var(--srf); border: 1px solid var(--line); border-radius: var(--r-m);
    padding: 12px 13px; margin-bottom: 8px; position: relative; overflow: hidden;
    transition: transform .12s ease, border-color .15s;
}
.row-card .rc-main { flex: 1; min-width: 0; }
.row-card .rc-title { font-family: var(--font-ui); font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.row-card .rc-sub { font-family: var(--font-data); font-size: 11.5px; color: var(--mut); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-card .rc-right { text-align: right; flex: none; }
.row-card .rc-num { font-family: var(--font-data); font-weight: 600; font-size: 15px; }
.row-card .rc-num-sub { font-family: var(--font-data); font-size: 11px; color: var(--mut); margin-top: 2px; }
.row-card .rc-spark { position: absolute; right: 0; top: 0; bottom: 0; width: 46%; opacity: .5; pointer-events: none;
    mask-image: linear-gradient(90deg, transparent, #000 55%); -webkit-mask-image: linear-gradient(90deg, transparent, #000 55%); }
.heat { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 4px 0 0 4px; }

/* лента дашборда */
.feed-row { display: flex; gap: 12px; align-items: baseline; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.feed-row:last-child { border-bottom: none; }
.row-link[data-href]:hover { background: var(--srf-2); }
div.row-link[data-href]:hover, a.row-link:hover { background: var(--srf-2); border-color: var(--line-strong); }

/* -------- графики -------- */
.chart-box { min-height: 60px; }
.chart-box svg { display: block; width: 100%; height: auto; }
.dash-spark svg, .k-spark svg, [data-spark] svg { display: block; }
.chart-legend { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 11.5px; color: var(--mut); }
.lg-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.charts-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
.bar-rect:hover, .donut-seg:hover { opacity: .8; }
.axis-l { font-family: var(--font-data); font-size: 9.5px; fill: var(--mut-2); }

/* score bar */
.score-bar { height: 6px; border-radius: 6px; background: var(--srf-3); overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--brand), var(--up)); }

/* -------- опасная зона -------- */
.danger-zone { border-color: rgba(255,107,122,.3); }
.danger-zone .card-title { color: var(--down); }

/* -------- bulk actionbar -------- */
.bulk-actionbar {
    position: sticky; bottom: calc(var(--dock-h) + 14px); z-index: 50;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    background: rgba(27, 33, 48, .95); border: 1px solid var(--line-strong);
    border-radius: var(--r-m); padding: 10px 14px; margin: 12px 0;
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow);
}
.bulk-actionbar .cnt { font-family: var(--font-data); font-size: 12px; color: var(--brand); font-weight: 600; }

/* -------- bottom sheet (навигация «Ещё») -------- */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 90; background: rgba(5, 7, 12, .6);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
    opacity: 0; transition: opacity .25s; pointer-events: none;
}
.sheet {
    position: fixed; left: 50%; bottom: 0; z-index: 95;
    width: min(640px, 100%); max-height: 86dvh; overflow-y: auto;
    transform: translate(-50%, 105%); transition: transform .32s cubic-bezier(.32, .9, .35, 1);
    background: var(--srf); border: 1px solid var(--line-strong); border-bottom: none;
    border-radius: 26px 26px 0 0; box-shadow: 0 -20px 60px rgba(0,0,0,.6);
    padding: 0 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet-open .sheet { transform: translate(-50%, 0); }
.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet .sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--srf-3); margin: 10px auto 8px; }
.sheet h3 {
    font-family: var(--font-ui); font-size: 11px; font-weight: 700;
    letter-spacing: .12em; text-transform: uppercase; color: var(--mut-2);
    margin: 14px 4px 6px;
}
.sheet .sb-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 13px; color: var(--text);
    font-family: var(--font-ui); font-weight: 600; font-size: 14px;
}
.sheet .sb-item svg { width: 19px; height: 19px; color: var(--mut); flex: none; }
.sheet .sb-item:active { background: var(--srf-2); }
.sheet .sb-item .sb-badge {
    margin-left: auto; font-family: var(--font-data); font-size: 10px; font-weight: 600;
    background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 2px 8px;
}

/* -------- тост -------- */
.toast {
    position: fixed; left: 50%; transform: translateX(-50%) translateY(14px);
    bottom: calc(var(--dock-h) + 24px); z-index: 120;
    width: max-content; max-width: min(420px, calc(100% - 32px));
    background: var(--srf-3); border: 1px solid var(--line-strong); border-left: 3px solid var(--brand);
    border-radius: 14px; padding: 12px 15px; font-size: 13px;
    box-shadow: var(--shadow); opacity: 0; pointer-events: none;
    transition: opacity .25s, transform .3s cubic-bezier(.3, 1.4, .5, 1);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* -------- логин -------- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; position: relative; z-index: 1; }
.login-card { width: min(380px, 100%); padding: 26px 22px; }
.login-card .sb-logo {
    width: 72px; height: 72px; margin: 0 auto 18px; border-radius: 22px;
    background: linear-gradient(135deg, var(--brand), #E08A1E); color: var(--brand-ink);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-ui); font-weight: 800; font-size: 28px;
    box-shadow: 0 16px 44px rgba(245,185,66,.4); animation: floatY 4s ease-in-out infinite;
}
@keyframes floatY { 50% { transform: translateY(-7px); } }

/* ============================================================
   МОБАЙЛ (<720px): stack-таблицы превращаются в карточки,
   мобильная сортировка видима, десктопные хвосты скрыты
   ============================================================ */
@media (max-width: 719px) {
    .mobile-sort { display: flex; }

    .table-wrap { background: transparent; border: none; padding: 0; overflow: visible; }
    table.stack, table.stack tbody { display: block; }
    table.stack thead, table.stack tfoot { display: none; }
    table.stack tbody tr {
        display: block; position: relative;
        background: linear-gradient(180deg, var(--srf) 0%, var(--bg-soft) 130%);
        border: 1px solid var(--line); border-radius: var(--r-m);
        padding: 11px 13px; margin-bottom: 9px;
    }
    table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: none; padding: 3px 0; font-size: 12.5px; text-align: right; }
    table.stack td[data-label]::before {
        content: attr(data-label);
        font-family: var(--font-ui); font-size: 10.5px; font-weight: 600;
        letter-spacing: .07em; text-transform: uppercase; color: var(--mut-2);
        flex: none; text-align: left;
    }
    table.stack td.stack-main { display: block; text-align: left; font-size: 14.5px; padding-bottom: 7px; margin-bottom: 5px; border-bottom: 1px dashed var(--line); }
    table.stack tr.no-data { background: transparent; border: none; }

    /* тепловая таблица позиций → карточки */
    .pos-heat-wrap { display: none; }
    .pos-cards { display: grid; }

    .row, .row2, .row3 { grid-template-columns: 1fr; }
}

@media (min-width: 720px) {
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
    .charts-2 { grid-template-columns: 1fr 1fr; }
    .pos-cards { display: none !important; }
    .pos-cards + * { margin-top: 0; }
    label.mobile-sort { display: none; }
}

/* ============================================================
   ДЕСКТОП (≥1000px): док → вертикальный рейл слева,
   контент расширяется, «Ещё» исчезает
   ============================================================ */
@media (min-width: 1000px) {
    body { font-size: 14px; }
    .app {
        max-width: 1220px;
        margin-left: max(248px, calc((100vw - 1220px - 248px) / 2 + 248px));
        margin-right: auto;
        padding: 0 28px 48px;
    }
    .topbar { padding-top: 20px; }
    .topbar .tb-title { font-size: 24px; }
    .tabs { top: 70px; margin-left: -6px; padding-left: 6px; }

    .dock {
        left: 20px; top: 20px; bottom: auto; transform: none;
        width: 204px; max-height: calc(100dvh - 40px); overflow-y: auto;
        flex-direction: column; align-items: stretch; gap: 3px;
        padding: 14px 10px; border-radius: 24px;
    }
    .dock a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; font-size: 13.5px; border-radius: 13px; }
    .dock a svg { width: 19px; height: 19px; }
    .dock .d-more { display: none; }
    .dock .d-extra { display: flex; }
    .dock .d-logout { margin-top: 10px; border-top: 1px solid var(--line); border-radius: 0 0 13px 13px; padding-top: 14px; color: var(--mut-2); }
    .dock .dock-brand {
        display: flex; align-items: center; gap: 11px;
        padding: 4px 8px 16px; margin-bottom: 8px;
        border-bottom: 1px solid var(--line);
        font-family: var(--font-ui); font-weight: 800; font-size: 13px;
        line-height: 1.15; letter-spacing: .01em; color: var(--text);
    }
    .dock .nav-badge { position: static; margin: 0 0 0 auto; }

    .fab { right: 40px; bottom: 40px; }
    .toast { bottom: 32px; }
    .bulk-actionbar { bottom: 14px; }

    .hero { padding: 24px 24px 0; }
    .hero .h-value { font-size: 52px; }
    .hero .h-chart { margin: 8px -24px 0; }
    .kpi .k-value { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
