/* ===========================
   ПЕРЕМЕННЫЕ И БАЗОВЫЕ СТИЛИ
   =========================== */
:root {
    --primary: #4f6ef7;
    --primary-dark: #3a57d9;
    --primary-light: #eef1ff;
    --primary-rgb: 79, 110, 247;

    --accent: #7c5cfc;
    --accent-rgb: 124, 92, 252;

    --danger: #f04646;
    --danger-light: #fff0f0;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --warning: #f59e0b;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f9fafc;
    --border: #e8eaf2;
    --border-strong: #d0d5e8;

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-on-primary: #ffffff;

    --header-bg: var(--primary);
    --msg-bg: #ffffff;
    --msg-bg-sent: var(--primary);
    --chat-bg: #edf0f9;

    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
    --shadow-xl: 0 24px 48px rgba(0,0,0,.16);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    --font: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.2s cubic-bezier(.4,0,.2,1);

    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

/* ТЁМНАЯ ТЕМА */
body.dark {
    --primary: #6b8bff;
    --primary-dark: #4f6ef7;
    --primary-light: rgba(107, 139, 255, 0.15);

    --bg: #0d0f1a;
    --surface: #161825;
    --surface-2: #1c1f31;
    --border: #262940;
    --border-strong: #333659;

    --text-primary: #e8eaf6;
    --text-secondary: #8891b8;
    --text-muted: #4d5478;

    --header-bg: #161825;
    --msg-bg: #1c1f31;
    --msg-bg-sent: var(--primary);
    --chat-bg: #0d0f1a;
}

/* СБРОС */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    overflow: hidden;
    font-size: 16px;
    line-height: 1.5;
}

button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

/* ===========================
   LAYOUT
   =========================== */
.app {
    height: 100dvh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 680px;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: var(--shadow-xl);
    position: relative;
    overflow: hidden;
}

.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    animation: screenIn 0.28s cubic-bezier(.4,0,.2,1);
}
.screen.active { display: flex; }

@keyframes screenIn {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===========================
   HEADER
   =========================== */
.header {
    background: var(--header-bg);
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 1px;
    background: rgba(255,255,255,0.08);
}

body.dark .header { box-shadow: 0 1px 0 var(--border); }

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.header-title-group { min-width: 0; }

.header-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-subtitle {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.65);
    display: block;
    margin-top: -1px;
}

.header-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    transition: opacity var(--transition);
    overflow: hidden;
}
.header-avatar:hover { opacity: 0.85; }
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.header-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    border: none;
    background: rgba(255,255,255,0.12);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    flex-shrink: 0;
}
.header-btn:hover { background: rgba(255,255,255,0.22); }

.header-btn-primary { background: rgba(255,255,255,0.22); }
.header-btn-primary:hover { background: rgba(255,255,255,0.35); }
.header-btn-danger { background: rgba(240,70,70,0.25); }
.header-btn-danger:hover { background: rgba(240,70,70,0.4); }

.header-back-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: rgba(255,255,255,0.12);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}
.header-back-btn:hover { background: rgba(255,255,255,0.22); }

/* ===========================
   AUTH SCREEN
   =========================== */
#authScreen {
    background: var(--bg);
    position: relative;
    overflow: hidden;
}

.auth-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.auth-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.35;
}

.auth-blob-1 {
    width: 400px; height: 400px;
    background: var(--primary);
    top: -100px; right: -100px;
}

.auth-blob-2 {
    width: 300px; height: 300px;
    background: var(--accent);
    bottom: -80px; left: -60px;
}

body.dark .auth-blob { opacity: 0.2; }

.auth-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    z-index: 1;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
}

.auth-logo-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(var(--primary-rgb), 0.4);
}

.auth-logo-text {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 28px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.auth-tabs {
    display: flex;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 24px;
    position: relative;
    gap: 4px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    position: relative;
    z-index: 1;
}
.auth-tab.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.auth-tab-indicator { display: none; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    pointer-events: none;
    z-index: 1;
}

.input-eye {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 4px;
    transition: color var(--transition);
}
.input-eye:hover { color: var(--text-secondary); }

.input-field {
    width: 100%;
    padding: 13px 44px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    outline: none;
}
.input-field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
    background: var(--surface);
}
.input-field::placeholder { color: var(--text-muted); }

/* Without left icon */
.input-field:not(.input-group .input-field) {
    padding-left: 14px;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    margin-top: 4px;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.4);
}
.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.5);
}
.btn-primary:active { transform: translateY(0); }

.status-message {
    margin-top: 8px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 8px;
    border-radius: var(--radius-sm);
    animation: fadeIn 0.2s;
}
.status-success {
    color: var(--success);
    background: var(--success-light);
}
.status-error {
    color: var(--danger);
    background: var(--danger-light);
}

/* ===========================
   SEARCH
   =========================== */
.search-box {
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.search-icon { color: var(--text-muted); flex-shrink: 0; }

.search-input {
    flex: 1;
    border: none;
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    padding: 9px 14px;
    border-radius: var(--radius-full);
    outline: none;
    transition: background var(--transition);
    border: 1.5px solid var(--border);
}
.search-input:focus {
    background: var(--surface);
    border-color: var(--primary);
}
.search-input::placeholder { color: var(--text-muted); }

/* ===========================
   CHATS LIST
   =========================== */
.chats-container, .users-container {
    flex: 1;
    overflow-y: auto;
    background: var(--bg);
    overscroll-behavior: contain;
}

.chats-list, .users-list {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-item, .user-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    gap: 12px;
    position: relative;
    overflow: hidden;
}
.chat-item:hover, .user-item:hover {
    background: var(--surface-2);
    box-shadow: var(--shadow-sm);
}
.chat-item:active, .user-item:active {
    transform: scale(0.99);
}

.chat-avatar, .user-avatar {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 800;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}
.chat-avatar img, .user-avatar img {
    width: 100%; height: 100%; object-fit: cover;
}

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

.chat-name, .user-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.last-message {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

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

.chat-unread {
    background: var(--primary);
    color: white;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 7px;
    min-width: 20px;
    text-align: center;
}

.chat-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: color var(--transition), background var(--transition);
    display: flex;
    align-items: center;
}
.chat-delete:hover {
    color: var(--danger);
    background: var(--danger-light);
}

/* Empty & loading states */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
    gap: 8px;
}
.empty-icon { font-size: 3rem; margin-bottom: 4px; }
.empty-state p { font-size: 1rem; font-weight: 600; color: var(--text-secondary); }
.empty-state span { font-size: 0.85rem; }

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.loading-spinner {
    width: 28px;
    height: 28px;
    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); } }

/* ===========================
   PROFILE SCREEN
   =========================== */
.profile-container {
    flex: 1;
    overflow-y: auto;
    background: var(--bg);
}

.profile-hero {
    background: var(--header-bg);
    padding: 32px 20px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.profile-avatar-wrap {
    position: relative;
    width: 96px;
    height: 96px;
    margin-bottom: 4px;
}

.profile-avatar-wrap img,
.profile-avatar-wrap .avatar-placeholder {
    width: 96px;
    height: 96px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 3px solid rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: rgba(255,255,255,0.15);
}

.avatar-edit-btn {
    position: absolute;
    bottom: 0; right: 0;
    width: 30px; height: 30px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 2px solid var(--header-bg);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition);
    box-shadow: var(--shadow-sm);
}
.avatar-edit-btn:hover { transform: scale(1.1); }

.profile-name {
    font-size: 1.3rem;
    font-weight: 800;
    color: white;
}

.profile-tag {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.65);
    font-weight: 500;
}

.profile-section {
    margin: 16px 12px 0;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.profile-item {
    display: flex;
    align-items: center;
    padding: 15px 16px;
    gap: 14px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border);
}
.profile-item:last-child { border-bottom: none; }
.profile-item:hover { background: var(--surface-2); }

.profile-item-icon {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.profile-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.profile-item-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.profile-item-value {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.profile-item-arrow { color: var(--text-muted); }

.profile-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 15px;
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--danger);
    transition: background var(--transition);
}
.profile-logout-btn:hover { background: var(--danger-light); }

/* ===========================
   CHAT SCREEN
   =========================== */
.chat-header {
    background: var(--header-bg);
    padding: 12px 12px;
    padding-top: calc(12px + var(--safe-top));
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-header-avatar {
    width: 38px; height: 38px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}
.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-header-text { min-width: 0; }

.chat-title {
    font-size: 1rem;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-status {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.65);
    display: block;
}

/* MESSAGES */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    gap: 4px;
    overscroll-behavior: contain;
    background-image: radial-gradient(circle at 25% 25%, rgba(var(--primary-rgb), 0.03) 0%, transparent 60%);
}

.message-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msgIn 0.2s cubic-bezier(.4,0,.2,1);
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-wrapper.sent { justify-content: flex-end; }
.message-wrapper.received { justify-content: flex-start; }

.message-avatar {
    width: 30px; height: 30px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    flex-shrink: 0;
    overflow: hidden;
    align-self: flex-end;
    margin-bottom: 2px;
}
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }

.message-wrapper.sent .message-avatar { display: none; }

.message {
    max-width: 72%;
    padding: 9px 13px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 6px;
    line-height: 1.45;
    font-size: 0.93rem;
    font-weight: 500;
    word-break: break-word;
}

.message.sent {
    background: var(--msg-bg-sent);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(var(--primary-rgb), 0.35);
}

.message.received {
    background: var(--msg-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.message-time {
    font-size: 0.68rem;
    opacity: 0.65;
    margin-left: auto;
    white-space: nowrap;
    font-weight: 600;
    align-self: flex-end;
}

/* Date separator */
.date-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
}
.date-separator span {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    padding: 3px 12px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
}

/* Media messages */
.media-message {
    max-width: 220px;
    max-height: 220px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: block;
    width: 100%;
    object-fit: cover;
    transition: opacity var(--transition);
}
.media-message:hover { opacity: 0.9; }

.file-message {
    background: rgba(0,0,0,0.07);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    min-width: 180px;
    width: 100%;
}
.message.sent .file-message { background: rgba(255,255,255,0.15); }

.file-icon { font-size: 1.8rem; }

.file-info { flex: 1; min-width: 0; }
.file-name {
    font-size: 0.82rem;
    font-weight: 600;
    word-break: break-all;
    line-height: 1.3;
}
.file-size {
    font-size: 0.72rem;
    opacity: 0.65;
    margin-top: 2px;
}

/* Voice message */
.voice-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    width: 200px;
}

.voice-play-button {
    width: 34px; height: 34px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.25);
    border: none;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.85rem;
    transition: background var(--transition);
}
.voice-play-button:hover { background: rgba(255,255,255,0.35); }

.voice-timeline {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.25);
    border-radius: var(--radius-full);
    position: relative;
    cursor: pointer;
}
.message.received .voice-timeline { background: var(--border); }

.voice-progress {
    height: 100%;
    background: currentColor;
    border-radius: var(--radius-full);
    width: 0%;
    opacity: 0.8;
    transition: width 0.1s linear;
}

.voice-time {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.75;
    min-width: 32px;
}

/* INPUT AREA */
.input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(10px + var(--safe-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    position: relative;
}

.attach-button {
    width: 42px; height: 42px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--surface-2);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition), transform var(--transition);
    border: 1.5px solid var(--border);
}
.attach-button:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}
.attach-button:active { transform: scale(0.95); }

.message-input-wrap { flex: 1; }

.message-input {
    width: 100%;
    padding: 11px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
    resize: none;
    max-height: 120px;
}
.message-input:focus {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}
.message-input::placeholder { color: var(--text-muted); }

.send-button {
    width: 42px; height: 42px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.4);
}
.send-button:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}
.send-button:active { transform: scale(0.96); }

/* ATTACH MENU */
.attach-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 12px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 100;
    animation: fadeSlideUp 0.18s ease-out;
}
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.attach-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background var(--transition);
    min-width: 70px;
}
.attach-menu-item:hover { background: var(--surface-2); }

.attach-menu-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}
.photo-icon { background: linear-gradient(135deg, #f093fb, #f5576c); }
.voice-icon { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.file-icon-btn { background: linear-gradient(135deg, #43e97b, #38f9d7); }

/* Error message */
.error-message {
    background: var(--danger-light);
    color: var(--danger);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    margin: 4px;
    font-size: 0.82rem;
    font-weight: 600;
    text-align: center;
    border: 1px solid rgba(240, 70, 70, 0.2);
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 8px;
    font-size: 0.8rem;
    font-weight: 500;
}

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

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s;
}
.image-view-backdrop { background: rgba(0,0,0,0.92); }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-sheet {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-width: 680px;
    padding: 0 0 calc(20px + var(--safe-bottom));
    box-shadow: var(--shadow-xl);
    animation: sheetUp 0.3s cubic-bezier(.32,.72,0,1);
    z-index: 1;
    max-height: 90dvh;
    overflow-y: auto;
}
@keyframes sheetUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-sheet-sm { max-height: 70dvh; }

.modal-handle {
    width: 40px; height: 4px;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    margin: 10px auto 4px;
}

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

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close-btn {
    width: 30px; height: 30px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--surface-2);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.modal-close-btn:hover { background: var(--border); }

.modal-body { padding: 20px; }

.modal-actions {
    display: flex;
    gap: 10px;
    padding: 16px 20px 0;
    justify-content: flex-end;
}
.modal-actions-column { flex-direction: column; }

.modal-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 12px 22px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 0.92rem;
    font-weight: 700;
    transition: all var(--transition);
}
.modal-btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.35);
}
.modal-btn-primary:hover { background: var(--primary-dark); }
.modal-btn-ghost {
    background: var(--surface-2);
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
}
.modal-btn-ghost:hover { background: var(--border); }
.modal-btn-danger {
    background: var(--danger);
    color: white;
    width: 100%;
}
.modal-btn-danger:hover { background: #c53030; }

/* Confirm modal (centered dialog) */
.modal-dialog {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 28px 24px 24px;
    max-width: 320px;
    width: calc(100% - 48px);
    text-align: center;
    box-shadow: var(--shadow-xl);
    z-index: 1;
    animation: dialogIn 0.25s cubic-bezier(.4,0,.2,1);
    align-self: center;
}
@keyframes dialogIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

#confirmModal { align-items: center; }

.modal-dialog-icon {
    width: 60px; height: 60px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}
.modal-dialog-icon-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.modal-dialog-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-dialog-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 4px;
}

/* Photo preview */
.photo-preview-wrap {
    padding: 16px 20px;
    display: flex;
    justify-content: center;
}
.photo-preview-wrap img {
    max-width: 100%;
    max-height: 340px;
    border-radius: var(--radius-lg);
    object-fit: contain;
    box-shadow: var(--shadow-md);
}

/* File preview */
.file-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px 20px;
}
.file-preview-icon {
    width: 72px; height: 72px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.file-preview-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    word-break: break-all;
    max-width: 260px;
}

/* Voice recorder */
.voice-recorder { padding: 20px; }

.voice-display {
    text-align: center;
    margin-bottom: 24px;
}

.voice-timer {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -1px;
    margin-bottom: 16px;
}

.voice-wave {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.voice-wave-idle span,
.voice-wave span {
    width: 4px;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    height: 8px;
    transition: height 0.1s;
}

.voice-wave.active span {
    background: var(--primary);
    animation: waveAnim 0.6s ease-in-out infinite;
}
.voice-wave.active span:nth-child(1) { animation-delay: 0s; }
.voice-wave.active span:nth-child(2) { animation-delay: 0.06s; }
.voice-wave.active span:nth-child(3) { animation-delay: 0.12s; }
.voice-wave.active span:nth-child(4) { animation-delay: 0.18s; }
.voice-wave.active span:nth-child(5) { animation-delay: 0.24s; }
.voice-wave.active span:nth-child(6) { animation-delay: 0.18s; }
.voice-wave.active span:nth-child(7) { animation-delay: 0.12s; }
.voice-wave.active span:nth-child(8) { animation-delay: 0.06s; }
.voice-wave.active span:nth-child(9) { animation-delay: 0s; }
.voice-wave.active span:nth-child(10) { animation-delay: 0.06s; }

@keyframes waveAnim {
    0%, 100% { height: 8px; }
    50% { height: 42px; }
}

.voice-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.voice-record-btn {
    width: 68px; height: 68px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.45);
    transition: transform var(--transition), box-shadow var(--transition);
}
.voice-record-btn:hover { transform: scale(1.05); }
.voice-record-btn:active { transform: scale(0.96); }
.voice-record-btn.recording {
    background: var(--danger);
    box-shadow: 0 4px 16px rgba(240,70,70, 0.4);
    animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(240,70,70,0.4); }
    50% { box-shadow: 0 4px 24px rgba(240,70,70,0.7); }
}

.voice-ctrl-btn {
    padding: 10px 18px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition);
}
.voice-ctrl-btn:hover { background: var(--border); }
.voice-ctrl-cancel { color: var(--text-muted); }
.voice-ctrl-send {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.35);
}
.voice-ctrl-send:hover { background: var(--primary-dark); }

/* Theme options */
.theme-options {
    display: flex;
    gap: 12px;
    padding: 20px;
    justify-content: center;
}

.theme-option {
    flex: 1;
    max-width: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 12px;
    border-radius: var(--radius-lg);
    border: 2px solid var(--border);
    background: var(--surface-2);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: all var(--transition);
    position: relative;
}
.theme-option:hover { border-color: var(--primary); }

.theme-option-preview {
    width: 90px; height: 64px;
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.theme-preview-light {
    background: #f4f6fb;
}
.theme-preview-dark {
    background: #0d0f1a;
}

.tp-header {
    height: 18px;
}
.theme-preview-light .tp-header { background: #4f6ef7; }
.theme-preview-dark .tp-header { background: #161825; }

.tp-msg {
    height: 12px;
    border-radius: 8px;
    margin: 6px 8px 0;
    width: 60%;
}
.tp-msg-r {
    margin-left: 8px;
}
.theme-preview-light .tp-msg-r { background: #fff; border: 1px solid #e8eaf2; }
.theme-preview-dark .tp-msg-r { background: #1c1f31; }

.tp-msg-s {
    margin-left: auto;
    margin-right: 8px;
}
.theme-preview-light .tp-msg-s { background: #4f6ef7; }
.theme-preview-dark .tp-msg-s { background: #6b8bff; }

.theme-option-check {
    position: absolute;
    top: 8px; right: 8px;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 800;
}

/* Image view */
.image-view-content {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 20px;
}
.image-view-content img {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    object-fit: contain;
}
.image-view-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 40px; height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    z-index: 2;
    transition: background var(--transition);
}
.image-view-close:hover { background: rgba(255,255,255,0.25); }

/* ===========================
   TOAST NOTIFICATIONS
   =========================== */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 360px;
    width: calc(100% - 40px);
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    font-size: 0.88rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.25s ease-out;
    pointer-events: all;
}
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-icon { font-size: 1.1rem; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateY(-12px) scale(0.95); }
}

/* ===========================
   SCROLLBAR
   =========================== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }

/* ===========================
   RESPONSIVE
   =========================== */
@media (min-width: 680px) {
    body { background: #e8ecf4; }
    body.dark { background: #060810; }
    .app {
        height: 100vh;
        border-radius: var(--radius-xl);
        margin: 0 auto;
        top: 50%; left: 50%;
        transform: translate(-50%, -50%);
        position: fixed;
        max-height: 820px;
    }
    .modal-sheet {
        border-radius: var(--radius-xl);
        margin-bottom: 20px;
        max-width: 480px;
    }
}

@media (max-width: 400px) {
    .message { max-width: 82%; }
    .auth-card { padding: 20px; }
    .voice-timer { font-size: 2rem; }
}

/* High-DPI displays */
@media (-webkit-min-device-pixel-ratio: 2) {
    .media-message { image-rendering: -webkit-optimize-contrast; }
}
