* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #050816;
    color: #e5e7eb;
    margin: 0;
}

/* Поддержка динамического viewport на iOS */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

@supports (height: 100dvh) {
    .app {
        height: 100dvh;
    }
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid rgba(148, 163, 184, 0.3);
    backdrop-filter: blur(10px);
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
}

.logo {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.04em;
    color: #a855f7;
}

.header-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.user-name {
    font-size: 14px;
    color: #cbd5f5;
}

.user-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-status select {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 8px;
    padding: 4px 8px;
    color: #e5e7eb;
    font-size: 13px;
}

/* Бейдж с ID и IP */
.user-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    background: rgba(15, 23, 42, 0.9);
    border-radius: 999px;
    padding: 2px 8px;
    border: 1px solid rgba(148, 163, 184, 0.4);
}

.user-badge-item {
    color: #9ca3af;
}

.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 260px;
    gap: 12px;
    padding: 12px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
}

/* Левая и правая колонка */
.sidebar-left,
.sidebar-right {
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.95), rgba(30, 64, 175, 0.5));
    border-radius: 18px;
    padding: 12px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #e5e7eb;
}

.sidebar-title-secondary {
    margin-top: 10px;
}

.users-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Элементы списка пользователей */
.user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 10px;
    cursor: pointer;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.user-item:hover {
    background: rgba(30, 64, 175, 0.7);
    border-color: rgba(129, 140, 248, 0.7);
    transform: translateY(-1px);
}

.user-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 20%, #a855f7, #2563eb);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #e5e7eb;
    flex-shrink: 0;
}

.user-name-text {
    font-size: 14px;
    color: #f9fafb;
}

.user-status-pill {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.9);
    color: #9ca3af;
}

/* Статусы */
.status-online {
    color: #4ade80;
}

.status-away {
    color: #facc15;
}

.status-offline {
    color: #9ca3af;
}

/* Центральная панель */
.center-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.call-panel {
    flex: 1;
    background: radial-gradient(circle at top, rgba(56, 189, 248, 0.2), rgba(15, 23, 42, 0.98));
    border-radius: 18px;
    border: 1px solid rgba(129, 140, 248, 0.6);
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.call-peer-info {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.call-peer-name {
    font-size: 16px;
    font-weight: 600;
    color: #e5e7eb;
}

.call-peer-status {
    font-size: 13px;
    color: #9ca3af;
}

/* Полоса выбора устройств */
.device-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.device-select {
    flex: 1 1 0;
    min-width: 120px;
    background: rgba(15, 23, 42, 0.9);
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    padding: 4px 8px;
    font-size: 12px;
    color: #e5e7eb;
}

/* Видео */
.video-wrapper {
    position: relative;
    flex: 1;
    border-radius: 14px;
    background: radial-gradient(circle at center, rgba(251, 191, 36, 0.15), rgba(15, 23, 42, 0.95));
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.6);
    min-height: 160px;
}

.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #020617;
}

.local-video {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 120px;
    height: 80px;
    border-radius: 12px;
    border: 2px solid rgba(129, 140, 248, 0.9);
    object-fit: cover;
    background: #020617;
}

/* Волны */
.voice-wave {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    height: 24px;
    align-items: flex-end;
    padding: 0 4px;
}

.wave-bar {
    width: 4px;
    border-radius: 2px 2px 0 0;
    background: #22d3ee;
    height: 4px;
    transition: height 0.08s linear;
}

/* Кнопки звонка */
.call-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    background: rgba(31, 41, 55, 0.9);
    color: #e5e7eb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.1s ease;
    touch-action: manipulation;
}

.btn:hover {
    background: rgba(55, 65, 81, 0.95);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.6);
}

.btn.primary {
    background: linear-gradient(135deg, #6366f1, #a855f7);
}

.btn.primary:hover {
    background: linear-gradient(135deg, #4f46e5, #9333ea);
}

.btn.small {
    padding: 6px 10px;
    font-size: 12px;
}

.call-btn {
    min-width: 80px;
}

.hangup {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
}

.hangup:hover {
    background: linear-gradient(135deg, #dc2626, #991b1b);
}

/* Чат */
.chat-panel {
    margin-top: 8px;
    background: rgba(15, 23, 42, 0.96);
    border-radius: 18px;
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    display: flex;
    flex-direction: column;
    max-height: 260px;
    min-height: 120px;
}

.chat-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
    margin-bottom: 6px;
}

.chat-msg {
    max-width: 80%;
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 13px;
}

.chat-msg-me {
    align-self: flex-end;
    background: rgba(79, 70, 229, 0.9);
}

.chat-msg-peer {
    align-self: flex-start;
    background: rgba(30, 64, 175, 0.9);
}

/* Текст и время в сообщении */
.chat-msg-text {
    margin-bottom: 2px;
    word-wrap: break-word;
}

.chat-msg-time {
    font-size: 10px;
    opacity: 0.7;
    text-align: right;
}

.chat-input-row {
    display: flex;
    gap: 6px;
}

.chat-input-row input[type="text"] {
    flex: 1;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    padding: 6px 10px;
    font-size: 13px;
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
}

.hidden-input {
    display: none;
}

/* Правая колонка — метрики и история */
.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 13px;
}

.metric-label {
    color: #9ca3af;
}

.metric-value {
    font-weight: 500;
}

/* История звонков */
.call-history {
    flex: 1;
    margin-top: 6px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.call-history-empty {
    font-size: 12px;
    color: #9ca3af;
}

.call-history-item {
    border-radius: 10px;
    padding: 6px 8px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.5);
    font-size: 12px;
}

.call-history-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}

.chi-peer {
    font-weight: 500;
    color: #e5e7eb;
}

.chi-time {
    color: #9ca3af;
}

.call-history-bottom {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}

.chi-meta {
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(55, 65, 81, 0.9);
}

.chi-direction-out {
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.7);
}

.chi-direction-in {
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.7);
}

.chi-result-completed {
    color: #a7f3d0;
    border-color: rgba(16, 185, 129, 0.8);
}

.chi-result-missed {
    color: #fed7aa;
    border-color: rgba(249, 115, 22, 0.8);
}

.chi-result-failed {
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.8);
}

/* Адаптация под планшеты и мобильные */
@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .sidebar-left,
    .sidebar-right {
        max-height: 200px;
    }

    .center-panel {
        order: 2;
    }

    .sidebar-left {
        order: 1;
    }

    .sidebar-right {
        order: 3;
    }

    .local-video {
        width: 90px;
        height: 60px;
    }
}

@media (max-width: 600px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .header-info {
        align-items: flex-start;
    }

    .app-main {
        padding: 8px;
        gap: 8px;
    }

    .call-panel {
        padding: 10px;
    }

    .video-wrapper {
        min-height: 140px;
    }

    .call-controls {
        gap: 6px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .btn.call-btn {
        min-width: 70px;
    }

    .device-bar {
        flex-direction: column;
    }

    .chat-panel {
        max-height: 220px;
    }
}
