/* ============================================================================
   MARKTEX — ПОДСКАЗКИ К ИНСТРУМЕНТАМ (tool-help.css)
   ----------------------------------------------------------------------------
   Парная часть к tool-help.js. Один файл на весь сайт:
     .mt-help-btn  — круглая кнопка «?» в углу инструмента (встраивает JS)
     .mt-help-pop  — всплывающая карточка «что это / как считать / зачем нужно»
   Карточка позиционируется фиксированно (JS считает координаты), поэтому не
   обрезается overflow у таблиц и сайдбаров.
   Переменные берёт дизайн-слоя страницы (--mx-*), но имеет свои фолбэки,
   чтобы работать и на страницах без дизайн-слоя.
   ========================================================================== */
.mt-help-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 17px; height: 17px; margin: 0 0 0 6px; padding: 0;
    border: 1px solid var(--mx-line-strong, rgba(255, 255, 255, .16));
    border-radius: 50%;
    background: transparent; color: var(--text-secondary, #9a9a93);
    font: 600 10px/1 var(--mx-f-ui, 'Onest'), system-ui, sans-serif;
    font-family: inherit;
    cursor: pointer; vertical-align: middle; flex-shrink: 0;
    transition: color .18s, border-color .18s, background .18s, transform .18s;
}
.mt-help-btn:hover, .mt-help-btn[aria-expanded="true"] {
    color: var(--gold, #d4af37); border-color: var(--mx-gold-line, rgba(212, 175, 55, .4));
    background: var(--mx-gold-wash, rgba(212, 175, 55, .1)); transform: scale(1.08);
}
.mt-help-btn:focus-visible { outline: 2px solid var(--gold, #d4af37); outline-offset: 2px; }
/* вариант для заголовков столбцов таблицы — кнопка чуть меньше и без сдвига базовой линии */
th .mt-help-btn, .mt-help-btn--sm { width: 15px; height: 15px; font-size: 9px; }

/* ---------- оверлей ---------- */
.mt-help-overlay {
    position: fixed; inset: 0; z-index: 10040;
    background: rgba(0, 0, 0, .38);
    opacity: 0; pointer-events: none; transition: opacity .18s;
}
.mt-help-overlay.on { opacity: 1; pointer-events: auto; }

/* ---------- карточка ---------- */
.mt-help-pop {
    position: fixed; z-index: 10041;
    width: 352px; max-width: calc(100vw - 24px);
    max-height: min(78vh, 620px); overflow-y: auto;
    padding: 0;
    background: #131312; color: var(--text-color, #ececea);
    border: 1px solid var(--mx-line-strong, rgba(255, 255, 255, .16));
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
    font-family: var(--mx-f-ui, 'Onest'), system-ui, sans-serif;
    font-size: 13px; line-height: 1.55; text-align: left;
    opacity: 0; transform: translateY(6px) scale(.985); pointer-events: none;
    transition: opacity .18s, transform .18s;
}
.mt-help-pop.on { opacity: 1; transform: none; pointer-events: auto; }
.mt-help-pop::-webkit-scrollbar { width: 6px; }
.mt-help-pop::-webkit-scrollbar-thumb { background: var(--mx-line-strong, rgba(255,255,255,.16)); border-radius: 3px; }

.mt-help-head {
    position: sticky; top: 0; display: flex; align-items: center; gap: 10px;
    padding: 14px 16px 12px;
    background: #131312; border-bottom: 1px solid var(--mx-line, rgba(255, 255, 255, .08));
}
.mt-help-head i { color: var(--gold, #d4af37); font-size: 14px; }
.mt-help-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.mt-help-close {
    width: 26px; height: 26px; flex-shrink: 0; border: 1px solid var(--mx-line, rgba(255,255,255,.08));
    border-radius: 50%; background: transparent; color: var(--text-secondary, #9a9a93);
    font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.mt-help-close:hover { color: var(--text-color, #ececea); border-color: var(--mx-line-strong, rgba(255,255,255,.16)); }

.mt-help-body { padding: 14px 16px 16px; }
.mt-help-sec { margin-bottom: 14px; }
.mt-help-sec:last-child { margin-bottom: 0; }
.mt-help-sec h4 {
    margin: 0 0 5px; font-size: 11px; font-weight: 700; letter-spacing: .1em;
    text-transform: uppercase; color: var(--gold, #d4af37);
}
.mt-help-sec p { margin: 0 0 6px; color: var(--text-secondary, #b6b6ae); }
.mt-help-sec p:last-child { margin-bottom: 0; }
.mt-help-sec strong { color: var(--text-color, #ececea); font-weight: 600; }
.mt-help-sec ul { margin: 0; padding-left: 18px; color: var(--text-secondary, #b6b6ae); }
.mt-help-sec li { margin-bottom: 4px; }
.mt-help-sec li:last-child { margin-bottom: 0; }

/* формула/методика — моноширинно и в отдельной полоске */
.mt-help-formula {
    margin: 2px 0 0; padding: 9px 11px;
    background: var(--mx-surface-2, rgba(255, 255, 255, .055));
    border-left: 2px solid var(--gold, #d4af37); border-radius: 8px;
    font: 500 12px/1.5 'JetBrains Mono', 'Consolas', monospace;
    color: var(--text-color, #ececea); white-space: pre-wrap; word-break: break-word;
}

/* подвал карточки: источник данных + ссылка на раздел */
.mt-help-foot {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 12px 16px; border-top: 1px solid var(--mx-line, rgba(255, 255, 255, .08));
    background: var(--mx-surface, rgba(255, 255, 255, .028));
}
.mt-help-src {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 999px;
    font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.mt-help-src.real { background: rgba(74, 222, 128, .12); color: var(--green, #4ade80); border: 1px solid rgba(74, 222, 128, .3); }
.mt-help-src.demo { background: rgba(251, 191, 36, .12); color: #fbbf24; border: 1px solid rgba(251, 191, 36, .3); }
.mt-help-src.mix { background: rgba(96, 165, 250, .12); color: #60a5fa; border: 1px solid rgba(96, 165, 250, .3); }
.mt-help-src.none { background: rgba(248, 113, 113, .12); color: var(--red, #f87171); border: 1px solid rgba(248, 113, 113, .3); }
.mt-help-link {
    margin-left: auto; color: var(--gold, #d4af37); font-size: 12px; font-weight: 600; text-decoration: none;
    border-bottom: 1px dashed transparent;
}
.mt-help-link:hover { border-bottom-color: var(--gold, #d4af37); }
.mt-help-note { font-size: 11px; color: var(--text-secondary, #9a9a93); }

/* ---------- светлая тема ---------- */
body.light .mt-help-pop, body.light .mt-help-head { background: #fff; color: #141414; }
body.light .mt-help-pop { box-shadow: 0 24px 60px rgba(0, 0, 0, .18); }
body.light .mt-help-sec p, body.light .mt-help-sec ul, body.light .mt-help-note { color: #4a4a45; }
body.light .mt-help-sec strong, body.light .mt-help-formula { color: #141414; }
body.light .mt-help-src.demo { background: rgba(180, 120, 10, .12); color: #92600a; }

/* ---------- мобилка: карточка становится нижней шторкой ---------- */
@media (max-width: 620px) {
    .mt-help-pop {
        left: 0 !important; right: 0; top: auto !important; bottom: 0;
        width: 100%; max-width: 100%; max-height: 76vh;
        border-radius: 18px 18px 0 0; border-left: 0; border-right: 0; border-bottom: 0;
    }
    .mt-help-pop.on { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .mt-help-pop, .mt-help-overlay, .mt-help-btn { transition: none !important; }
}
