/* peakml.chromoshub.ru — разметка пиков 1D-CNN (стили унаследованы от peakfit.chromoshub.ru) */
:root {
    --bg: #0d1117; --bg-2: #161b22; --bg-3: #1c2430; --card: #10151d;
    --line: #26303c; --line-2: #313d4d;
    --txt: #e6edf3; --txt-2: #9aa7b4; --txt-3: #6b7684;
    --accent: #58b0ff; --accent-2: #2f81f7; --peak: #d29922; --base: #3fb950; --emg: #ff6ec7;
    /* классы пиков: симметричный, хвостящий, фронтирующий, неразделённый, артефакт */
    --c0: #3987e5; --c1: #d95926; --c2: #199e70; --c3: #c98500; --c4: #d55181;
    --mono: "JetBrains Mono", "Cascadia Code", "Fira Code", "DejaVu Sans Mono", "Consolas", monospace;
    --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="light"] {
    --bg: #f4f6fa; --bg-2: #ffffff; --bg-3: #eef1f6; --card: #ffffff;
    --line: #dde3ec; --line-2: #c8d1de;
    --txt: #16202f; --txt-2: #52617a; --txt-3: #808d9b;
    --accent: #1f6feb; --accent-2: #1a5fd0; --peak: #b8860b; --base: #1a7f37; --emg: #c026d3;
    --c0: #2a78d6; --c1: #eb6834; --c2: #1baf7a; --c3: #eda100; --c4: #e87ba4;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--ui); background: var(--bg); color: var(--txt); min-height: 100vh; display: flex; flex-direction: column; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 13px 18px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.brand { display: inline-flex; align-items: baseline; gap: 9px; font-weight: 600; font-size: 15px; }
.brand__mark { font-size: 18px; color: var(--accent); }
.brand__sub { font-weight: 400; font-size: 12px; color: var(--txt-3); }
.actions { display: flex; align-items: center; gap: 10px; }
.lang { display: inline-flex; height: 32px; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.lang__btn { font-family: var(--mono); font-size: 11px; font-weight: 600; padding: 0 9px; border: 0; background: var(--bg-3); color: var(--txt-2); cursor: pointer; }
.lang__btn + .lang__btn { border-left: 1px solid var(--line-2); }
.lang__btn:hover { color: var(--accent); }
.lang__btn.is-active { background: var(--accent-2); color: #fff; }
.icon-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line-2); border-radius: 8px; background: var(--bg-3); color: var(--txt-2); cursor: pointer; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn .i-moon { display: none; }
:root[data-theme="light"] .icon-btn .i-sun { display: none; }
:root[data-theme="light"] .icon-btn .i-moon { display: block; }

/* help dialog */
.modal-back { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, .55); }
.modal-back[hidden] { display: none; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 760px; max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0, 0, 0, .45); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal__head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--txt); }
.modal__body { overflow-y: auto; padding: 4px 20px 22px; }
.modal__body h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin: 22px 0 8px; }
.modal__body p { font-size: 13px; line-height: 1.55; color: var(--txt-2); margin: 8px 0; }
.modal__body ol { padding-left: 20px; margin: 8px 0; }
.modal__body ol li { font-size: 13px; line-height: 1.5; color: var(--txt-2); margin-bottom: 6px; }
.modal__body ol li b, .modal__body p b { color: var(--txt); font-weight: 600; }
.modal__body ul.help-params { list-style: none; padding: 0; margin: 8px 0; }
.modal__body ul.help-params li { font-size: 12.5px; line-height: 1.5; color: var(--txt-3); margin-bottom: 9px; }
.modal__body ul.help-params li b { color: var(--txt); font-weight: 600; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; position: relative; }
.field { display: inline-flex; align-items: center; gap: 8px; }
.field__lbl { font-size: 13px; color: var(--txt-2); }
.select { font-family: var(--ui); font-size: 13px; background: var(--bg-3); color: var(--txt); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; cursor: pointer; max-width: 260px; }
.btn { display: inline-flex; align-items: center; font-size: 13px; font-weight: 500; padding: 8px 14px; border-radius: 8px; cursor: pointer; border: 1px solid var(--accent-2); background: var(--accent-2); color: #fff; }
.btn:hover { background: var(--accent); }
.btn--ghost { background: var(--bg-3); color: var(--txt-2); border-color: var(--line-2); }
.btn--ghost:hover { background: var(--bg-3); color: var(--accent); border-color: var(--accent); }
.fname { font-family: var(--mono); font-size: 12px; color: var(--txt-2); }
.toolbar__spacer { flex: 1; }
.status { font-size: 12px; color: var(--txt-3); }
.status.err { color: #f85149; }

.wrap { max-width: 1180px; width: 100%; margin: 0 auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; flex: 1 1 auto; min-height: 0; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; font-size: 13px; color: var(--txt-2); border-bottom: 1px solid var(--line); background: var(--bg-2); }
.chip { font-family: var(--mono); font-size: 12px; padding: 1px 9px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line-2); color: var(--txt-2); }
.mono { font-family: var(--mono); } .muted { color: var(--txt-3); font-size: 12px; }

/* ---------- Parameters ---------- */
.params__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px 18px; padding: 14px; }
.pf { display: flex; flex-direction: column; gap: 5px; }
.pf__top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pf__lbl { font-size: 12px; color: var(--txt-2); }
.pf__val { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.pf input[type="range"] { width: 100%; accent-color: var(--accent-2); height: 20px; cursor: pointer; }
.pf .select { width: 100%; max-width: none; padding: 6px 9px; font-size: 13px; }
.pf--chk { flex-direction: row; align-items: center; gap: 8px; }
.pf--chk input { accent-color: var(--accent-2); width: 15px; height: 15px; cursor: pointer; }
.pf--chk label { font-size: 13px; color: var(--txt-2); cursor: pointer; }
.pf.is-off { opacity: .4; pointer-events: none; }
.pf.is-auto input[type="range"] { opacity: .45; pointer-events: none; }
.pf.is-auto .pf__val::after { content: " ⇠auto"; color: var(--txt-3); font-size: 10px; }
/* the params panel must let tooltip bubbles escape its rounded box */
.panel.params { overflow: visible; }
.panel.params .panel__head { border-radius: 12px 12px 0 0; }

/* custom "speech bubble" tooltips (replace native title) */
[data-tip] { position: relative; }
.pf[data-tip]:hover { z-index: 60; }
[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute; left: 50%; bottom: calc(100% + 9px); transform: translateX(-50%);
    width: max-content; max-width: 240px; white-space: normal; text-align: left;
    background: var(--bg-2); color: var(--txt);
    border: 1px solid var(--line-2); border-radius: 12px;
    padding: 8px 12px; font-size: 12px; line-height: 1.42; font-weight: 400;
    box-shadow: 0 8px 26px rgba(0, 0, 0, .38); z-index: 60; pointer-events: none;
    animation: tip-in .12s ease-out;
}
[data-tip]:hover::before {
    content: ''; position: absolute; left: 50%; bottom: calc(100% + 3px); transform: translateX(-50%);
    border: 7px solid transparent; border-top-color: var(--bg-2);
    z-index: 61; pointer-events: none;
    filter: drop-shadow(0 3px 1px rgba(0, 0, 0, .18));
    animation: tip-in .12s ease-out;
}
@keyframes tip-in { from { opacity: 0; } to { opacity: 1; } }
.params__range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 14px 14px; }
.params__range .range-dash { color: var(--txt-3); }
.params__range.is-limited .num-in { border-color: var(--accent); color: var(--accent); }
.num-in { font-family: var(--mono); font-size: 13px; width: 84px; background: var(--bg-3); color: var(--txt); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 8px; }

.chart { position: relative; width: 100%; min-height: 360px; }
.chart svg { width: 100%; height: auto; display: block; }
.placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--txt-3); font-size: 14px; text-align: center; padding: 0 20px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--txt-3); font-family: var(--mono); font-size: 10px; }
.chart .axis-title { fill: var(--txt-2); font-family: var(--ui); font-size: 12px; }
.chart .signal { fill: none; stroke: var(--accent); stroke-width: 1.3; stroke-linejoin: round; }
.chart .baseline { fill: none; stroke: var(--base); stroke-width: 1.2; stroke-dasharray: 5 4; opacity: .85; }
.chart .noise-band { fill: var(--txt-3); fill-opacity: .12; stroke: none; }
.chart .thr-line { fill: none; stroke: var(--txt-3); stroke-width: 1; stroke-dasharray: 2 3; opacity: .8; }
.chart .emg-fit { fill: none; stroke: var(--emg, #d6336c); stroke-width: 1.6; opacity: .95; }
.chart .emg-comp { fill: none; stroke: var(--emg, #d6336c); stroke-width: 1; stroke-dasharray: 4 3; opacity: .55; }
.chart .clip-fit { fill: none; stroke: var(--emg, #d6336c); stroke-width: 1.5; stroke-dasharray: 6 3; opacity: .9; }
.chart .range-off { fill: var(--txt-3); fill-opacity: .08; }
.chart .peak-band { fill: transparent; }
.chart .peak-area { fill: color-mix(in srgb, var(--peak) 22%, transparent); }
.chart .peak-area.is-hi { fill: color-mix(in srgb, var(--peak) 42%, transparent); }
.chart .peak-line { stroke: var(--peak); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .peak-lbl { fill: var(--peak); font-family: var(--mono); font-size: 9px; }
.chart .peak-band.is-hi { fill: color-mix(in srgb, var(--peak) 20%, transparent); }
.chart .peak-line.is-hi { stroke-width: 1.6; stroke-dasharray: none; }
.chart .peak-base { fill: none; stroke: var(--peak); stroke-width: 1; opacity: .8; }
.chart .peak-base.is-hi { stroke-width: 2; opacity: 1; }
.chart .peak-drop { stroke: var(--peak); stroke-width: .8; opacity: .5; }
.chart .pk-handle { fill: var(--bg-2); stroke: var(--peak); stroke-width: 1.5; }
.chart .pk-handle.is-hi { fill: var(--peak); }
.chart.manual svg { cursor: crosshair; }
.chart .file-tick { fill: none; stroke: var(--txt-3); stroke-width: 1; }
.chart .file-mark { fill: var(--txt-3); opacity: .8; }
.chart .sel-rect { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 1; }
.chart #pfHit { cursor: crosshair; }
.chart.pan-ready #pfHit { cursor: grab; }
.chart.panning #pfHit { cursor: grabbing; }
.chart .cross { stroke: var(--txt-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .cross-dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.chart .tip-bg { fill: var(--bg-2); stroke: var(--line-2); stroke-width: 1; }
.chart .tip-tx { fill: var(--txt); font-family: var(--mono); font-size: 11px; }
.chart .tip-peak { fill: var(--peak); }

.table-wrap { overflow: auto; flex: 1 1 auto; min-height: 0; max-height: 60vh; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { position: sticky; top: 0; background: var(--bg-2); text-align: left; padding: 8px 12px; color: var(--txt-3); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th.num, .tbl td.num { text-align: right; font-family: var(--mono); }
.tbl th[data-sort] { cursor: pointer; user-select: none; }
.tbl th[data-sort]:hover { color: var(--accent); }
.tbl:not(.show-adv) .col-adv { display: none; }
.tbl.suit-on .col-adv { display: table-cell; }
.tbl.two-row .col-adv { display: none; }                       /* metrics move to the sub-row */
.tbl td.cell-bad { color: #f85149; font-weight: 700; background: color-mix(in srgb, #f85149 13%, transparent); }
/* two-row layout: each peak = a main row + a full-width metrics sub-row */
.tbl.two-row tbody tr.pk-main > td { border-bottom: none; }
.tbl.two-row tbody tr.pk-main { cursor: pointer; }
.tbl td.pk-metrics { padding: 2px 12px 8px 34px; color: var(--txt-3); font-size: 12px; }
.tbl td.pk-metrics .m { display: inline-block; margin-right: 16px; white-space: nowrap; }
.tbl td.pk-metrics .m b { color: var(--txt); font-family: var(--mono); font-weight: 600; margin-left: 4px; }
.tbl td.pk-metrics .m.cell-bad, .tbl td.pk-metrics .m.cell-bad b { color: #f85149; font-weight: 700; }
.suit-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); font-size: 12px; }
.suit-bar label, .suit-inline { display: inline-flex; align-items: center; gap: 5px; color: var(--txt-2); white-space: nowrap; }
.num-in--xs { width: 58px; padding: 4px 6px; font-size: 12px; }
.val-chip.suit-verdict.is-ok { color: var(--base); border-color: color-mix(in srgb, var(--base) 55%, var(--line-2)); }
.val-chip.suit-verdict.is-bad { color: #f85149; border-color: color-mix(in srgb, #f85149 55%, var(--line-2)); }
.tbl th.sort-asc::after { content: ' ▲'; }
.tbl th.sort-desc::after { content: ' ▼'; }
.tbl td { padding: 7px 12px; border-bottom: 1px solid var(--line); color: var(--txt); }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--bg-3); }
.tbl tbody tr.is-hi { background: color-mix(in srgb, var(--peak) 18%, transparent); }
.tbl .pk-n { color: var(--peak); font-family: var(--mono); white-space: nowrap; }
.tbl .pk-m { color: var(--emg); font-weight: 700; margin-left: 2px; }
.tbl .pk-c { color: var(--emg); font-weight: 700; margin-left: 2px; }
.tbl .pk-lq { color: #d29922; font-family: var(--mono); font-size: 10px; margin-left: 4px; }
.tbl .pk-ld { color: #f85149; font-family: var(--mono); font-size: 10px; margin-left: 4px; }
.tbl .pk-rd { color: #3fb0d8; font-weight: 700; margin-left: 4px; cursor: help; }
.lod-line { fill: none; stroke: #d29922; stroke-width: 1; stroke-dasharray: 5 4; opacity: .8; }
.loq-line { fill: none; stroke: var(--base); stroke-width: 1; stroke-dasharray: 5 4; opacity: .8; }
.lod-lbl { fill: var(--txt-3); font-family: var(--mono); font-size: 9px; }
.pk-del { border: none; background: none; color: var(--txt-3); cursor: pointer; font-size: 12px; padding: 0 5px 0 0; line-height: 1; }
.pk-del:hover { color: #e5484d; }

.head-right { display: inline-flex; align-items: center; gap: 10px; }
.head-left { display: inline-flex; align-items: center; gap: 10px; }
.select--sm { padding: 4px 8px; font-size: 12px; max-width: 220px; }
.mini-btn { font-size: 12px; padding: 4px 10px; border-radius: 7px; cursor: pointer; border: 1px solid var(--line-2); background: var(--bg-3); color: var(--txt-2); }
.mini-btn:hover { color: var(--accent); border-color: var(--accent); }
.mini-btn.is-active { color: #fff; background: var(--emg); border-color: var(--emg); }
.chart-hint { padding: 8px 14px 12px; font-size: 12px; }

/* ---------- Validation panel ---------- */
.val-chip { font-family: var(--mono); font-size: 12px; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--line-2); }
.val-chip.val-ok { color: var(--base); border-color: color-mix(in srgb, var(--base) 50%, var(--line-2)); }
.val-chip.val-miss { color: #d29922; border-color: color-mix(in srgb, #d29922 50%, var(--line-2)); }
.val-chip.val-extra { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--line-2)); }
#valTbl tbody tr.val-missrow { color: var(--txt-3); background: color-mix(in srgb, #d29922 8%, transparent); }
#valTbl tbody tr { cursor: pointer; }
#valTbl tbody tr:hover { background: var(--bg-3); }

.toolbar.drag-over { outline: 2px dashed var(--accent); outline-offset: -3px; }
.drop-hint { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: color-mix(in srgb, var(--card) 90%, transparent); color: var(--accent); font-weight: 600; font-size: 14px; border-radius: 12px; }
.toolbar.drag-over .drop-hint { display: flex; }

@media (max-width: 820px) {
    body { display: block; }
    .wrap { flex: none; min-height: 0; }
    .table-wrap { max-height: 65vh; }
}

/* ---------- Print ---------- */
@media print {
    @page { margin: 14mm; }
    :root {
        --bg: #fff; --bg-2: #fff; --bg-3: #f4f6fa; --card: #fff;
        --line: #cbd5e1; --line-2: #b0bccc;
        --txt: #101820; --txt-2: #333; --txt-3: #555;
        --accent: #1f6feb; --accent-2: #1a5fd0; --peak: #b8860b; --base: #1a7f37;
    }
    body { background: #fff; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .topbar .actions, .toolbar, .params, .chart-hint, #resetZoom,
    #pfHover, #pfHit, .sel-rect, .drop-hint { display: none !important; }
    .topbar { background: #fff; border-bottom: 1px solid #ccc; }
    .wrap { max-width: none; margin: 0; padding: 0; gap: 12px; }
    .panel { box-shadow: none; border: 1px solid #ccc; }
    .panel--chart, .chart, .chart svg { break-inside: avoid; }
    .table-wrap { max-height: none; overflow: visible; }
    .tbl th { position: static; }
    .tbl tbody tr { break-inside: avoid; }
    .chart svg, .signal, .baseline, .peak-area, .peak-base, .peak-line { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- peakml: классы пиков ---------- */
.cls-0 { --cc: var(--c0); } .cls-1 { --cc: var(--c1); } .cls-2 { --cc: var(--c2); }
.cls-3 { --cc: var(--c3); } .cls-4 { --cc: var(--c4); }
.chart .pk-fill { fill: color-mix(in srgb, var(--cc) 26%, transparent); stroke: none; }
.chart .pk-fill.is-hi { fill: color-mix(in srgb, var(--cc) 50%, transparent); }
.chart .pk-edge { stroke: var(--cc); stroke-width: 1; opacity: .55; }
.chart .pk-mark { fill: var(--cc); stroke: var(--card); stroke-width: 1.2; }
.chart .pk-num { fill: var(--cc); font-family: var(--mono); font-size: 9px; }
.cls-chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cls-chip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--cc); flex: none; }
.legend { display: inline-flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--txt-2); }
.legend .cls-chip b { font-family: var(--mono); font-weight: 600; color: var(--txt); }
.info { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 0 14px 14px; }
.conf { font-family: var(--mono); font-size: 12px; color: var(--txt-2); }
.conf.lo { color: #d29922; }
.tbl tbody tr.is-hi { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.badge-model { font-family: var(--mono); font-size: 11px; color: var(--txt-3); }
.placeholder[hidden] { display: none; }
#valPanel .table-wrap { max-height: 42vh; border-top: 1px solid var(--line); }
.chart-hint.foot { line-height: 1.5; border-top: 1px solid var(--line); padding-top: 9px; }
.params .chart-hint.foot { border-top: 0; padding-top: 0; }
.cls-defs .cls-chip { display: inline-flex; vertical-align: baseline; }
.cls-defs .cls-chip b { color: var(--txt-2); font-weight: 600; }
.tbl.two-row tbody tr.pk-sub { cursor: pointer; }
.tbl.two-row tbody tr.pk-sub.is-hi { background: color-mix(in srgb, var(--accent) 16%, transparent); }
