: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;
}

.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 button {
    flex: 1;
    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;
}

.hidden-input {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}
