/* ========================================================================
   OurTgApp — Modern Dark Theme
   ======================================================================== */

:root {
    /* --- Palette --- */
    --bg-primary: #0f1923;
    --bg-secondary: #0a1220;
    --bg-sidebar: #0c1525;
    --bg-surface: #152232;
    --bg-msg-in: #1a2d42;
    --bg-msg-out: #1d4470;
    --bg-input: #1a2b3d;
    --bg-hover: #162435;
    --bg-active: #1d3a5c;

    /* --- Text --- */
    --text-primary: #e8edf2;
    --text-secondary: #7c8d9e;
    --text-tertiary: #546778;

    /* --- Accent --- */
    --accent: #3d9be9;
    --accent-light: #5bb0f5;
    --accent-dim: #2a6fa8;
    --accent-glow: rgba(61, 155, 233, 0.15);
    --accent-gradient: linear-gradient(135deg, #3d9be9 0%, #5b7fff 100%);

    /* --- Borders & Shadows --- */
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.45);
    --shadow-glow: 0 0 20px rgba(61, 155, 233, 0.12);

    /* --- Radii --- */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* --- Misc --- */
    --danger: #e55b5b;
    --success: #4ecf73;
    --glass: rgba(15, 25, 35, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);

    /* --- Transition --- */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv11', 'ss01';
}

.hidden { display: none !important; }

/* ===================== Layout ===================== */

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ===================== Sidebar ===================== */

#sidebar {
    width: 380px;
    min-width: 380px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 2;
}

#sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(12, 21, 37, 0.95) 0%, var(--bg-sidebar) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.01em;
}

.sidebar-logo {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-logo svg {
    width: 16px;
    height: 16px;
}

/* Search */

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
    transition: color var(--transition-fast);
}

#search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: all var(--transition-normal);
}

#search-input::placeholder {
    color: var(--text-tertiary);
}

#search-input:focus {
    border-color: var(--accent);
    background: rgba(26, 43, 61, 0.9);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#search-input:focus ~ .search-icon,
.search-wrapper:focus-within .search-icon {
    color: var(--accent);
}

/* Chat list */

#chat-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
    padding: 4px 0;
}

/* ---- Chat item ---- */

.chat-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin: 1px 6px;
    cursor: pointer;
    gap: 12px;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    position: relative;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--bg-active);
    box-shadow: inset 3px 0 0 var(--accent);
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-top-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.chat-name {
    font-size: 14.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.chat-type-icon {
    color: var(--text-tertiary);
    margin-right: 3px;
    font-size: 13px;
}

.chat-date {
    font-size: 12px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    margin-left: 8px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.chat-preview {
    font-size: 13.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.35;
}

.chat-preview .preview-sender {
    color: var(--accent);
    font-weight: 500;
}

/* ===================== Main Area ===================== */

#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: var(--bg-primary);
}

/* ---- Empty state ---- */

#empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    gap: 8px;
    user-select: none;
}

.empty-icon {
    color: var(--text-tertiary);
    opacity: 0.5;
    margin-bottom: 8px;
    animation: empty-float 4s ease-in-out infinite;
}

@keyframes empty-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.empty-text {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.empty-hint {
    font-size: 14px;
    color: var(--text-tertiary);
}

/* ---- Chat view ---- */

#chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-header {
    padding: 12px 24px;
    background: var(--glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    z-index: 3;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.15);
}

#chat-header .avatar {
    width: 42px;
    height: 42px;
    font-size: 16px;
}

#chat-header-name {
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

#chat-header-details {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-top: 1px;
}

/* ---- Messages ---- */

#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

#messages-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 0 calc(12% - 16px);
    max-width: 100%;
}

#messages-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    color: var(--text-tertiary);
    font-size: 13px;
}

.loader-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* Date separator */

.date-separator {
    text-align: center;
    padding: 10px 0 6px;
    position: sticky;
    top: 0;
    z-index: 1;
}

.date-separator span {
    background: rgba(10, 18, 32, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 500;
    padding: 5px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    letter-spacing: 0.01em;
}

/* ---- Message bubble ---- */

.message {
    max-width: 62%;
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    position: relative;
    line-height: 1.5;
    font-size: 14px;
    min-width: 90px;
    animation: msg-appear 0.2s ease-out;
}

@keyframes msg-appear {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-in {
    align-self: flex-start;
    background: var(--bg-msg-in);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.message-out {
    align-self: flex-end;
    background: var(--bg-msg-out);
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}

.msg-sender {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-light);
    margin-bottom: 2px;
}

.msg-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.msg-text a {
    color: var(--accent-light);
    text-decoration: none;
    border-bottom: 1px solid rgba(91, 176, 245, 0.3);
    transition: border-color var(--transition-fast);
}

.msg-text a:hover {
    border-bottom-color: var(--accent-light);
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 3px;
    font-weight: 500;
}

.edited-mark {
    font-style: italic;
    opacity: 0.7;
}

/* Forward */
.msg-forward {
    border-left: 2px solid var(--accent);
    padding-left: 10px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
}

/* Reply */
.msg-reply {
    border-left: 2px solid var(--accent);
    padding-left: 10px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.msg-reply:hover { color: var(--accent); }

/* ---- Media in messages ---- */

.msg-photo {
    border-radius: var(--radius-md);
    display: block;
    max-width: 100%;
    cursor: pointer;
    transition: filter var(--transition-fast);
}

.msg-photo:hover {
    filter: brightness(1.05);
}

.msg-video {
    border-radius: var(--radius-md);
    display: block;
    max-width: 100%;
}

.msg-video-note {
    border-radius: 50%;
    width: 240px;
    height: 240px;
    object-fit: cover;
    box-shadow: var(--shadow-md);
}

.msg-sticker {
    display: block;
    max-width: 200px;
}

.msg-gif {
    border-radius: var(--radius-md);
    display: block;
    max-width: 320px;
}

.msg-audio {
    display: flex;
    align-items: center;
    gap: 8px;
}

.msg-audio audio {
    max-width: 260px;
    height: 36px;
    border-radius: var(--radius-sm);
}

.msg-document {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.msg-document:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--border-light);
}

.doc-icon {
    font-size: 28px;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-glow);
    border-radius: var(--radius-sm);
}

.doc-name {
    font-size: 14px;
    font-weight: 500;
    word-break: break-all;
}

.doc-size {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* ---- Extracted text (collapsible) ---- */

.extracted-text {
    margin-top: 6px;
    font-size: 12px;
    border-top: 1px solid var(--border);
    padding-top: 6px;
}

.extracted-text summary {
    cursor: pointer;
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color var(--transition-fast);
}

.extracted-text summary:hover {
    color: var(--accent-light);
}

.extracted-text[open] summary {
    margin-bottom: 4px;
}

.extracted-content {
    margin-top: 4px;
    white-space: pre-wrap;
    color: var(--text-secondary);
    max-height: 200px;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.45;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-sm);
}

/* ---- Input area ---- */

#message-input-area {
    display: flex;
    align-items: flex-end;
    padding: 10px calc(12% - 16px);
    background: var(--glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--glass-border);
    gap: 6px;
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    line-height: 1.45;
    transition: all var(--transition-normal);
}

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

#message-input:focus {
    border-color: var(--accent-dim);
    background: rgba(26, 43, 61, 0.95);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--accent-gradient);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(61, 155, 233, 0.3);
}

#send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(61, 155, 233, 0.4);
}

#send-btn:active {
    transform: scale(0.95);
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* ---- Action buttons (attach, mic, camera) ---- */

#attach-btn,
#mic-btn,
#camera-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

#attach-btn:hover,
#mic-btn:hover,
#camera-btn:hover {
    color: var(--accent);
    background: var(--accent-glow);
}

/* Recording state */
#mic-btn.recording {
    color: #fff;
    background: var(--danger);
    box-shadow: 0 0 16px rgba(229, 91, 91, 0.45);
    animation: mic-recording 1.5s ease-in-out infinite;
}

@keyframes mic-recording {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 16px rgba(229, 91, 91, 0.45);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 24px rgba(229, 91, 91, 0.6);
    }
}

/* ---- File preview ---- */

#file-preview {
    display: flex;
    align-items: center;
    padding: 10px calc(12% - 16px);
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    gap: 8px;
    flex-shrink: 0;
}

#file-preview-content {
    flex: 1;
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

#file-preview-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

#file-preview-close:hover {
    color: var(--danger);
    background: rgba(229, 91, 91, 0.1);
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    min-width: 0;
    flex-shrink: 0;
}

.file-thumb-img {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.file-thumb-icon {
    font-size: 24px;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--accent-glow);
    border-radius: var(--radius-sm);
}

.file-preview-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.file-preview-size {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* ---- Drag & drop overlay ---- */

#messages-container.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -6px;
    background: rgba(61, 155, 233, 0.04);
}

/* ---- Voice recording bar ---- */

#voice-record-bar {
    display: flex;
    align-items: center;
    padding: 14px calc(12% - 16px);
    background: linear-gradient(90deg,
        rgba(229, 91, 91, 0.08) 0%,
        var(--bg-sidebar) 40%);
    border-top: 1px solid rgba(229, 91, 91, 0.15);
    gap: 0;
    flex-shrink: 0;
    animation: voice-bar-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes voice-bar-in {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.voice-record-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.record-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: record-pulse 1.4s ease-in-out infinite;
    flex-shrink: 0;
    box-shadow: 0 0 10px rgba(229, 91, 91, 0.6);
}

@keyframes record-pulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 10px rgba(229, 91, 91, 0.6);
        transform: scale(1);
    }
    50% {
        opacity: 0.25;
        box-shadow: 0 0 4px rgba(229, 91, 91, 0.15);
        transform: scale(0.85);
    }
}

.record-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--danger);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#voice-record-timer {
    font-size: 15px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 40px;
}

/* --- Waveform equalizer --- */

.voice-waveform {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 32px;
    padding: 0 20px;
}

.wave-bar {
    width: 3px;
    border-radius: 2px;
    background: var(--danger);
    opacity: 0.6;
    animation: wave-eq 1.2s ease-in-out infinite;
}

.wave-bar:nth-child(1)  { height: 8px;  animation-delay: 0.00s; }
.wave-bar:nth-child(2)  { height: 14px; animation-delay: 0.08s; }
.wave-bar:nth-child(3)  { height: 20px; animation-delay: 0.16s; }
.wave-bar:nth-child(4)  { height: 10px; animation-delay: 0.24s; }
.wave-bar:nth-child(5)  { height: 26px; animation-delay: 0.32s; }
.wave-bar:nth-child(6)  { height: 16px; animation-delay: 0.40s; }
.wave-bar:nth-child(7)  { height: 22px; animation-delay: 0.48s; }
.wave-bar:nth-child(8)  { height: 12px; animation-delay: 0.56s; }
.wave-bar:nth-child(9)  { height: 28px; animation-delay: 0.64s; }
.wave-bar:nth-child(10) { height: 18px; animation-delay: 0.72s; }
.wave-bar:nth-child(11) { height: 24px; animation-delay: 0.80s; }
.wave-bar:nth-child(12) { height: 10px; animation-delay: 0.88s; }
.wave-bar:nth-child(13) { height: 20px; animation-delay: 0.96s; }
.wave-bar:nth-child(14) { height: 14px; animation-delay: 1.04s; }
.wave-bar:nth-child(15) { height: 26px; animation-delay: 0.12s; }
.wave-bar:nth-child(16) { height: 8px;  animation-delay: 0.20s; }
.wave-bar:nth-child(17) { height: 18px; animation-delay: 0.28s; }
.wave-bar:nth-child(18) { height: 22px; animation-delay: 0.36s; }
.wave-bar:nth-child(19) { height: 12px; animation-delay: 0.44s; }
.wave-bar:nth-child(20) { height: 16px; animation-delay: 0.52s; }

@keyframes wave-eq {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}

#voice-record-cancel {
    background: none;
    border: 1px solid rgba(229, 91, 91, 0.25);
    color: var(--danger);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    opacity: 0.8;
}

#voice-record-cancel:hover {
    opacity: 1;
    background: rgba(229, 91, 91, 0.12);
    border-color: rgba(229, 91, 91, 0.4);
    transform: scale(1.08);
}

/* ---- Video recording overlay ---- */

#video-record-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    animation: overlay-in 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes overlay-in {
    from {
        opacity: 0;
        backdrop-filter: blur(0);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(20px);
    }
}

.video-preview-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#video-preview {
    max-width: 75%;
    max-height: 58vh;
    border-radius: var(--radius-xl);
    background: #000;
    box-shadow:
        0 0 0 1px rgba(229, 91, 91, 0.2),
        0 0 40px rgba(229, 91, 91, 0.08),
        var(--shadow-lg);
    animation: video-glow 2.5s ease-in-out infinite;
}

@keyframes video-glow {
    0%, 100% {
        box-shadow:
            0 0 0 1px rgba(229, 91, 91, 0.2),
            0 0 40px rgba(229, 91, 91, 0.08),
            var(--shadow-lg);
    }
    50% {
        box-shadow:
            0 0 0 1px rgba(229, 91, 91, 0.35),
            0 0 60px rgba(229, 91, 91, 0.15),
            var(--shadow-lg);
    }
}

.video-rec-badge {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(229, 91, 91, 0.9);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.08em;
    box-shadow: 0 2px 10px rgba(229, 91, 91, 0.4);
    animation: rec-badge-pulse 2s ease-in-out infinite;
}

.video-rec-badge .record-dot {
    width: 7px;
    height: 7px;
    background: #fff;
    box-shadow: none;
    animation: record-pulse 1.4s ease-in-out infinite;
}

@keyframes rec-badge-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.video-timer-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 6px 14px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: var(--radius-full);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #fff;
}

#video-record-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.video-ctrl-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: none;
}

.video-ctrl-cancel {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: var(--text-secondary);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.video-ctrl-cancel:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.25) !important;
    transform: scale(1.03);
}

.video-ctrl-stop {
    background: linear-gradient(135deg, var(--accent) 0%, #5b7fff 100%);
    color: #fff;
    box-shadow: 0 4px 20px rgba(61, 155, 233, 0.35);
}

.video-ctrl-stop:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 28px rgba(61, 155, 233, 0.45);
}

.video-ctrl-stop:active {
    transform: scale(0.97);
}

/* ===================== Search results ===================== */

#search-results {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 25, 35, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    overflow-y: auto;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

#search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--glass);
    border-bottom: 1px solid var(--glass-border);
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
    letter-spacing: -0.01em;
}

#search-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

#search-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

#search-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.search-item {
    padding: 12px 24px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-radius: var(--radius-sm);
    margin: 2px 8px;
}

.search-item:hover {
    background: var(--bg-hover);
}

.search-chat-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
}

.search-msg-text {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.45;
}

.search-msg-text mark {
    background: rgba(61, 155, 233, 0.25);
    color: var(--accent-light);
    border-radius: 2px;
    padding: 1px 3px;
}

.search-msg-date {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 6px;
    font-weight: 500;
}

/* ===================== Image viewer ===================== */

#image-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    cursor: pointer;
    animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

#image-viewer img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    animation: zoom-in 0.25s ease-out;
}

@keyframes zoom-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===================== Scrollbar (Webkit) ===================== */

::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ===================== Avatar colors ===================== */

.avatar-color-0 { background: linear-gradient(135deg, #e17076, #d44f56); }
.avatar-color-1 { background: linear-gradient(135deg, #7bc862, #5caa44); }
.avatar-color-2 { background: linear-gradient(135deg, #e5ca77, #d4b044); }
.avatar-color-3 { background: linear-gradient(135deg, #65aadd, #4088c0); }
.avatar-color-4 { background: linear-gradient(135deg, #a695e7, #8b6fd4); }
.avatar-color-5 { background: linear-gradient(135deg, #ee7aae, #d45a90); }
.avatar-color-6 { background: linear-gradient(135deg, #6ec9cb, #4eaeb0); }
.avatar-color-7 { background: linear-gradient(135deg, #faa774, #e08a55); }

/* ===================== Audio player style ===================== */

audio::-webkit-media-controls-panel {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
}

/* ===================== Selection ===================== */

::selection {
    background: rgba(61, 155, 233, 0.3);
    color: #fff;
}

/* ===================== Focus visible ===================== */

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible) {
    outline: none;
}

/* ======================== Login Screen ======================== */
#login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 9999;
}

.login-form {
    width: 100%;
    max-width: 360px;
    padding: 40px 32px;
    background: var(--bg-secondary);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.login-logo {
    color: var(--accent);
    margin-bottom: 4px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 8px;
}

.login-field {
    width: 100%;
}

.login-field input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.login-field input:focus {
    border-color: var(--accent);
}

.login-field input::placeholder {
    color: var(--text-secondary);
}

.login-error {
    color: var(--danger);
    font-size: 13px;
    min-height: 18px;
    text-align: center;
}

.login-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}

.login-btn:hover {
    opacity: 0.9;
}

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
