:root {
    color-scheme: light dark;

    --bg: #f5f5f3;
    --panel: #ffffff;
    --text: #191a1c;
    --muted: #727780;
    --line: #e7e7e3;
    --grid: rgba(25, 26, 28, 0.07);
    --accent: #1f9d63;
    --ok: #1f9d63;
    --fail: #d93a3a;
    /* Пунктир «данные недоступны»: белый на тёмном фоне, нейтральный на светлом. */
    --nodata: #9aa0a8;
    --shadow: 0 10px 30px rgba(25, 26, 28, 0.10);

    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e0f11;
        --panel: #15171a;
        --text: #eceef0;
        --muted: #7f858d;
        --line: #24272b;
        --grid: rgba(255, 255, 255, 0.06);
        --accent: #34b37a;
        --ok: #34b37a;
        --fail: #ff6b6b;
        --nodata: #ffffff;
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.has-expanded {
    overflow: hidden;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.brand-dot {
    position: relative;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

.brand-dot::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.13;
}

.topbar-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.updated {
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--muted);
}

.icon-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

.icon-btn svg {
    width: 15px;
    height: 15px;
}

.icon-btn.is-busy svg {
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------- контент */

.content {
    max-width: 960px;
    margin: 0 auto;
    padding: 28px 24px 48px;
}

.charts {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.hint {
    margin: 20px 0 0;
    color: var(--muted);
    font-size: 11.5px;
    text-align: center;
}

/* ---------------------------------------------------------------- панель */

.panel {
    padding: 18px 20px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.panel-heading {
    min-width: 0;
}

.panel-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.panel-stats {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

.panel-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
}

.panel-meta {
    color: var(--muted);
    font-size: 11.5px;
    white-space: nowrap;
}

.expand-btn {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    color: var(--muted);
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.expand-btn:hover {
    color: var(--text);
    background: var(--grid);
}

.expand-btn svg {
    width: 13px;
    height: 13px;
}

.expand-btn .icon-collapse {
    display: none;
}

.panel.is-expanded .expand-btn .icon-collapse {
    display: block;
}

.panel.is-expanded .expand-btn .icon-expand {
    display: none;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    color: var(--muted);
    font-size: 11.5px;
    min-width: 0;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-dot.is-fail {
    background: var(--fail);
}

.legend-dot.is-time {
    background: var(--ok);
}

.legend-dash {
    display: inline-block;
    width: 15px;
    height: 0;
    border-top: 1.5px dashed var(--nodata);
}

/* ------------------------------------------------------- переключатель периода */

.panel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px 14px;
    flex-wrap: wrap;
    margin: 10px 0 6px;
}

.range-switch {
    display: inline-flex;
    flex: none;
    gap: 2px;
    margin-left: auto;
    padding: 2px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 9px;
}

.range-btn {
    padding: 3px 9px;
    color: var(--muted);
    font: inherit;
    font-size: 11px;
    line-height: 1.3;
    white-space: nowrap;
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.range-btn:hover {
    color: var(--text);
}

.range-btn[aria-pressed="true"] {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 9%, var(--panel));
}

.range-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ----------------------------------------------------------------- график */

.chart {
    position: relative;
    height: 236px;
    border-radius: 9px;
    cursor: zoom-in;
}

.chart:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.chart-svg {
    display: block;
    width: 100%;
    height: 100%;
}

.chart-svg text {
    font-family: inherit;
    font-size: 10.5px;
    fill: var(--muted);
    font-variant-numeric: tabular-nums;
}

.chart-svg .axis-unit {
    font-size: 9.5px;
    opacity: 0.75;
}

.chart-svg .grid-line {
    stroke: var(--grid);
    stroke-width: 1;
}

.chart-svg .grid-line.is-base {
    stroke: var(--line);
}

.chart-svg .area-time {
    fill: var(--ok);
    fill-opacity: 0.10;
    stroke: none;
}

.chart-svg .area-fail {
    fill: var(--fail);
    fill-opacity: 0.16;
    stroke: none;
}

.chart-svg .line-time {
    fill: none;
    stroke: var(--ok);
    stroke-width: 1.8;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-svg .line-fail {
    fill: none;
    stroke: var(--fail);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-svg .fail-dot {
    fill: var(--fail);
}

/* Разрыв в данных: пунктирная перемычка между соседними отрезками. */
.chart-svg .gap-line {
    fill: none;
    stroke: var(--nodata);
    stroke-width: 1.4;
    stroke-dasharray: 4 4;
}

.chart-svg .crosshair {
    display: none;
    stroke: var(--muted);
    stroke-width: 1;
    stroke-dasharray: 3 3;
    opacity: 0.6;
}

.chart-svg .crosshair.is-on {
    display: block;
}

.chart-svg .hover-dot {
    display: none;
    stroke: var(--panel);
    stroke-width: 1.5;
}

.chart-svg .hover-dot.is-on {
    display: block;
}

.chart-svg .hover-dot.is-fail {
    fill: var(--fail);
}

.chart-svg .hover-dot.is-time {
    fill: var(--ok);
}

/* --------------------------------------------------------- состояния */

.chart-state {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 0 20px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.chart-state[hidden] {
    display: none;
}

.state-icon svg {
    display: block;
    width: 22px;
    height: 22px;
    opacity: 0.55;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--line);
    border-top-color: var(--muted);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.retry-btn {
    margin-top: 2px;
    padding: 5px 12px;
    color: var(--text);
    font: inherit;
    font-size: 11.5px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}

.retry-btn:hover {
    border-color: var(--muted);
}

/* --------------------------------------------------------------- tooltip */

.tooltip {
    position: fixed;
    z-index: 100;
    min-width: 178px;
    padding: 9px 11px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    font-size: 12px;
    pointer-events: none;
}

.tooltip[hidden] {
    display: none;
}

.tip-time {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.tip-row {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.tip-row + .tip-row {
    margin-top: 2px;
}

.tip-row b {
    margin-left: auto;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tip-sub {
    margin-left: 6px;
    color: var(--muted);
    font-size: 10.5px;
}

.tip-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex: none;
}

.tip-dot.is-fail {
    background: var(--fail);
}

.tip-dot.is-time {
    background: var(--ok);
}

.tip-dash {
    flex: none;
    width: 11px;
    height: 0;
    border-top: 1.5px dashed var(--nodata);
}

.tip-row.is-nodata {
    color: var(--muted);
}

.tip-row.is-nodata span {
    margin-top: 1px;
}

/* -------------------------------------------------------------- разворот */

.panel.is-expanded {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    padding: 18px 24px 22px;
    border-radius: 0;
    border: none;
    animation: expand-in 0.16s ease-out;
}

.panel.is-expanded .panel-title {
    font-size: 16px;
}

.panel.is-expanded .chart {
    flex: 1;
    height: auto;
    min-height: 0;
    margin-top: 4px;
    cursor: zoom-out;
}

.panel.is-expanded .panel-bar {
    margin-bottom: 4px;
}

@keyframes expand-in {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

/* -------------------------------------------------------------- адаптив */

@media (max-width: 640px) {
    .topbar-inner {
        padding: 14px 20px;
    }

    .content {
        padding: 20px 16px 40px;
    }

    .panel {
        padding: 14px 14px 12px;
    }

    .panel-meta {
        display: none;
    }

    .range-btn {
        padding: 3px 7px;
        font-size: 10.5px;
    }

    .chart {
        height: 196px;
    }

    .panel.is-expanded {
        padding: 14px;
    }
}

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