:root {
    color-scheme: dark;
    --tv-bg: #050914;
    --tv-panel: rgba(13, 24, 45, 0.86);
    --tv-line: rgba(137, 168, 207, 0.16);
    --tv-text: #f4f8ff;
    --tv-muted: #89a0bd;
    --tv-cyan: #43d9f8;
    --tv-blue: #5b8cff;
    --tv-green: #5fe0ad;
    --tv-amber: #ffc861;
    --tv-violet: #a889ff;
    --burn-x: 0px;
    --burn-y: 0px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    width: 100%;
    min-height: 100%;
    background: var(--tv-bg);
    color: var(--tv-text);
    font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
    overflow: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 12% 10%, rgba(52, 120, 255, 0.18), transparent 35%),
        radial-gradient(circle at 78% 0%, rgba(55, 220, 244, 0.1), transparent 32%),
        linear-gradient(135deg, #050914 0%, #071121 50%, #07101c 100%);
    pointer-events: none;
}

.tv-shell {
    position: relative;
    z-index: 1;
    height: 100vh;
    min-height: 0;
    width: 100vw;
    padding: clamp(18px, 1.45vw, 30px) clamp(22px, 1.8vw, 38px);
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    gap: clamp(10px, 0.85vw, 18px);
    transform: translate(var(--burn-x), var(--burn-y));
    transition: transform 2s ease;
}

.tv-header, .tv-statusbar, .tv-footer, .tv-panel-heading, .tv-controls, .tv-legend, .tv-source-list {
    display: flex;
    align-items: center;
}

.tv-header { justify-content: space-between; }
.tv-eyebrow, .tv-panel-kicker {
    margin: 0 0 4px;
    color: var(--tv-cyan);
    font-size: clamp(10px, 0.68vw, 14px);
    font-weight: 700;
    letter-spacing: 0.18em;
}
.tv-header h1 {
    margin: 0;
    font-size: clamp(28px, 2.2vw, 46px);
    line-height: 1.08;
    letter-spacing: 0.02em;
}
.tv-header-meta { text-align: right; }
.tv-clock { font-size: clamp(26px, 2vw, 42px); font-variant-numeric: tabular-nums; font-weight: 700; }
.tv-date { color: var(--tv-muted); font-size: clamp(12px, 0.86vw, 18px); }

.tv-statusbar {
    justify-content: space-between;
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid var(--tv-line);
    border-radius: 10px;
    background: rgba(8, 18, 34, 0.68);
    color: var(--tv-muted);
    font-size: clamp(11px, 0.74vw, 15px);
}
.tv-live-state { display: flex; align-items: center; gap: 8px; color: var(--tv-green); }
.tv-live-state[data-state="partial"] { color: var(--tv-amber); }
.tv-live-state[data-state="error"] { color: #ff7d86; }
.tv-live-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.tv-status-meta { display: flex; gap: 26px; }
.tv-status-meta strong { color: var(--tv-text); font-variant-numeric: tabular-nums; }

.tv-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(10px, 0.85vw, 18px);
}
.tv-kpi-grid[data-count="1"] { grid-template-columns: minmax(0, 1fr); }
.tv-kpi-grid[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tv-kpi-grid[data-count="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tv-kpi, .tv-panel {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--tv-line);
    background: linear-gradient(145deg, rgba(17, 32, 58, 0.9), rgba(8, 18, 34, 0.82));
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.18);
}
.tv-kpi { min-height: clamp(110px, 9.1vh, 160px); border-radius: 16px; padding: clamp(14px, 1.15vw, 24px); display: flex; flex-direction: column; justify-content: space-between; }
.tv-kpi::after { content: ""; position: absolute; inset: auto -30% -80% 15%; height: 130%; background: radial-gradient(circle, currentColor 0%, transparent 65%); opacity: 0.07; }
.tv-kpi-payment { color: var(--tv-cyan); }
.tv-kpi-operator { color: var(--tv-blue); }
.tv-kpi-support { color: var(--tv-green); }
.tv-kpi-transfer { color: var(--tv-violet); }
.tv-kpi-label { color: var(--tv-muted); font-size: clamp(13px, 0.88vw, 18px); }
.tv-kpi-value { color: var(--tv-text); font-size: clamp(36px, 3.1vw, 64px); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.04em; }
.tv-kpi-note { color: currentColor; font-size: clamp(10px, 0.68vw, 14px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tv-content-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: clamp(10px, 0.85vw, 18px);
}
.tv-content-grid[data-count="1"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.tv-content-grid[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); }
.tv-content-grid[data-count="3"] { grid-template-rows: repeat(2, minmax(0, 1fr)); }
.tv-panel { min-height: 0; border-radius: 16px; padding: clamp(14px, 1.1vw, 22px); display: flex; flex-direction: column; }
.tv-panel-heading { justify-content: space-between; min-height: 42px; margin-bottom: 8px; }
.tv-panel h2 { margin: 0; font-size: clamp(17px, 1.2vw, 25px); }
.tv-legend { gap: 14px; color: var(--tv-muted); font-size: clamp(10px, 0.64vw, 13px); }
.tv-legend span { display: inline-flex; align-items: center; gap: 5px; }
.tv-legend i { width: 18px; height: 3px; border-radius: 3px; }
.legend-payment { background: var(--tv-cyan); }
.legend-operator { background: var(--tv-blue); }
.legend-handled { background: var(--tv-green); }
.legend-transferred { background: var(--tv-violet); }
.legend-payment-new { background: var(--tv-cyan); }
.legend-payment-renewal { background: var(--tv-amber); }
.tv-chart-wrap { flex: 1; min-height: 0; position: relative; }
.tv-chart-wrap canvas { width: 100%; height: 100%; display: block; }

.tv-footer { justify-content: space-between; gap: 20px; min-height: 38px; }
.tv-source-list { gap: 10px; min-width: 0; overflow: hidden; }
.tv-source-badge { border: 1px solid var(--tv-line); border-radius: 999px; padding: 5px 9px; color: var(--tv-muted); font-size: clamp(9px, 0.62vw, 12px); white-space: nowrap; }
.tv-source-badge::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--tv-green); }
.tv-source-badge[data-state="delayed"]::before { background: var(--tv-amber); }
.tv-source-badge[data-state="unavailable"]::before { background: #ff7d86; }
.tv-controls { gap: 8px; }
.tv-controls button { border: 1px solid var(--tv-line); border-radius: 8px; background: rgba(16, 31, 53, 0.9); color: #d9e7f7; padding: 7px 12px; cursor: pointer; font-size: 12px; }
.tv-controls button:disabled { cursor: wait; opacity: 0.72; }
.tv-refresh-feedback { min-width: 0; max-width: 260px; overflow: hidden; color: var(--tv-muted); font-size: clamp(9px, 0.62vw, 12px); text-overflow: ellipsis; white-space: nowrap; }
.tv-refresh-feedback[data-state="success"] { color: var(--tv-green); }
.tv-refresh-feedback[data-state="error"] { color: #ff7d86; }
#btn-refresh { display: inline-flex; align-items: center; gap: 6px; }
.tv-refresh-icon { display: inline-block; font-size: 15px; line-height: 1; transform-origin: center; }
#btn-refresh.is-refreshing .tv-refresh-icon { animation: tv-refresh-spin 0.8s linear infinite; }
.tv-controls button:focus-visible { outline: 2px solid var(--tv-cyan); outline-offset: 2px; }

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

.tv-pairing { position: fixed; z-index: 4; inset: 0; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at center, #102342, #050914 65%); }
.tv-pairing[hidden] { display: none; }
.tv-pairing-card { width: min(620px, 90vw); padding: 44px; border: 1px solid var(--tv-line); border-radius: 22px; background: var(--tv-panel); text-align: center; }
.tv-pairing-card h1 { margin: 8px 0 14px; font-size: 34px; }
.tv-pairing-card p { color: var(--tv-muted); line-height: 1.8; }

@media (max-aspect-ratio: 4/3), (max-width: 980px) {
    html, body { overflow: auto; }
    .tv-shell { min-height: 100vh; height: auto; }
    .tv-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tv-content-grid { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: 340px; }
    .tv-footer { align-items: flex-start; flex-direction: column; }
}

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