:root {
    --primary-color: #3390ec;
    --primary-hover: #2b7cc9;
    --bg-color: #f1f2f3;
    --sidebar-bg: #ffffff;
    --chat-bg: #8eace2; /* Fallback */
    --my-msg-bg: #eeffde;
    --other-msg-bg: #ffffff;
    --text-color: #000000;
    --secondary-text: #707579;
    --border-color: #dfe1e5;
    --input-bg: #f1f1f1;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.04);
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    height: 100%;
    max-width: 100%; /* Full width for app-like feel */
    background: var(--sidebar-bg);
    display: flex;
    overflow: hidden;
}

@media (min-width: 1000px) {
    .container {
        /* max-width: 1600px; */
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
}

/* Auth Screen */
.screen {
    display: none;
    width: 100%;
    height: 100%;
}

.screen.active {
    display: flex;
}

#auth-screen {
    justify-content: center;
    align-items: center;
    background: white; 
    background-image: url("https://web.telegram.org/img/bg_0.png");
    background-size: cover;
}

.auth-box {
    background: white;
    padding: 48px 40px; /* Increased padding */
    border-radius: 24px; /* Curved window */
    /* box-shadow: 0 10px 20px rgba(0,0,0,0.05);  */
    text-align: center;
    width: 360px;
    position: relative;
    overflow: hidden;
}

.auth-icon {
    width: 100px; /* Larger icon */
    height: 100px;
    background-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 auto 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 48px;
    box-shadow: 0 10px 20px rgba(51, 144, 236, 0.3);
}

.auth-icon img {
    width: 72px;
    height: 72px;
    border-radius: 18px;
}

.auth-box h1 {
    color: var(--text-color);
    margin-bottom: 10px;
    font-size: 26px; /* Slightly larger */
    font-weight: 700;
}

.auth-subtitle {
    color: var(--secondary-text);
    margin-bottom: 30px;
    font-size: 15px;
}

.tabs {
    display: flex;
    margin-bottom: 25px;
    background: transparent; /* Cleaner tabs */
    border-radius: 0;
    padding: 0;
    gap: 20px;
    justify-content: center;
}

.tab-btn {
    flex: 0 0 auto;
    padding: 10px 5px;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--secondary-text);
    border-radius: 0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 15px;
}

.tab-btn.active {
    color: var(--primary-color);
    background: none;
    border-bottom-color: var(--primary-color);
    box-shadow: none;
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 20px; /* More spacing */
}

.auth-form.active {
    display: flex;
}

.auth-help {
    margin-top: 14px;
    text-align: left;
    border: 1px solid #d6dfeb;
    border-radius: 12px;
    background: #f7faff;
}

.auth-help summary {
    cursor: pointer;
    padding: 10px 12px;
    font-size: 14px;
    color: #2f3336;
    font-weight: 600;
}

.auth-help-body {
    padding: 0 12px 12px;
    color: #536170;
    font-size: 13px;
    line-height: 1.45;
    display: grid;
    gap: 5px;
}

.input-group {
    position: relative;
}

input {
    width: 100%;
    box-sizing: border-box;
    padding: 16px 20px; /* Taller inputs */
    border: 1px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.3s;
    font-size: 16px;
    background: var(--bg-color); /* Slight background */
}

input:focus {
    border-color: var(--primary-color);
    background: white;
}

button {
    padding: 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    transition: background-color 0.3s, transform 0.1s;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 10px rgba(51, 144, 236, 0.3); /* Button shadow */
}

button:hover {
    background-color: var(--primary-hover);
}

button:active {
    transform: scale(0.98);
}

/* Chat Screen */
#chat-screen {
    /* display: flex; removed to allow .screen class to toggle display */
    width: 100%;
}

.sidebar {
    width: 350px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* border-bottom: 1px solid var(--border-color); Remove border for cleaner look */
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
}

#user-profile-btn {
    padding: 4px 8px;
    border-radius: 12px;
}

#user-profile-btn:hover {
    background: rgba(51, 144, 236, 0.08);
}

#logout-btn {
    background: none;
    color: var(--secondary-text);
    padding: 8px;
    margin: 0;
    width: auto;
    font-size: 18px;
}

#logout-btn:hover {
    color: #e53935;
    background: rgba(229, 57, 53, 0.1);
}

.search-box {
    padding: 0 15px 10px;
    overflow: hidden;
    max-height: 100px;
    transition: max-height 0.2s ease, opacity 0.2s ease;
    opacity: 1;
}

.search-box.collapsed {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

#open-add-user-btn {
    margin: 0 15px 8px;
    border-radius: 14px;
    padding: 12px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 12px 24px rgba(37, 98, 166, 0.2);
}

#open-add-user-btn:hover {
    transform: translateY(-1px);
}

#open-add-user-btn i {
    font-size: 14px;
}

.id-add-row {
    display: flex;
    gap: 8px;
}

.search-box input {
    width: 100%;
    box-sizing: border-box;
    background: var(--input-bg);
    border: 1px solid transparent;
    padding: 10px 15px 10px 40px; /* Space for icon */
    border-radius: 22px;
    font-size: 15px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23707579' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

#add-user-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: none;
}

.search-box input:focus {
    background-color: white;
    border-color: var(--primary-color);
}

.users-list {
    flex: 1;
    overflow-y: auto;
    padding-top: 5px;
}

.users-empty-hint {
    margin: 10px 14px 14px;
    padding: 12px;
    border-radius: 12px;
    background: #eef6ff;
    color: #356797;
    font-size: 13px;
    line-height: 1.45;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.2);
}

/* User List Improvements */
.user-item {
    padding: 12px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background-color 0.1s;
    border-radius: 12px;
    margin: 2px 8px; /* Tighter spacing */
}

.user-item:hover {
    background-color: #f1f1f1;
}

.user-item.active {
    background-color: #3390ec; /* Active blue */
    color: white;
}

.user-item.active .user-name {
    color: white;
}

.user-item.active .user-status {
    color: rgba(255, 255, 255, 0.85);
}

.avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    /* Default gradient, will be overridden by JS colors */
    background: linear-gradient(135deg, #66a6ff, #89f7fe);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 700;
    font-size: 20px;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    overflow: hidden;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.avatar.avatar-image {
    color: transparent;
    background: transparent;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75) inset;
}

.avatar-photo {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

/* Avatar Colors (Telegram Palette) */
.avatar.color-1 { background: linear-gradient(135deg, #ff512f, #dd2476); }
.avatar.color-2 { background: linear-gradient(135deg, #f09819, #edde5d); }
.avatar.color-3 { background: linear-gradient(135deg, #11998e, #38ef7d); }
.avatar.color-4 { background: linear-gradient(135deg, #4568dc, #b06ab3); }
.avatar.color-5 { background: linear-gradient(135deg, #00b09b, #96c93d); }
.avatar.color-6 { background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045); }

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    min-width: 0; /* Text truncation fix */
}

.user-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-color);
}

.user-status {
    font-size: 14px;
    color: var(--secondary-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #3390ec;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
}

.user-badge i {
    font-size: 10px;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #9bb7d4;
    background-image: url("https://web.telegram.org/img/bg_0.png");
    background-size: auto; 
    position: relative;
}

.chat-header {
    padding: 12px 20px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 15px;
    font-weight: 600;
    font-size: 18px;
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

#chat-user-name {
    cursor: pointer;
}

.chat-user-box {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

#chat-user-status {
    font-size: 12px;
    font-weight: 500;
    color: var(--secondary-text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chat-user-avatar {
    cursor: pointer;
}

#chat-back-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    padding: 0;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: none;
    background: transparent;
    color: var(--secondary-text);
    display: none;
}

#chat-back-btn:hover {
    background: rgba(51, 144, 236, 0.1);
    color: var(--primary-color);
}

#chat-user-meta-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    padding: 0;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: none;
    background: transparent;
    color: var(--secondary-text);
}

#chat-user-meta-btn:hover {
    background: rgba(51, 144, 236, 0.1);
    color: var(--primary-color);
}

#chat-user-id {
    font-size: 13px;
    color: var(--secondary-text);
}

.call-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.call-actions button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: 0 8px 16px rgba(26, 33, 43, 0.12);
    transition: transform 0.16s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.call-actions button:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 22px rgba(26, 33, 43, 0.18);
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.empty-state {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    padding: 5px 15px;
    border-radius: 15px;
    align-self: center;
    margin-top: auto;
    margin-bottom: auto;
    font-size: 14px;
}

.message {
    max-width: 70%;
    padding: 10px 13px;
    border-radius: 14px;
    position: relative;
    font-size: 16px;
    line-height: 1.42;
    box-shadow: none;
    word-wrap: break-word;
    border: 1px solid rgba(25, 35, 48, 0.08);
}

.message.sent {
    align-self: flex-end;
    background-color: #eff6ff;
    border-bottom-right-radius: 14px;
}

.message.sent::after {
    content: none;
}

.message.received {
    align-self: flex-start;
    background-color: #ffffff;
    border-bottom-left-radius: 14px;
}

.message.received::after {
    content: none;
}

.message-time {
    font-size: 11px;
    color: #7a8491;
    float: right;
    margin-left: 10px;
    position: relative;
    top: 2px;
    font-variant-numeric: tabular-nums;
}

.message.sent .message-time {
    color: #6e7c8f;
}

.message.system {
    align-self: center;
    background: rgba(0, 0, 0, 0.24);
    color: #fff;
    font-size: 13px;
    border-radius: 14px;
    padding: 6px 12px;
    box-shadow: none;
}

.message.call-log {
    max-width: 78%;
}

.call-log-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.message.selected {
    outline: 2px solid rgba(51, 144, 236, 0.5);
    box-shadow: 0 0 0 2px rgba(51, 144, 236, 0.12);
}

/* Input Area Refinement */
.input-area {
    padding: 6px 10px 8px;
    background: white;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 10;
    max-width: none;
    margin: 0;
    width: 100%;
    box-sizing: border-box;
}

.input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: var(--bg-color);
    border-radius: 22px; /* Rounded pill */
    padding: 2px 12px;
}

.reply-preview {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(51, 144, 236, 0.1);
    border-radius: 12px;
    padding: 6px 8px;
    margin: 4px 0 2px;
    color: #2f3336;
    font-size: 12px;
}

.reply-preview-text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: calc(100% - 34px);
}

#reply-cancel-btn {
    border: none;
    width: 24px;
    height: 24px;
    margin: 0;
    padding: 0;
    background: transparent;
    color: #5e6a76;
    box-shadow: none;
}

#reply-cancel-btn:hover {
    color: #2f3336;
}

.voice-hint {
    margin: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 56px;
    z-index: 12;
    background: rgba(15, 23, 34, 0.8);
    color: #ffffff;
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 12px;
    pointer-events: none;
}

.voice-hint.recording {
    display: inline-flex !important;
    align-items: center;
    gap: 7px;
}

.voice-hint.recording::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff3b30;
    box-shadow: 0 0 0 rgba(255, 59, 48, 0.6);
    animation: voicePulse 1.2s ease-out infinite;
}

@keyframes voicePulse {
    0% {
        transform: scale(0.95);
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.6);
    }
    70% {
        transform: scale(1.08);
        opacity: 0.86;
        box-shadow: 0 0 0 8px rgba(255, 59, 48, 0);
    }
    100% {
        transform: scale(0.95);
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(255, 59, 48, 0);
    }
}

.input-area input[type="text"] {
    flex: 1;
    border: none;
    padding: 9px 0;
    background: transparent;
    border-radius: 0;
    font-size: 16px;
    margin: 0 6px;
}

.input-area input[type="text"]:focus {
    box-shadow: none;
    background: transparent;
}

#attach-btn {
    background: none;
    color: var(--secondary-text);
    font-size: 22px;
    padding: 8px;
    margin: 0;
    width: auto;
    transition: color 0.2s;
    box-shadow: none;
}

#voice-btn {
    background: none;
    color: var(--secondary-text);
    font-size: 22px;
    padding: 8px;
    margin: 0;
    width: auto;
    transition: color 0.2s;
    box-shadow: none;
}

#voice-btn.recording {
    color: #e53935;
    animation: micPulse 1.1s ease-in-out infinite;
}

#voice-btn:hover {
    color: var(--primary-color);
    transform: none;
    background: none;
}

#attach-btn:hover {
    color: var(--primary-color);
    transform: none;
    background: none;
}

#send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    margin-top: 0;
    box-shadow: none;
    color: var(--primary-color);
    background: transparent;
    transition: all 0.2s;
}

#send-btn:hover {
    transform: scale(1.1);
    background-color: rgba(51, 144, 236, 0.1);
}

#attach-btn:active,
#voice-btn:active,
#send-btn:active {
    transform: scale(0.94);
}

/* Send button becomes filled when typing? For now just icon */
#send-btn i {
    margin-left: -2px; /* Visual center */
}

.media-content img, .media-content video {
    max-width: 100%;
    border-radius: 8px;
    margin-bottom: 5px;
    display: block;
}

.media-content-audio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
}

.voice-player {
    width: min(240px, 58vw);
    height: 36px;
    margin: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(51, 144, 236, 0.22);
    accent-color: #3390ec;
    color-scheme: light;
    -webkit-appearance: none;
    appearance: none;
}

.voice-player::-webkit-media-controls-panel {
    background: rgba(235, 242, 251, 0.96);
    border-radius: 999px;
}

.voice-player::-webkit-media-controls-play-button,
.voice-player::-webkit-media-controls-mute-button {
    border-radius: 50%;
}

.voice-duration {
    min-width: 34px;
    text-align: right;
    font-size: 11px;
    color: #6f7d8f;
    font-variant-numeric: tabular-nums;
}

@keyframes micPulse {
    0% { opacity: 1; }
    50% { opacity: 0.45; }
    100% { opacity: 1; }
}

.media-thumb {
    width: min(260px, 62vw);
    max-height: 220px;
    object-fit: cover;
    cursor: pointer;
}

.media-preview {
    position: fixed;
    inset: 0;
    z-index: 260;
    background: rgba(7, 10, 14, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.media-preview img,
.media-preview video {
    width: auto;
    max-width: min(100%, 980px);
    max-height: calc(100vh - 80px);
    border-radius: 14px;
}

.media-preview-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 42px;
    height: 42px;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.2);
}

.user-item-main {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.remove-contact-btn {
    border: none;
    background: transparent;
    color: var(--secondary-text);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin: 0;
    padding: 0;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: none;
}

.remove-contact-btn:hover {
    background: rgba(229, 57, 53, 0.12);
    color: #e53935;
}

#remote-video, #local-video {
    position: fixed;
    right: 14px;
    bottom: 14px;
    width: 260px;
    border-radius: 12px;
    z-index: 99;
    background: #000;
    object-fit: cover;
    display: none;
}

#local-video {
    width: 180px;
    z-index: 201;
    cursor: move;
}

body.video-call-active #remote-video {
    display: block !important;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    z-index: 189;
}

body.video-call-active #local-video {
    display: block !important;
    width: min(28vw, 220px);
    height: min(38vw, 320px);
    border-radius: 14px;
    top: auto;
    left: auto;
    right: 14px;
    bottom: 14px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
}

.profile-panel {
    position: fixed;
    top: 74px;
    left: 53px;
    width: 320px;
    z-index: 110;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profile-panel-title {
    font-size: 15px;
    font-weight: 700;
}

.profile-subtitle {
    margin-top: 4px;
    font-size: 13px;
    color: var(--secondary-text);
    font-weight: 600;
}

.profile-row {
    font-size: 14px;
    color: #2f3336;
}

.profile-panel button {
    margin-top: 0;
    text-transform: none;
    letter-spacing: 0;
    padding: 10px 12px;
    border-radius: 10px;
    box-shadow: none;
    font-size: 14px;
}

.profile-panel input[type="text"] {
    width: 100%;
    border: 1px solid #dbe3ec;
    border-radius: 10px;
    padding: 9px 10px;
    font-size: 14px;
    margin: 0;
    box-sizing: border-box;
}

#upload-avatar-btn {
    background: linear-gradient(135deg, #2d9cff, #4b7dff);
}

#reset-avatar-btn {
    background: #eef2f7;
    color: #42536a;
}

#reset-avatar-btn:hover {
    background: #dde5ef;
}

#open-admin-btn {
    background: #2f3948;
}

.admin-panel {
    position: fixed;
    top: 82px;
    right: 24px;
    width: min(860px, calc(100vw - 48px));
    max-height: calc(100vh - 110px);
    overflow: auto;
    z-index: 170;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 18px 32px rgba(0, 0, 0, 0.2);
    padding: 14px;
}

.admin-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-title {
    font-size: 18px;
    font-weight: 700;
}

.admin-stats {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 8px;
}

.admin-stat {
    background: #f2f6fb;
    border-radius: 10px;
    padding: 10px;
    font-size: 13px;
}

.admin-stat b {
    display: block;
    font-size: 18px;
    margin-top: 4px;
    color: #1c2a3b;
}

.admin-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.admin-settings,
.admin-create-user,
.admin-storage {
    margin-top: 10px;
    border: 1px solid #e7edf5;
    border-radius: 10px;
    padding: 10px;
}

.admin-subtitle {
    font-size: 13px;
    color: #5f6f83;
    font-weight: 600;
}

.admin-toggle {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #2f3336;
}

.admin-switch-row input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.admin-switch {
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: #c9d4e1;
    position: relative;
    transition: background 0.2s ease;
    box-shadow: inset 0 0 0 1px rgba(42, 58, 77, 0.2);
}

.admin-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 3px 8px rgba(25, 35, 48, 0.35);
    transition: transform 0.2s ease;
}

.admin-switch-row input:checked + .admin-switch {
    background: #3390ec;
}

.admin-switch-row input:checked + .admin-switch::after {
    transform: translateX(20px);
}

.admin-inline {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-inline input,
.admin-inline select {
    min-height: 36px;
    border: 1px solid #dbe3ec;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
}

.admin-inline button {
    margin: 0;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
}

.admin-hint {
    margin-top: 6px;
    font-size: 12px;
    color: #69778a;
}

.admin-users {
    margin-top: 10px;
}

.admin-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto auto auto;
    gap: 8px;
    align-items: center;
    border: 1px solid #e7edf5;
    border-radius: 10px;
    padding: 8px;
    margin-top: 8px;
}

.admin-user-name {
    font-weight: 600;
    color: #2f3336;
}

.admin-user-meta {
    color: #69778a;
    font-size: 12px;
}

.admin-btn {
    padding: 7px 10px;
    border-radius: 8px;
    color: #fff;
    border: none;
}

.admin-btn-user {
    background: #e34c4c;
}

.admin-btn-user-files {
    background: #f08a24;
}

.admin-btn-file {
    background: #8f56d8;
}

.hidden {
    display: none !important;
}

.call-panel {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 320px;
    z-index: 160;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(223, 225, 229, 0.8);
    border-radius: 18px;
    box-shadow: 0 20px 38px rgba(19, 30, 44, 0.2);
    backdrop-filter: blur(10px);
    padding: 14px;
}

.call-panel-title {
    font-size: 14px;
    font-weight: 700;
    color: #2f3336;
}

.call-panel-user {
    margin-top: 4px;
    font-size: 15px;
    font-weight: 600;
}

.call-panel-status {
    margin-top: 6px;
    font-size: 13px;
    color: var(--secondary-text);
}

.call-panel-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

.call-btn {
    flex: 1;
    margin: 0;
    padding: 10px 12px;
    border-radius: 12px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 8px 16px rgba(29, 37, 49, 0.14);
    transition: transform 0.16s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.call-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 20px rgba(29, 37, 49, 0.2);
}

.call-btn.success {
    background: #2eaf66;
}

.call-btn.success:hover {
    background: #289b5b;
}

.call-btn.danger {
    background: #e34c4c;
}

.call-btn.danger:hover {
    background: #d73f3f;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(24, 31, 40, 0.35);
    z-index: 170;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.modal-overlay.compact {
    background: transparent;
    backdrop-filter: none;
    pointer-events: none;
}

.modal-window {
    width: min(380px, calc(100% - 20px));
    background: rgba(255, 255, 255, 0.97);
    border-radius: 18px;
    border: 1px solid rgba(223, 225, 229, 0.9);
    box-shadow: 0 20px 38px rgba(16, 24, 32, 0.24);
    padding: 18px;
}

.modal-overlay.compact .modal-window {
    position: fixed;
    width: min(300px, calc(100% - 20px));
    border-radius: 14px;
    padding: 14px;
    pointer-events: auto;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.modal-text {
    margin-top: 10px;
    font-size: 14px;
    color: #404a54;
    line-height: 1.45;
}

.modal-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    margin: 0;
    padding: 10px 15px;
    border-radius: 12px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 8px 16px rgba(25, 34, 45, 0.12);
    transition: transform 0.16s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.modal-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 22px rgba(25, 34, 45, 0.16);
}

.modal-btn.secondary {
    background: #eceff2;
    color: #2f3336;
}

.modal-btn.secondary:hover {
    background: #dfe3e8;
}

.modal-btn.primary {
    background: var(--primary-color);
}

.contact-actions-list {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.contact-action-btn {
    margin: 0;
    width: 100%;
    border-radius: 12px;
    padding: 10px 12px;
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: none;
    background: #f4f7fb;
    color: #253443;
    font-size: 14px;
    font-weight: 600;
}

.contact-action-btn:hover {
    background: #e8eef6;
}

.contact-action-btn.danger {
    background: #fff2f2;
    color: #cb3939;
}

.contact-action-btn.danger:hover {
    background: #ffe8e8;
}

.contact-input-label {
    margin-top: 12px;
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #3c4652;
}

.contact-input-field {
    margin-top: 8px;
    width: 100%;
    border: 1px solid #d3dbe5;
    border-radius: 12px;
    padding: 11px 12px;
    font-size: 14px;
    background: #f8fbff;
    color: #243647;
}

.contact-input-field:focus {
    outline: none;
    border-color: #7eb2ff;
    box-shadow: 0 0 0 3px rgba(80, 139, 255, 0.14);
}

.toast-container {
    position: fixed;
    right: 20px;
    top: 20px;
    z-index: 180;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: rgba(25, 33, 44, 0.92);
    color: #fff;
    border-radius: 12px;
    padding: 10px 13px;
    font-size: 13px;
    min-width: 220px;
    box-shadow: 0 12px 24px rgba(13, 18, 26, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.incoming-call-overlay {
    position: fixed;
    inset: 0;
    z-index: 190;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, rgba(62, 118, 182, 0.4), rgba(14, 20, 28, 0.92));
    backdrop-filter: blur(6px);
}

.incoming-call-overlay.compact {
    background: transparent;
    backdrop-filter: none;
    align-items: flex-start;
    justify-content: flex-start;
    pointer-events: none;
}

.incoming-call-window {
    width: min(420px, calc(100% - 28px));
    padding: 26px 22px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow: 0 20px 44px rgba(5, 10, 18, 0.35);
    text-align: center;
}

.incoming-call-overlay.compact .incoming-call-window {
    width: auto;
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    position: fixed;
    right: 18px;
    bottom: 18px;
    cursor: grab;
    touch-action: none;
    pointer-events: auto;
}

.incoming-call-icon {
    width: 88px;
    height: 88px;
    margin: 0 auto;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    font-size: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.incoming-call-title {
    margin-top: 14px;
    font-size: 26px;
    color: #fff;
    font-weight: 700;
}

.incoming-call-user {
    margin-top: 8px;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.9);
}

.incoming-call-actions {
    margin-top: 24px;
    display: flex;
    justify-content: center;
    gap: 14px;
}

.incoming-call-active {
    margin-top: 14px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.incoming-call-overlay.compact .incoming-call-icon,
.incoming-call-overlay.compact .incoming-call-title,
.incoming-call-overlay.compact .incoming-call-user,
.incoming-call-overlay.compact .incoming-call-actions,
.incoming-call-overlay.compact .incoming-call-active .incoming-btn.flat {
    display: none;
}

.incoming-call-overlay.compact .incoming-call-active {
    margin: 0 0 16px;
}

.incoming-call-overlay.compact #incoming-end-btn {
    min-width: 220px;
    border-radius: 999px;
}

.incoming-btn {
    margin: 0;
    min-width: 132px;
    border-radius: 14px;
    padding: 12px 14px;
    text-transform: none;
    letter-spacing: 0;
    box-shadow: 0 12px 24px rgba(7, 14, 22, 0.4);
}

.incoming-btn.flat {
    background: rgba(255, 255, 255, 0.18);
}

.incoming-btn.flat:hover {
    background: rgba(255, 255, 255, 0.26);
}

.incoming-btn.off {
    opacity: 0.65;
}

.incoming-btn.answer {
    background: #2eaf66;
}

.incoming-btn.answer:hover {
    background: #279c59;
}

.incoming-btn.decline {
    background: #e34c4c;
}

.incoming-btn.decline:hover {
    background: #d53f3f;
}

.message-menu {
    position: fixed;
    z-index: 210;
    min-width: 170px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(223, 225, 229, 0.96);
    border-radius: 12px;
    box-shadow: 0 16px 30px rgba(15, 23, 34, 0.24);
    padding: 6px;
}

.menu-btn {
    width: 100%;
    margin: 0;
    border: none;
    background: transparent;
    color: #2f3336;
    border-radius: 10px;
    text-align: left;
    padding: 8px 10px;
    box-shadow: none;
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
}

.menu-btn:hover {
    background: rgba(51, 144, 236, 0.12);
}

.menu-btn.danger {
    color: #d74a4a;
}

.select-toolbar {
    position: fixed;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 205;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(223, 225, 229, 0.94);
    border-radius: 14px;
    padding: 8px 10px;
    box-shadow: 0 14px 30px rgba(13, 20, 31, 0.24);
}

@media (max-width: 900px) {
    body {
        height: 100dvh;
        align-items: stretch;
    }

    .container {
        height: 100dvh;
        max-width: 100%;
    }

    #auth-screen {
        align-items: flex-start;
        padding: calc(env(safe-area-inset-top, 0px) + 10px) 8px 10px;
        box-sizing: border-box;
        overflow-y: auto;
    }

    .auth-box {
        width: min(360px, 100%);
        margin: 0 auto;
        padding: 28px 18px;
    }

    .sidebar {
        width: 100%;
        border-right: none;
    }

    .chat-area {
        width: 100%;
        display: none;
    }

    #chat-screen.mobile-chat-active .sidebar {
        display: none;
    }

    #chat-screen.mobile-chat-active .chat-area {
        display: flex;
    }

    #chat-back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .chat-header {
        padding: 10px 12px;
        gap: 10px;
    }

    #chat-user-name {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #chat-user-status {
        max-width: 110px;
    }

    .call-actions button {
        width: 36px;
        height: 36px;
    }

    .avatar {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }

    .messages-container {
        padding: 12px 10px;
    }

    .message {
        max-width: 82%;
        font-size: 15px;
    }

    .media-thumb {
        width: min(72vw, 300px);
        max-height: 180px;
    }

    .voice-player {
        width: min(236px, 70vw);
        height: 34px;
    }

    .voice-hint {
        bottom: 52px;
    }

    .input-area {
        max-width: none;
        padding: 6px 8px 8px;
    }

    .input-wrapper {
        padding: 2px 9px;
    }

    .input-area input[type="text"] {
        margin: 0 6px;
        font-size: 15px;
    }

    .profile-panel {
        top: 80px;
        left: 8px;
        right: 8px;
        width: auto;
    }

    .admin-panel {
        top: 8px;
        left: 8px;
        right: 8px;
        width: auto;
        max-height: calc(100dvh - 16px);
        padding: 10px;
        border-radius: 12px;
        margin: 0 auto;
    }

    .admin-head,
    .admin-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .admin-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-row {
        grid-template-columns: 1fr;
    }

    .admin-inline {
        align-items: stretch;
    }

    .admin-inline input,
    .admin-inline select,
    .admin-inline button,
    .admin-row button {
        width: 100%;
    }

    .call-panel {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
    }

    .incoming-call-window {
        width: calc(100% - 18px);
        padding: 22px 14px;
        border-radius: 18px;
    }

    .incoming-call-title {
        font-size: 22px;
    }

    .incoming-call-actions {
        gap: 10px;
    }

    .incoming-call-active {
        gap: 8px;
    }

    .incoming-btn {
        min-width: 0;
        flex: 1;
    }

    .message-menu {
        width: calc(100% - 16px);
        left: 8px !important;
    }

    .select-toolbar {
        left: 8px;
        right: 8px;
        transform: none;
        justify-content: space-between;
    }

    .modal-window {
        width: calc(100% - 24px);
    }

    #remote-video {
        width: 100vw;
        max-width: none;
        right: 0;
        bottom: 0;
    }

    #local-video {
        right: 8px;
        bottom: 76px;
        width: 35vw;
        max-width: 140px;
        height: 46vw;
        max-height: 200px;
    }

    .toast-container {
        left: 8px;
        right: 8px;
        top: 8px;
    }

    .toast {
        min-width: 0;
    }
}
