:root {
    --primary: #6C5CE7;
    --primary-dark: #5A4BD1;
    --primary-light: #A29BFE;
    --secondary: #00CEC9;
    --accent: #FD79A8;
    --bg-primary: #0F0F1A;
    --bg-secondary: #1A1A2E;
    --bg-tertiary: #252540;
    --bg-chat: #12121F;
    --text-primary: #FFFFFF;
    --text-secondary: #A0A0B8;
    --text-muted: #6B6B80;
    --border: #2A2A45;
    --message-sent: #6C5CE7;
    --message-received: #252540;
    --online: #00B894;
    --offline: #636E72;
    --danger: #E17055;
    --success: #00B894;
    --warning: #FDCB6E;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 20px;
    --transition: 0.2s ease;
    --sidebar-width: 360px;
    --header-height: 64px;
}

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

html {
    height: 100%;
    height: -webkit-fill-available;
}

html, body {
    width: 100%;
    overflow: hidden;
    position: fixed;
    inset: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    margin: 0;
}

#app {
    width: 100%;
    height: 100%;
    height: 100dvh;
    height: -webkit-fill-available;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    flex: 1;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

#auth-screen.active {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

/* ===== AUTH SCREEN ===== */
.auth-container {
    width: 100%;
    max-width: 420px;
    margin: auto;
    padding: 1.5rem 1.25rem 5rem;
    box-sizing: border-box;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    box-shadow: 0 8px 32px rgba(108, 92, 231, 0.4);
}

.logo-icon svg {
    width: 36px;
    height: 36px;
    color: white;
}

.auth-logo h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.auth-logo p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 1.5rem;
}

.auth-tab {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.auth-tab.active {
    background: var(--primary);
    color: white;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.input-group {
    margin-bottom: 1rem;
}

.input-group input {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: var(--transition);
    outline: none;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4);
}

.btn-block {
    width: 100%;
}

/* ===== CHAT LAYOUT ===== */
.chat-layout {
    display: flex;
    height: 100%;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    height: var(--header-height);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.sidebar-actions {
    display: flex;
    gap: 0.25rem;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 1rem;
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--primary);
}

.search-box svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.conversation-item:hover,
.conversation-item.active {
    background: var(--bg-tertiary);
}

.conversation-item.active {
    border-left: 3px solid var(--primary);
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    flex-shrink: 0;
}

.conversation-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.unread-badge {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* ===== AVATAR ===== */
.avatar {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-text {
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

.avatar-sm { width: 40px; height: 40px; font-size: 0.85rem; }
.avatar-md { width: 44px; height: 44px; font-size: 0.9rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }
.avatar-xl { width: 80px; height: 80px; font-size: 1.5rem; }

.avatar .status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

.status-dot.online { background: var(--online); }
.status-dot.offline { background: var(--offline); }

/* ===== CHAT AREA ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.empty-icon {
    width: 80px;
    height: 80px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.empty-icon svg {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
}

.chat-empty h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.chat-active.hidden {
    display: none !important;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: var(--header-height);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    cursor: pointer;
}

.chat-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.chat-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

/* ===== MESSAGES ===== */
.messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
}

.message {
    display: flex;
    gap: 0.5rem;
    max-width: 75%;
    animation: messageIn 0.2s ease;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-bubble {
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    position: relative;
    word-wrap: break-word;
}

.message.received .message-bubble {
    background: var(--message-received);
    border-bottom-left-radius: 4px;
}

.message.sent .message-bubble {
    background: var(--message-sent);
    border-bottom-right-radius: 4px;
}

.message-text {
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.message-image {
    max-width: 280px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.25rem;
    justify-content: flex-end;
}

.message-time {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
}

.message-status {
    display: inline-flex;
    align-items: center;
    margin-left: 0.25rem;
    font-size: 0.75rem;
    line-height: 1;
}

.message-status.sent {
    color: rgba(255,255,255,0.45);
}

.message-status.read {
    color: var(--secondary);
}

.message-status svg {
    width: 14px;
    height: 14px;
}

.chat-status.online {
    color: var(--online);
}

.chat-status.offline {
    color: var(--text-muted);
}

.secure-warning {
    background: rgba(225, 112, 85, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.secure-warning code {
    background: var(--bg-tertiary);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.permission-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.permission-actions .btn {
    flex: 1;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.ws-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--offline);
    flex-shrink: 0;
}

.ws-status.connected {
    background: var(--online);
}

.message-edited {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.4);
    font-style: italic;
}

.message-reply {
    padding: 0.375rem 0.625rem;
    border-left: 3px solid var(--primary-light);
    margin-bottom: 0.375rem;
    background: rgba(0,0,0,0.15);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.8rem;
}

.message-reply strong {
    color: var(--primary-light);
    font-size: 0.75rem;
}

.date-divider {
    text-align: center;
    margin: 1rem 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.date-divider span {
    background: var(--bg-tertiary);
    padding: 0.25rem 0.75rem;
    border-radius: 10px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 1rem;
    align-self: flex-start;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== MESSAGE INPUT ===== */
.message-input-area {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 5;
}

.reply-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary);
}

.reply-content {
    flex: 1;
    min-width: 0;
}

.reply-content strong {
    font-size: 0.8rem;
    color: var(--primary-light);
}

.reply-content p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.message-input-wrapper {
    flex: 1;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: var(--transition);
}

.message-input-wrapper:focus-within {
    border-color: var(--primary);
}

#message-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
}

#message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: var(--primary) !important;
    color: white !important;
    border-radius: 50% !important;
    width: 42px !important;
    height: 42px !important;
}

.send-btn:hover {
    background: var(--primary-dark) !important;
}

/* ===== ICON BUTTON ===== */
.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn.logout-btn:hover {
    background: rgba(225, 112, 85, 0.15);
    color: var(--danger);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#media-permission-modal {
    z-index: 6000;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 440px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
}

.user-search-results {
    margin-top: 0.75rem;
}

.user-result-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.user-result-item:hover {
    background: var(--bg-tertiary);
}

.user-result-info h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

.user-result-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ===== VIDEO CALL ===== */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 3500;
    background: var(--bg-primary);
}

.call-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: var(--bg-secondary);
}

#local-video {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 160px;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    z-index: 10;
}

.call-controls .call-btn svg {
    pointer-events: none;
}

.call-info {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 5;
}

.call-info h2 {
    margin: 1rem 0 0.5rem;
}

.call-info p {
    color: var(--text-secondary);
}

.call-controls {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1.5rem;
    z-index: 10;
}

.call-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--bg-tertiary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.call-btn svg {
    width: 24px;
    height: 24px;
}

.call-btn:hover {
    transform: scale(1.1);
}

.call-btn-end {
    background: var(--danger);
}

.call-btn-accept {
    background: var(--success);
}

.call-btn-decline {
    background: var(--danger);
}

.call-btn.muted {
    background: var(--danger);
}

/* ===== INCOMING CALL ===== */
.incoming-call {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(15, 15, 26, 0.97);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    pointer-events: auto;
}

.incoming-call.hidden {
    display: none !important;
    pointer-events: none;
}

.incoming-call-content {
    text-align: center;
}

.incoming-call-content h2 {
    margin: 1.5rem 0 0.5rem;
    font-size: 1.5rem;
}

.incoming-call-content p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.incoming-call-actions {
    display: flex;
    gap: 3rem;
    justify-content: center;
    align-items: center;
}

.incoming-call-actions .call-btn {
    width: 72px;
    height: 72px;
    min-width: 72px;
    min-height: 72px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    position: relative;
    z-index: 2;
    border: none;
    user-select: none;
    -webkit-user-select: none;
}

.incoming-call-actions .call-btn svg {
    pointer-events: none;
}

.incoming-call-actions .call-btn-accept {
    background: var(--success);
    box-shadow: 0 0 24px rgba(0, 184, 148, 0.4);
}

.incoming-call-actions .call-btn-decline {
    background: var(--danger);
    transform: rotate(135deg);
}

/* ===== CALL CONNECTING ===== */
.call-connecting {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(15, 15, 26, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.call-connecting.hidden {
    display: none !important;
    pointer-events: none;
}

.call-connecting-box {
    text-align: center;
    padding: 2rem;
}

.call-connecting-box p {
    margin-top: 1.25rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.call-connecting-hint {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.5); }
    70% { box-shadow: 0 0 0 20px rgba(108, 92, 231, 0); }
    100% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0); }
}

.user-info.clickable {
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 0.25rem;
    margin: -0.25rem;
    transition: background 0.2s;
}

.user-info.clickable:hover {
    background: var(--bg-tertiary);
}

.input-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    font-weight: 500;
}

.input-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
}

.modal-profile {
    max-width: 480px;
}

.profile-form .input-group {
    margin-bottom: 1rem;
}

.profile-avatar-row {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.profile-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.profile-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}

.profile-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
}

.btn-secondary:hover {
    background: var(--border);
}

/* ===== INSTALL BANNER (PWA) ===== */
.install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 8000;
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent, rgba(15, 15, 26, 0.95) 20%);
    pointer-events: none;
}

.install-banner.hidden {
    display: none !important;
}

.install-banner-inner {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    max-width: 520px;
    margin: 0 auto;
    padding: 0.875rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.install-banner-icon {
    border-radius: 12px;
    flex-shrink: 0;
}

.install-banner-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.install-banner-text strong {
    font-size: 0.9rem;
}

.install-banner-text span {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.install-banner-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.btn-install {
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn-dismiss-install {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 50%;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    animation: toastIn 0.3s ease;
    max-width: 360px;
}

.toast.error { border-left: 3px solid var(--danger); }
.toast.success { border-left: 3px solid var(--success); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== RESPONSIVE / MOBILE (iPhone) ===== */
@media (max-width: 768px) {
    .mobile-only { display: flex; }

    :root {
        --header-height: 56px;
        --sidebar-width: 100%;
    }

    /* iOS input zoom oldini olish */
    .input-group input,
    .input-group textarea,
    #message-input,
    .search-box input,
    .btn,
    .auth-tab {
        font-size: 16px !important;
    }

    .auth-logo {
        margin-bottom: 1.25rem;
    }

    .auth-logo h1 {
        font-size: 1.5rem;
    }

    .auth-logo p {
        font-size: 0.85rem;
    }

    .logo-icon {
        width: 56px;
        height: 56px;
        margin-bottom: 0.75rem;
    }

    .logo-icon svg {
        width: 28px;
        height: 28px;
    }

    .auth-container {
        padding: 1rem 1rem 6.5rem;
    }

    .auth-tabs {
        margin-bottom: 1rem;
    }

    .input-group {
        margin-bottom: 0.75rem;
    }

    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        z-index: 10;
        transition: transform 0.3s ease;
    }

    .sidebar.hidden-mobile {
        transform: translateX(-100%);
    }

    .sidebar-header {
        padding: 0.5rem 0.75rem;
        height: auto;
        min-height: var(--header-height);
        gap: 0.5rem;
    }

    .user-info {
        flex: 1;
        min-width: 0;
        gap: 0.5rem;
    }

    .user-name {
        font-size: 0.85rem;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar-actions {
        flex-shrink: 0;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }

    .icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .search-box {
        margin: 0.5rem 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    .chat-area {
        width: 100%;
    }

    .chat-header {
        padding: 0.5rem 0.75rem;
        height: auto;
        min-height: var(--header-height);
        gap: 0.5rem;
    }

    .chat-title {
        font-size: 0.9rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 160px;
    }

    .chat-header-actions {
        flex-shrink: 0;
        gap: 0.15rem;
    }

    .message {
        max-width: 88%;
    }

    .message-input-area {
        padding: 0.5rem 0.625rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }

    .input-row {
        gap: 0.35rem;
    }

    .send-btn {
        width: 38px !important;
        height: 38px !important;
        flex-shrink: 0;
    }

    #local-video {
        width: 90px;
        height: 68px;
        top: 0.5rem;
        right: 0.5rem;
    }

    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: min(92dvh, 92vh);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        margin-bottom: 0;
    }

    .modal-profile {
        max-height: min(94dvh, 94vh);
    }

    .profile-avatar-row {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .install-banner {
        padding: 0.5rem 0.625rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }

    .install-banner-inner {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .install-banner-icon {
        width: 40px;
        height: 40px;
    }

    .install-banner-text strong {
        font-size: 0.8rem;
    }

    .install-banner-text span {
        font-size: 0.72rem;
    }

    .install-banner-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .btn-install {
        font-size: 0.8rem;
        padding: 0.45rem 0.85rem;
    }

    .toast-container {
        top: calc(0.5rem + env(safe-area-inset-top, 0px));
        left: 0.75rem;
        right: 0.75rem;
    }

    .toast {
        max-width: 100%;
        font-size: 0.85rem;
    }

    .chat-empty {
        padding: 1.25rem;
    }

    .chat-empty h2 {
        font-size: 1.1rem;
    }

    .chat-empty p {
        font-size: 0.85rem;
    }

    .incoming-call-content h2 {
        font-size: 1.25rem;
    }

    .incoming-call-actions {
        gap: 2rem;
    }

    .incoming-call-actions .call-btn {
        width: 64px;
        height: 64px;
    }
}

@media (max-width: 390px) {
    .user-name {
        max-width: 72px;
    }

    .chat-title {
        max-width: 120px;
    }

    .auth-logo h1 {
        font-size: 1.35rem;
    }
}

@media (max-width: 480px) {
    .call-controls {
        gap: 1rem;
        bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    }

    .call-btn {
        width: 48px;
        height: 48px;
    }
}
