:root {
    /* Заполняется из Telegram.WebApp.themeParams (telegram.ts). Дефолты — тёмная тема. */
    --bg: #17212b;
    --text: #ffffff;
    --hint: #708499;
    --link: #6ab7ff;
    --button: #5288c1;
    --button-text: #ffffff;
    --secondary-bg: #232e3c;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    overscroll-behavior: none;
}

#app {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
}

.screen--center {
    justify-content: center;
    align-items: stretch;
}

h1 {
    font-size: 20px;
    margin: 0 0 8px;
}

.hint {
    color: var(--hint);
    font-size: 14px;
}

.error {
    color: #ff6b6b;
    font-size: 14px;
    min-height: 18px;
}

input[type='password'],
input[type='text'] {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

button {
    font-size: 16px;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    background: var(--button);
    color: var(--button-text);
    cursor: pointer;
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

button.secondary {
    background: var(--secondary-bg);
    color: var(--text);
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

.device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px;
    border-radius: 12px;
    background: var(--secondary-bg);
    cursor: pointer;
}

.device-item--disabled {
    opacity: 0.55;
    cursor: default;
}

.device-item__name {
    font-size: 16px;
    font-weight: 600;
}

.device-item__meta {
    color: var(--hint);
    font-size: 13px;
    margin-top: 2px;
}

.badge {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--hint);
    white-space: nowrap;
}

.badge--online {
    color: #4caf50;
}
.badge--offline {
    color: #ff6b6b;
}
.badge--busy {
    color: #ffb74d;
}

/* ---- Экран стрима ---- */
.stream {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
}

/* Панель открыта: экран устройства уходит из-под чёлки и кнопок Telegram, верх становится нажимаемым. */
.stream--inset {
    padding-top: calc(
        var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px)
    );
}

.stream__video-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #000;
    touch-action: none;
    /* На компьютере курсор показывает, что область экрана живая и принимает клики. */
    cursor: pointer;
    /* Колесо мыши уходит на устройство, страница мини-приложения от него не едет. */
    overscroll-behavior: contain;
}

.stream__video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.stream__status {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    text-align: center;
    color: #fff;
    font-size: 15px;
    padding: 0 24px;
    pointer-events: none;
}

.stream__bar {
    display: flex;
    gap: 8px;
    padding: 8px calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom))
        calc(8px + env(safe-area-inset-left));
    background: rgba(0, 0, 0, 0.6);
    align-items: center;
}

.stream__bar-side {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    gap: 8px;
}

.stream__bar-side--right {
    justify-content: flex-end;
}

.stream__bar > button {
    flex: 0 0 28%;
}

.stream__bar-side button {
    flex: 0 1 50%;
}

.stream__bar button {
    padding: 10px 8px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.stream__bar--hidden {
    display: none;
}

/* Ручка панели: маленькая, полупрозрачная, у правого края — почти не перекрывает экран. */
.stream__bar-toggle {
    position: absolute;
    right: calc(4px + env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 44px;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.35);
    color: rgba(255, 255, 255, 0.8);
    touch-action: manipulation;
}

.stream__rtt {
    position: absolute;
    top: calc(6px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
    font-size: 12px;
    color: #7fff7f;
    background: rgba(0, 0, 0, 0.45);
    padding: 2px 6px;
    border-radius: 6px;
    pointer-events: none;
}

/* Поле-приёмник фокуса для физической клавиатуры: невидимо, но внутри экрана —
   при focus() браузер не прокручивает страницу к нему, как было бы при left:-9999px. */
.hidden-input {
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    outline: none;
    pointer-events: none;
}

/* Подсказка-кнопка поверх видео: браузер на компьютере не даёт звук без жеста. */
.stream__unmute {
    position: absolute;
    left: 50%;
    bottom: 16%;
    transform: translateX(-50%);
    z-index: 6;
    padding: 12px 18px;
    border: 0;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    color: #fff;
    background: rgba(20, 20, 20, 0.88);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    touch-action: manipulation;
}

.stream__unmute[hidden] {
    display: none;
}

.stream__paste {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    display: flex;
    gap: 6px;
    padding: 8px;
    border-radius: 12px;
    background: rgba(20, 20, 20, 0.92);
    z-index: 5;
}

.stream__paste[hidden] {
    display: none;
}

.stream__paste input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: #111;
    color: #fff;
    font-size: 16px;
}

.stream__pin {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    padding: 8px;
    border-radius: 12px;
    background: rgba(20, 20, 20, 0.92);
    z-index: 5;
}

.stream__pin[hidden] {
    display: none;
}

.stream__pin-hint {
    margin-bottom: 6px;
    text-align: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
}

.stream__pin-count {
    margin-bottom: 8px;
    text-align: center;
    font-size: 16px;
    letter-spacing: 2px;
    color: #fff;
    min-height: 20px;
}

.stream__pin-keys {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.stream__pin-keys button {
    padding: 12px 0;
    font-size: 18px;
}

.stream__rtt--good {
    color: #6fdc8c;
}

.stream__rtt--mid {
    color: #f1c21b;
}

.stream__rtt--bad {
    color: #ff8389;
}

.analytics h2 {
    font-size: 15px;
    margin: 16px 0 8px;
}

.analytics__scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.analytics__table {
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.analytics__table th,
.analytics__table td {
    padding: 6px 8px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.25);
    text-align: left;
}

.analytics__table td:last-child {
    white-space: normal;
    min-width: 180px;
}

.analytics__row--bad td {
    background: rgba(255, 80, 80, 0.14);
}
