/* css/style.css */

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

/* ============== LIGHT THEME ============== */
:root,
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-sidebar: #ffffff;
    --bg-hover: #eeeeee;
    --bg-active: #e3e3e3;
    --bg-message-out: #5B7CF7;
    --bg-message-in: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #888888;
    --text-message-out: #ffffff;
    --text-message-in: #1a1a1a;
    --border-color: #e0e0e0;
    --accent: #5B7CF7;
    --accent-hover: #4a6ae0;
    --danger: #e74c3c;
    --online: #2ecc71;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --chat-wallpaper: url('https://avatars.mds.yandex.net/i?id=a2bf3010ace698f516841d08b2f035ad_l-17960750-images-thumbs&n=13');
    --chat-wallpaper-size: cover;
    --chat-wallpaper-repeat: no-repeat;
}

/* ============== DARK THEME ============== */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #0e0e0e;
    --bg-sidebar: #1a1a1a;
    --bg-hover: #252525;
    --bg-active: #303030;
    --bg-message-out: #5B7CF7;
    --bg-message-in: #2a2a2a;
    --text-primary: #e8e8e8;
    --text-secondary: #777777;
    --text-message-out: #ffffff;
    --text-message-in: #e0e0e0;
    --border-color: #2a2a2a;
    --accent: #5B7CF7;
    --accent-hover: #6d8bff;
    --danger: #e74c3c;
    --online: #2ecc71;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --chat-wallpaper: url('https://img.freepik.com/premium-photo/abstract-background-design-rough-dark-angel-blue_851755-62479.jpg?semt=ais_hybrid&w=740');
    /* Обои отдалены — паттерн мельче, повторяется плиткой */
    --chat-wallpaper-size: 600px auto;
    --chat-wallpaper-repeat: repeat;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-secondary);
}

/* ===================== AUTH ===================== */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
}

.auth-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.logo-icon {
    width: 56px;
    height: 56px;
    background: var(--accent);
    color: #fff;
    font-size: 26px;
    font-weight: 700;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.auth-subtitle {
    color: var(--text-secondary);
    margin-top: 4px;
    font-size: 14px;
}

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

.auth-tab {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tab.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.auth-tab:hover:not(.active) {
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.form-group input:focus {
    border-color: var(--accent);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-full {
    width: 100%;
    padding: 12px;
}

.hidden {
    display: none !important;
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

[data-theme="dark"] .alert-error {
    background: #2d1515;
    border-color: #5c2020;
}

[data-theme="dark"] .alert-success {
    background: #0a3622;
    border-color: #14532d;
}

/* =================== MESSENGER =================== */

.messenger {
    display: flex;
    height: 100vh;
    background: var(--bg-primary);
}

/* ---------- SIDEBAR ---------- */

.sidebar {
    width: 340px;
    min-width: 340px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.sidebar-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.search-box {
    padding: 12px 20px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--accent);
    background: var(--bg-primary);
}

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

/* ---------- CONVERSATIONS ---------- */

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conversations-list::-webkit-scrollbar {
    width: 4px;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

[data-theme="dark"] .conversations-list::-webkit-scrollbar-thumb {
    background: #444;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

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

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

.avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    position: relative;
}

.avatar-online::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 11px;
    height: 11px;
    background: var(--online);
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
}

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

.conversation-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.conversation-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.conversation-time {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.conversation-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-last-msg {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.unread-badge {
    min-width: 20px;
    height: 20px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.loading-spinner {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.no-conversations {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.no-conversations p {
    margin-bottom: 4px;
}

/* ---------- SIDEBAR FOOTER ---------- */

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-profile .avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    font-size: 14px;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 13px;
}

.user-status-text {
    font-size: 11px;
    color: var(--online);
}

.sidebar-footer-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =========== CHAT AREA =========== */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-secondary);
}

/* ===== Обои чата — используем переменные ===== */
.chat-area.has-wallpaper .messages-container {
    background-image: var(--chat-wallpaper);
    background-size: var(--chat-wallpaper-size);
    background-position: center;
    background-repeat: var(--chat-wallpaper-repeat);
    background-attachment: fixed;
}

/* Полупрозрачный оверлей поверх обоев */
.chat-area.has-wallpaper .messages-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
}

[data-theme="light"] .chat-area.has-wallpaper .messages-container::before {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .chat-area.has-wallpaper .messages-container::before {
    background: rgba(0, 0, 0, 0.3);
}

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

.empty-state h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 16px;
}

.empty-state p {
    margin-top: 6px;
    font-size: 14px;
}

/* ---------- CHAT HEADER ---------- */

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    z-index: 2;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 16px;
}

.chat-user-info {
    display: flex;
    flex-direction: column;
}

.chat-user-name {
    font-weight: 600;
    font-size: 15px;
}

.chat-user-status {
    font-size: 12px;
    color: var(--text-secondary);
}

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

.btn-back {
    display: none;
}

/* ---------- MESSAGES ---------- */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.messages-container::-webkit-scrollbar {
    width: 5px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: rgba(150,150,150,0.4);
    border-radius: 5px;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: auto;
    position: relative;
    z-index: 1;
}

.message-row {
    display: flex;
    max-width: 70%;
    animation: msgIn 0.2s ease;
}

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

.message-row.outgoing {
    align-self: flex-end;
}

.message-row.incoming {
    align-self: flex-start;
}

.message-bubble {
    padding: 9px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.message-row.outgoing .message-bubble {
    background: var(--bg-message-out);
    color: var(--text-message-out);
    border-bottom-right-radius: 4px;
}

.message-row.incoming .message-bubble {
    background: var(--bg-message-in);
    color: var(--text-message-in);
    border-bottom-left-radius: 4px;
}

[data-theme="dark"] .message-bubble {
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.message-time {
    font-size: 10px;
    margin-top: 3px;
    text-align: right;
    opacity: 0.65;
}

.message-row.incoming .message-time {
    text-align: left;
}

.date-separator {
    text-align: center;
    margin: 16px 0;
    position: relative;
    z-index: 1;
}

.date-separator span {
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    padding: 4px 14px;
    border-radius: 12px;
    font-size: 12px;
    display: inline-block;
    backdrop-filter: blur(4px);
}

[data-theme="light"] .date-separator span {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-secondary);
}

.messages-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
    font-size: 14px;
    z-index: 1;
}

/* ---------- INPUT AREA ---------- */

.message-input-area {
    padding: 12px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    z-index: 2;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 6px 6px 6px 16px;
    transition: border-color 0.2s;
}

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

#message-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    padding: 6px 0;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
}

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

.btn-send {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border: none;
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-send:hover {
    background: var(--accent-hover);
}

/* =========== MODAL =========== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

[data-theme="dark"] .modal-overlay {
    background: rgba(0, 0, 0, 0.65);
}

.modal {
    background: var(--bg-primary);
    border-radius: 14px;
    width: 100%;
    max-width: 440px;
    max-height: 500px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    margin: 16px;
    border: 1px solid var(--border-color);
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-body input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    margin-bottom: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body input:focus {
    border-color: var(--accent);
}

.user-search-results {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

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

.user-result-item .avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 16px;
}

.user-result-info {
    display: flex;
    flex-direction: column;
}

.user-result-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.user-result-username {
    font-size: 12px;
    color: var(--text-secondary);
}

/* =========== RESPONSIVE =========== */

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: auto;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }

    .messenger.chat-open .sidebar {
        display: none;
    }

    .messenger.chat-open .chat-area {
        display: flex;
    }

    .btn-back {
        display: flex !important;
    }

    .message-row {
        max-width: 85%;
    }
}