/*
  shotdetectstats/static/shotdetectstats/css/theme-v2-chart.css

  Тема "Chart":
    - плоский темный стиль
    - тонкие границы
    - аккуратная сетка для мини-графика
    - умеренная типографика (без чрезмерной жирности)
*/

:root {
    --bg: #0b0c0f;
    --bg2: #0e0f13;

    --panel: #121318;
    --panel2: #0f1115;

    --border: rgba(255, 255, 255, 0.08);
    --border2: rgba(255, 255, 255, 0.06);

    --text: rgba(255, 255, 255, 0.92);
    --muted: rgba(255, 255, 255, 0.60);

    --up: #22c55e;
    --down: #ef4444;

    --radius: 12px;
    --radius-sm: 10px;

    --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);

    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --ui: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

.sd-page {
    min-height: 100%;
    padding: 0 0 28px;
    color: var(--text);
    font-family: var(--ui);
    background:
        radial-gradient(900px 520px at 10% 5%, rgba(34, 197, 94, 0.10), transparent 60%),
        radial-gradient(900px 520px at 90% 10%, rgba(239, 68, 68, 0.08), transparent 60%),
        linear-gradient(180deg, var(--bg2), var(--bg));
}

.is-hidden { display: none !important; }

/* ========================= TOPBAR ========================= */

.sd-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

/* ---- info-бар ---- */

.sd-infobar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    min-height: 36px;
    flex-wrap: wrap;
}

.sd-infobar__left { flex-shrink: 0; }

.sd-infobar__toggle {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.sd-infobar__toggle:hover {
    border-color: rgba(255, 255, 255, 0.14);
}

.sd-infobar__toggle svg {
    flex-shrink: 0;
}

/* Пульсация кнопки «Параметры» до первого клика */
.sd-infobar__toggle.is-pulsing {
    border-color: #2b6cb0;
    animation: sd-toggle-glow 2s ease-in-out infinite;
}

.sd-infobar__toggle.is-pulsing::before,
.sd-infobar__toggle.is-pulsing::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 8px;
    border: 1px solid #2b6cb0;
    opacity: 0;
    pointer-events: none;
}

.sd-infobar__toggle.is-pulsing::before {
    animation: sd-pulse-ring 2s ease-out infinite;
}

.sd-infobar__toggle.is-pulsing::after {
    animation: sd-pulse-ring 2s ease-out infinite 1s;
}

@keyframes sd-toggle-glow {
    0%, 100% { box-shadow: 0 0 4px rgba(43, 108, 176, 0.3); }
    50%      { box-shadow: 0 0 12px rgba(43, 108, 176, 0.6); }
}

@keyframes sd-pulse-ring {
    0%   { opacity: 0.7; transform: scale(1); }
    100% { opacity: 0;   transform: scale(1.1); }
}

/* ---- chips: мета-информация (биржа, маркет, период, обновлено) ---- */

.sd-infobar__chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    flex: 1;
    min-width: 0;
    font-size: 12px;
    color: var(--muted);
}

/* ---- styled filter chips (синие прямоугольники) ---- */

.sd-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(43, 108, 176, 0.12);
    border: 1px solid rgba(43, 108, 176, 0.30);
    border-radius: 999px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.92);
    white-space: nowrap;
    font-family: var(--mono);
}

.sd-filter-chip--muted {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border);
    color: var(--muted);
}

/* ---- панель параметров ---- */

.sd-params {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: var(--panel);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
}

.sd-params__body {
    padding: 10px 12px 12px;
}

.sd-params__row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.sd-params__field {
    display: flex;
    flex-direction: column;
    min-width: 120px;
}

.sd-params__field label {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 3px;
}

.sd-params__field select {
    height: 28px;
    line-height: 28px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0 8px;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
}

.sd-params__field select:focus {
    border-color: #2b6cb0;
}

.sd-params__field select option {
    background: var(--bg);
    color: var(--text);
}

.sd-params__apply {
    height: 28px;
    padding: 0 16px;
    background: #2b6cb0;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.sd-params__apply:hover {
    background: #2c5f9e;
}

.sd-params__apply:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ---------------- status ---------------- */

.sd-status {
    margin: 12px 14px 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border2);
    color: var(--muted);
}
.sd-status--error {
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.10);
    color: rgba(255, 255, 255, 0.92);
}

/* ---------------- layout ---------------- */

.sd-layout {
    margin: 14px 14px 0;
    display: grid;
    gap: 14px;
}

.sd-panel {
    background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.02));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.sd-panel__head {
    padding: 14px 14px 10px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 14px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border2);
}

/* Заголовок прижат влево (забирает свободное место) */
.sd-panel__titleblock { margin-right: auto; }

.sd-panel__kicker {
    font-size: 12px;
    letter-spacing: 1px;
    font-weight: 700;
}
.sd-panel__subtitle { margin-top: 4px; font-size: 12px; color: var(--muted); }

.sd-panel__sentiments {
    margin-left: auto;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}


/* линейный индикатор */
.sd-sentiment { min-width: 190px; }
.sd-sentiment__top { display: flex; align-items: baseline; gap: 10px; }
.sd-sentiment__value { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.sd-sentiment__label { font-size: 11px; color: var(--muted); letter-spacing: 0.6px; }

.sd-sentiment__bar {
    margin-top: 8px;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border2);
    background: rgba(0,0,0,0.22);
    display: flex;
}

.sd-sentiment__seg { height: 100%; }
.sd-sentiment__seg--up { background: rgba(34, 197, 94, 0.75); }
.sd-sentiment__seg--down { background: rgba(239, 68, 68, 0.70); }

.sd-sentiment__legend {
    margin-top: 8px;
    display: grid;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}
.sd-sentiment__row { display: flex; align-items: center; gap: 8px; }
.sd-dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.sd-dot--up { background: var(--up); }
.sd-dot--down { background: var(--down); }
.sd-sentiment__num { font-family: var(--mono); font-weight: 600; color: var(--text); font-size: 14px; }

.sd-strip {
    padding: 12px 14px 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

/* Чипы внутри header (sd-panel__chips) — inline, между title и sentiments */
.sd-panel__chips {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.sd-panel__chips .sd-chip {
    min-width: auto;
    padding: 6px 10px;
}

/* компактнее: второй индикатор (объёмы) */
.sd-sentiment--volume .sd-sentiment__label { letter-spacing: 0.4px; }

/* ---------------- sections + tops ---------------- */

.sd-sections,
.sd-tops {
    padding: 12px 14px 0;
}

.sd-section-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.sd-card {
    border-radius: var(--radius);
    background: rgba(0,0,0,0.16);
    border: 1px solid var(--border2);
    padding: 12px;
}

.sd-card__title {
    font-size: 12px;
    letter-spacing: 0.6px;
    font-weight: 700;
    margin: 0 0 10px;
}

.sd-metricrow {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 7px 0;
    border-top: 1px solid var(--border2);
}
.sd-metricrow:first-of-type { border-top: 0; }

.sd-metricrow__label {
    font-size: 12px;
    color: var(--muted);
}

.sd-metricrow__value {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 650;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sd-badge {
    font-family: var(--mono);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 999px;
    border: 1px solid var(--border2);
    color: var(--muted);
}

.sd-go {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 10px;
    border: 1px solid var(--border2);
    background: rgba(255,255,255,0.03);
    color: var(--text);
    text-decoration: none;
}

.sd-top-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.sd-toplist {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

.sd-topitem {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.sd-topitem__symbol {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
}

.sd-topitem__value {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.sd-chip {
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: rgba(0,0,0,0.16);
    border: 1px solid var(--border2);
}
.sd-chip__label { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.sd-chip__value {
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.1px;
}

/* ---- ссылка на график (SVG-иконка) ---- */

.sd-go {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    color: var(--muted);
    text-decoration: none;
    flex-shrink: 0;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.sd-go:hover {
    border-color: #2b6cb0;
    background: rgba(43, 108, 176, 0.15);
    color: var(--text);
}

.sd-go.is-hidden { display: none; }

/* ---------------- chart ---------------- */

.sd-panel__chartwrap { padding: 10px 14px 0; }

.sd-chart {
    height: 170px;
    border-radius: var(--radius-sm);
    padding: 6px;
    background:
        linear-gradient(180deg, rgba(0,0,0,0.22), rgba(0,0,0,0.28));
    border: 1px solid var(--border2);
}

.sd-chart__frame {
    height: 100%;
    display: grid;
    /*
      Колонка под ось Y расширяется под длину подписи.

      Важно:
        - ось Y не должна накладываться на бары
        - подписи не должны укорачиваться "..." при больших значениях
        - расстояние между осью Y и барами фиксируется через gap
    */
    grid-template-columns: 60px 1fr;
    grid-template-rows: 1fr 22px;
    gap: 4px;
}

.sd-chart__axis--y { grid-column: 1; grid-row: 1; position: relative; color: var(--muted); font-size: 10px; }
.sd-chart__axis--x { grid-column: 2; grid-row: 2; position: relative; color: var(--muted); font-size: 10px; }

.sd-chart__axis--x {
    /* Небольшой внутренний отступ, чтобы крайние подписи не упирались в границы */
    padding-right: 2px;
    padding-left: 2px;
}

.sd-chart__plot {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    overflow: hidden;

    background-image:
        linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.04) 1px, transparent 1px);
    background-size: 10% 25%;
    border-radius: 8px;
}

.sd-chart__slot {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    position: relative;
}

.sd-chart__bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;

    display: block;
    border-radius: 6px 6px 4px 4px;
    opacity: 0.55;
}

.sd-chart__bar--down {
    background: rgba(239, 68, 68, 0.68);
}

.sd-chart__bar--up {
    left: 0;
    right: 0;
    background: rgba(34, 197, 94, 0.62);
    mix-blend-mode: screen;
    box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.25);
}

/*
  Подписи осей:
  - X: в нормальном потоке (flex), чтобы не было наложений и "слипания" слева.
  - Y: абсолютное позиционирование (верх/низ), чтобы метки всегда были у краёв.
*/
.sd-chart__tick {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--mono);
}

/*
  Ось Y не должна обрезать значения по ширине.
  Ширина колонки под ось считается через max-content в grid,
  поэтому здесь важно отключить ellipsis.
*/
.sd-chart__axis--y .sd-chart__tick {
    position: absolute;
    left: 0;
    transform: none;
    max-width: 100%;
    overflow: visible;
    text-overflow: clip;
}

.sd-chart__axis--x {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    overflow: hidden;
}

.sd-chart__axis--x .sd-chart__tick {
    position: relative;
    transform: none;
    max-width: 22%;
}

.sd-chart__axis--x .sd-chart__tick--x-left { text-align: left; }
.sd-chart__axis--x .sd-chart__tick--x-mid { text-align: center; }
.sd-chart__axis--x .sd-chart__tick--x-right { text-align: right; }

.sd-chart__tick--top { top: 0; }
.sd-chart__tick--bottom { bottom: 0; }

.sd-chart--empty { opacity: 0.6; }

/* ---------------- metrics grid ---------------- */

.sd-grid--v3 {
    padding: 12px 14px 14px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.sd-metric {
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: rgba(0,0,0,0.16);
    border: 1px solid var(--border2);
}
.sd-metric__label { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.sd-metric__value {
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 600;
}
.sd-metric__value-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.sd-metric__go {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    text-decoration: none;
    color: rgba(255,255,255,0.92);
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
}

@media (max-width: 980px) {
    .sd-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sd-section-grid { grid-template-columns: 1fr; }
    .sd-top-grid { grid-template-columns: 1fr; }
    .sd-grid--v3 { grid-template-columns: 1fr; }
    .sd-chart__frame { grid-template-columns: 60px 1fr; }
    .sd-select__control { min-width: 110px; }
}


.sd-topitem__range {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    margin-left: 8px;
}

/* (N) детектов рядом с % использует тот же стиль, что и диапазон */

/* TOP-5: компактный индикатор Up/Down на строке */
.sd-topitem__main { font-weight: 600; color: var(--text); }

.sd-miniud {
    width: 56px;
    height: 6px;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border2);
    background: rgba(0,0,0,0.22);
    display: inline-flex;
}
.sd-miniud__seg { height: 100%; }
.sd-miniud__seg--up { background: rgba(34, 197, 94, 0.75); }
.sd-miniud__seg--down { background: rgba(239, 68, 68, 0.70); }

/* TOP-5: диапазон для разброса использует .sd-topitem__range */

/* ============================================================
   Гистограмма дистанции (diverging bar chart)
   Бары растут от нулевой линии: вверх — зелёные, вниз — красные.
   ============================================================ */

.sd-dist-chart {
    height: 330px;
    border-radius: var(--radius-sm);
    padding: 6px;
    background:
        linear-gradient(180deg, rgba(0,0,0,0.22), rgba(0,0,0,0.28));
    border: 1px solid var(--border2);
}

.sd-dist-chart__frame {
    height: 100%;
    display: grid;
    grid-template-columns: 60px 1fr;
    grid-template-rows: 1fr 22px;
    gap: 4px;
}

/* Обёртка plot + нулевая линия — позиционирует линию по центру */
.sd-dist-chart__plotwrap {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
}

.sd-dist-chart__plot {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 2px;

    background-image:
        linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.04) 1px, transparent 1px);
    background-size: 10% 25%;
}

/* Горизонтальная нулевая линия по центру */
.sd-dist-chart__zero {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 0;
    border-top: 1px dashed rgba(255, 255, 255, 0.25);
    pointer-events: none;
}

/* Один временной слот */
.sd-dist-chart__slot {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Верхняя и нижняя половины слота */
.sd-dist-chart__half {
    flex: none;
    position: relative;
    min-height: 0;
}

/* Верхняя: бары выравниваются к нижнему краю (к нулевой линии) */
.sd-dist-chart__half--top {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: stretch;
}

/* Нижняя: бары выравниваются к верхнему краю (к нулевой линии) */
.sd-dist-chart__half--bottom {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
}

/* Бар средней дистанции (сплошной) */
.sd-dist-chart__bar {
    border-radius: 4px;
    min-height: 1px;
    flex-shrink: 0;
}

.sd-dist-chart__bar--up {
    background: rgba(34, 197, 94, 0.62);
    box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.25);
}

.sd-dist-chart__bar--down {
    background: rgba(239, 68, 68, 0.68);
    box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.2);
}

/* Силуэт максимальной дистанции (пунктирная граница, прозрачный) */
.sd-dist-chart__ghost {
    position: absolute;
    left: 0;
    right: 0;
    border-radius: 4px;
    background: transparent;
    pointer-events: none;
}

.sd-dist-chart__ghost--up {
    bottom: 0;
    border: 1px dashed rgba(255, 255, 255, 0.30);
}

.sd-dist-chart__ghost--down {
    top: 0;
    border: 1px dashed rgba(255, 255, 255, 0.30);
}

/* Подписи количества детектов */
.sd-dist-chart__count {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    font-family: var(--mono);
    font-size: 8px;
    font-weight: 600;
    line-height: 1;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
}

.sd-dist-chart__count--up {
    bottom: 100%;
    margin-bottom: 1px;
    color: var(--up);
}

.sd-dist-chart__count--down {
    top: 100%;
    margin-top: 1px;
    color: var(--down);
}

/* Оси */
.sd-dist-chart__axis--y {
    grid-column: 1;
    grid-row: 1;
    position: relative;
    color: var(--muted);
    font-size: 10px;
}

.sd-dist-chart__axis--x {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    padding-right: 2px;
    padding-left: 2px;
}

.sd-dist-chart__tick {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--mono);
}

/* Y-ось: абсолютное позиционирование (верх / середина / низ) */
.sd-dist-chart__axis--y .sd-dist-chart__tick {
    position: absolute;
    left: 0;
    max-width: 100%;
    overflow: visible;
    text-overflow: clip;
}

.sd-dist-chart__tick--top { top: 0; }
.sd-dist-chart__tick--mid { top: 50%; transform: translateY(-50%); }
.sd-dist-chart__tick--bottom { bottom: 0; }

/* X-ось */
.sd-dist-chart__axis--x .sd-dist-chart__tick {
    position: relative;
    max-width: 22%;
}

.sd-dist-chart__tick--x-left { text-align: left; }
.sd-dist-chart__tick--x-mid { text-align: center; }
.sd-dist-chart__tick--x-right { text-align: right; }

.sd-dist-chart--empty { opacity: 0.6; }

@media (max-width: 980px) {
    .sd-dist-chart__frame { grid-template-columns: minmax(25px, max-content) 1fr; }
}
