@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
    --primary-color: #ff7b00;
    --secondary-color: #ffa048;
    --accent-color: #00D2D3;
    --bg-dark: #0F0F0F;
    --bg-section: #1A1A1A;
    --card-bg: #1F1F1F;
    --text-light: #FFFFFF;
    --text-gray: #B0B0B0;
    --border-color: #333333;
    --glow-red: rgba(220, 127, 20, 0.3);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark) url('img/bg.png') center/cover fixed no-repeat;
    color: var(--text-light);
    min-height: 100vh;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 36px;
    border-radius: 50px;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: 0.5px;
    border: none;
    cursor: pointer;
    transition: 0.3s ease;
}

.btn-primary {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: var(--text-light);
    box-shadow: 0 10px 30px var(--glow-red);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px var(--glow-red);
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(15,15,15,0.7);
    background-blend-mode: darken;
}

.login-wrap {
    padding: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.login-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 24px;
    padding: 50px 40px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-icon {
    width: 70px;
    height: 70px;
    margin: 0 auto 20px;
    border-radius: 50%;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 900;
    box-shadow: 0 10px 30px var(--glow-red);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 900;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-gray);
    margin-bottom: 30px;
    font-size: 0.95rem;
}

.login-error {
    background: rgba(220, 50, 50, 0.15);
    border: 1px solid rgba(220, 50, 50, 0.4);
    color: #ff8a8a;
    padding: 10px 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-form input {
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 15px 18px;
    color: var(--text-light);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: 0.3s ease;
}

.login-form input:focus {
    border-color: var(--primary-color);
}

.login-btn { width: 100%; }

/* Panel */
.panel-header {
    background: rgba(15,15,15,0.9);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.panel-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-logo {
    font-weight: 900;
    font-size: 1.3rem;
    color: var(--primary-color);
    text-decoration: none;
}

.panel-logout {
    color: var(--text-gray);
    text-decoration: none;
    font-weight: 600;
    padding: 8px 18px;
    border: 2px solid var(--border-color);
    border-radius: 50px;
    transition: 0.3s ease;
}

.panel-logout:hover {
    border-color: var(--primary-color);
    color: var(--text-light);
}

.panel-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 20px;
}

.panel-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 30px;
}

.back-link {
    display: inline-block;
    color: var(--text-gray);
    text-decoration: none;
    margin-bottom: 20px;
    font-weight: 600;
    transition: 0.3s ease;
}

.back-link:hover { color: var(--primary-color); }

.direction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 25px;
}

.direction-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 30px;
    text-decoration: none;
    color: var(--text-light);
    transition: 0.3s ease;
}

.direction-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-5px);
    box-shadow: 0 15px 40px var(--glow-red);
}

.direction-icon { font-size: 2rem; margin-bottom: 12px; }
.direction-card h3 { margin-bottom: 8px; font-size: 1.2rem; }
.direction-card p { color: var(--text-gray); font-size: 0.9rem; }

/* Conversations */
.conv-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 15px 20px;
    text-decoration: none;
    color: var(--text-light);
    transition: 0.3s ease;
}

.conv-item:hover {
    border-color: var(--primary-color);
}

.conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--border-color);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 700; margin-bottom: 4px; }
.conv-last {
    color: var(--text-gray);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-last-author { color: #d0d0d0; font-weight: 600; }

.conv-unread {
    background: var(--primary-color);
    color: var(--text-light);
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 24px;
    height: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.loader { color: var(--text-gray); padding: 30px 0; text-align: center; }

/* Chat */
.chat-main { display: flex; flex-direction: column; }

.chat-window {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    height: 65vh;
    overflow: hidden;
    position: relative;
}

.chat-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255,255,255,0.02);
    flex-shrink: 0;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-section);
    flex-shrink: 0;
}

.chat-topbar-info { min-width: 0; }

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

.chat-topbar-sub {
    font-size: 0.8rem;
    color: var(--text-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pinned-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: rgba(255, 123, 0, 0.08);
    border-bottom: 1px solid var(--border-color);
    border-left: 3px solid var(--primary-color);
    flex-shrink: 0;
    cursor: pointer;
    transition: 0.2s ease;
}

.pinned-bar:hover { background: rgba(255, 123, 0, 0.14); }

.pinned-icon { font-size: 1rem; flex-shrink: 0; }

.pinned-body { min-width: 0; flex: 1; }

.pinned-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.pinned-text {
    font-size: 0.85rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pinned-name { font-weight: 600; color: var(--primary-color); }

/* Полноэкранный просмотр закреплённого сообщения (как во ВКонтакте) */
.pinned-view {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border-radius: 20px;
    overflow: hidden;
}

.pinned-view-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.pinned-view-back {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.pinned-view-back:hover { color: var(--primary-color); }

.pinned-view-title { font-weight: 700; font-size: 1.05rem; }

.pinned-view-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.pinned-view-date {
    background: var(--bg-section);
    color: var(--text-gray);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 50px;
    margin-bottom: 18px;
}

.pinned-view-msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
}

.pinned-view-msg .msg-avatar { width: 36px; height: 36px; }

.pinned-view-bubble {
    background: var(--bg-section);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px 16px;
    max-width: calc(100% - 46px);
}

.pinned-view-name {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.pinned-view-text {
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg { display: flex; align-items: flex-end; gap: 8px; }
.msg-in { justify-content: flex-start; }
.msg-out { justify-content: flex-end; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-section);
}

.msg-content {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.msg-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.msg-text { white-space: pre-wrap; }

.msg-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    align-self: flex-start;
}
.msg-out .msg-actions { align-self: flex-end; }

.msg-reply-btn {
    background: none;
    border: none;
    color: var(--text-gray);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 4px 2px 0;
    opacity: 0.7;
}
.msg-reply-btn:hover { opacity: 1; color: var(--primary-color); }

.msg-delete-btn {
    background: none;
    border: none;
    color: var(--text-gray);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 4px 2px 0;
    opacity: 0.7;
    line-height: 1;
}
.msg-delete-btn:hover { opacity: 1; color: #ff6b6b; }

.msg-meta-inline {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.75);
    white-space: nowrap;
}

.msg-in .msg-meta-inline { color: rgba(255,255,255,0.45); }

.msg-time { opacity: 0.95; }

.msg-ticks { letter-spacing: -2px; color: #fff; }

.reply-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 15px;
    background: var(--bg-section);
    border-top: 1px solid var(--border-color);
    border-left: 3px solid var(--primary-color);
}

.reply-preview-body { min-width: 0; }
.reply-preview-name { font-size: 0.8rem; font-weight: 600; color: var(--primary-color); }
.reply-preview-text {
    font-size: 0.85rem;
    color: var(--text-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-preview-cancel {
    background: none;
    border: none;
    color: var(--text-gray);
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
}
.reply-preview-cancel:hover { color: var(--text-light); }

.msg-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg-reply {
    border-left: 3px solid var(--primary-color);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 6px 10px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    opacity: 0.9;
}

.msg-reply-name {
    display: block;
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.msg-out .msg-reply {
    border-left-color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.msg-out .msg-reply-name { color: #fff; }

.msg-fwd {
    border-left: 3px solid var(--border-color);
    padding-left: 10px;
    margin-bottom: 8px;
}

.msg-fwd-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 6px 10px;
    margin-bottom: 6px;
    font-size: 0.85rem;
}

.msg-fwd-name {
    display: block;
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.msg-fwd-text { opacity: 0.9; }

.load-more-wrap {
    display: flex;
    justify-content: center;
    padding: 4px 0 12px;
}

.load-more-wrap .btn {
    padding: 8px 18px;
    font-size: 0.85rem;
}

.msg-in .msg-bubble { background: var(--bg-section); border: 1px solid var(--border-color); }
.msg-out .msg-bubble { background: linear-gradient(45deg, var(--primary-color), var(--secondary-color)); }

.msg-system {
    text-align: center;
    color: var(--text-gray);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 4px 20px;
    line-height: 1.4;
}

.msg-system b { color: var(--text-light); font-weight: 700; }

.chat-form {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-top: 1px solid var(--border-color);
}

.chat-form input {
    flex: 1;
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    border-radius: 50px;
    padding: 12px 20px;
    color: var(--text-light);
    font-family: inherit;
    outline: none;
}

.chat-form input:focus { border-color: var(--primary-color); }
.chat-form .btn { padding: 12px 26px; }

/* Кнопки-иконки (фото / голосовое) рядом с полем ввода */
.icon-btn {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--bg-dark);
    color: var(--text-light);
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
    user-select: none;
    touch-action: none;
}

.icon-btn:hover { border-color: var(--primary-color); }
.icon-btn:disabled { opacity: 0.5; cursor: default; }

.voice-btn.recording {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    border-color: var(--primary-color);
    transform: scale(1.08);
}

/* Панель записи голосового сообщения — заменяет форму, пока идёт запись */
.recording-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    border-top: 1px solid var(--border-color);
}

.recording-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff3b3b;
    flex-shrink: 0;
    animation: recording-pulse 1s infinite ease-in-out;
}

.recording-dot.static { animation: none; opacity: 1; }

@keyframes recording-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.recording-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.recording-hint {
    color: var(--text-gray);
    font-size: 0.85rem;
    flex: 1;
}

.recording-cancel {
    flex-shrink: 0;
    background: none;
    border: 2px solid var(--border-color);
    color: var(--text-light);
    border-radius: 50px;
    padding: 8px 16px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
}

.recording-cancel:hover { border-color: var(--primary-color); color: var(--primary-color); }

.recording-send {
    flex-shrink: 0;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    border: none;
    color: var(--text-light);
    border-radius: 50px;
    padding: 8px 18px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 6px 18px var(--glow-red);
}

.recording-send:hover { transform: translateY(-1px); }
.recording-send:disabled { opacity: 0.5; cursor: default; box-shadow: none; transform: none; }

/* Вложения в сообщениях */
.msg-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.msg-photo {
    max-width: 220px;
    max-height: 280px;
    width: 100%;
    border-radius: 12px;
    object-fit: cover;
    display: block;
}

.msg-sticker {
    width: 120px;
    height: 120px;
    object-fit: contain;
    display: block;
    margin-bottom: 6px;
}

/* Голосовые сообщения — плеер в стиле ВКонтакте: круглая кнопка play,
   полоса прогресса и таймер справа. */
.msg-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 220px;
    margin-bottom: 6px;
    padding: 6px 12px 6px 6px;
    border-radius: 22px;
    background: rgba(0, 0, 0, 0.18);
}

.msg-out .msg-voice { background: rgba(0, 0, 0, 0.15); }
.msg-in .msg-voice { background: rgba(255, 255, 255, 0.06); }

.msg-voice-audio-el { display: none; }

.msg-voice-play {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    background: var(--text-light);
    color: var(--primary-color);
}

.msg-in .msg-voice-play { background: var(--primary-color); color: var(--text-light); }

.msg-voice-track {
    position: relative;
    flex: 1;
    height: 22px;
    cursor: pointer;
}

.msg-voice-track::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.35);
}

.msg-in .msg-voice-track::before { background: rgba(255, 255, 255, 0.15); }

.msg-voice-progress {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 3px;
    width: 0%;
    border-radius: 2px;
    background: var(--text-light);
    pointer-events: none;
}

.msg-in .msg-voice-progress { background: var(--primary-color); }

.msg-voice-progress::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: inherit;
}

.msg-voice-duration {
    flex-shrink: 0;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.85);
}

.msg-in .msg-voice-duration { color: var(--text-gray); }

/* Разделитель «Непрочитанные сообщения», как в нативном клиенте ВКонтакте */
.unread-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 6px 0;
}

.unread-divider span {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: var(--text-light);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 6px 16px;
    border-radius: 50px;
    box-shadow: 0 6px 18px var(--glow-red);
}

@media (max-width: 600px) {
    .panel-title { font-size: 1.5rem; }
    .msg-content { max-width: 85%; }
    .msg-photo { max-width: 170px; max-height: 220px; }
}
