/* =========================================================
   LegaGram — интерфейс в стиле Telegram
   ========================================================= */

:root,
[data-theme="dark"] {
    --bg-sidebar: #17212b;
    --bg-chat: #0e1621;
    --bg-gap: #0e1621;
    --bg-hover: #202b36;
    --bg-active: #2b5278;
    --bg-input: #242f3d;
    --bg-composer: #182533;
    --bg-menu: #1e2a37;
    --border: #0b121a;
    --text-main: #f5f5f5;
    --text-secondary: #7f91a4;
    --text-muted: #6d7f8f;
    --accent: #6ab3f3;
    --accent-btn: #5288c1;
    --accent-btn-hover: #5f97d3;
    --msg-own: #2b5278;
    --msg-other: #182533;
    --meta-own: #7da8d3;
    --meta-other: #6d7f8f;
    --check: #7ac1f9;
    --pill-bg: rgba(14, 22, 33, 0.62);
    --switch-off: #3a4a5a;
    --danger: #ec3942;
    --success: #4dcd5e;
    --overlay: rgba(0, 0, 0, 0.6);
    --scroll: #34455a;
    --transition: 0.15s ease;
}

[data-theme="light"] {
    --bg-sidebar: #ffffff;
    --bg-chat: #c9dbb9;
    --bg-gap: #f1f1f1;
    --bg-hover: #f4f4f5;
    --bg-active: #3390ec;
    --bg-input: #f4f4f5;
    --bg-composer: #ffffff;
    --bg-menu: #ffffff;
    --border: #dadce0;
    --text-main: #000000;
    --text-secondary: #707579;
    --text-muted: #a2acb4;
    --accent: #3390ec;
    --accent-btn: #3390ec;
    --accent-btn-hover: #2b84dd;
    --msg-own: #eeffde;
    --msg-other: #ffffff;
    --meta-own: #5da557;
    --meta-other: #a0acb6;
    --check: #4fae4e;
    --pill-bg: rgba(60, 90, 60, 0.42);
    --switch-off: #c4c9cc;
    --danger: #e53935;
    --success: #31b545;
    --overlay: rgba(0, 0, 0, 0.4);
    --scroll: #c1c9d1;
}

[data-density="compact"] .chat-item { height: 56px; padding: 0 8px; }
[data-density="compact"] .chat-item .avatar { width: 42px; height: 42px; font-size: 16px; }
[data-density="compact"] .message { font-size: 14px; padding: 4px 9px 5px; }
[data-density="compact"] .message.first { margin-top: 5px; }
[data-density="compact"] .menu-item { height: 38px; }

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

html, body { width: 100%; height: 100%; }

body {
    font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-sidebar);
    color: var(--text-main);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 10px; }

button {
    font-family: inherit; font-size: inherit; color: inherit;
    border: none; background: transparent; cursor: pointer;
    -webkit-tap-highlight-color: transparent; user-select: none;
}
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
input, textarea { font-family: inherit; }
[hidden] { display: none !important; }

svg.i {
    width: 24px; height: 24px; flex-shrink: 0;
    fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}
svg.i.fill { fill: currentColor; stroke: none; }

@keyframes pop {
    from { opacity: 0; transform: scale(0.94); }
    to   { opacity: 1; transform: scale(1); }
}

/* =========================================================
   АВАТАРЫ (цвета как в Telegram)
   ========================================================= */

.avatar {
    width: 54px; height: 54px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: #fff; font-size: 20px; font-weight: 500;
    user-select: none; flex-shrink: 0;
    background: linear-gradient(#72d5fd, #2a9ef1);
    overflow: hidden; position: relative;
}
.avatar.large { width: 42px; height: 42px; font-size: 17px; }
.avatar.xl    { width: 84px; height: 84px; font-size: 32px; }
.avatar-image {
    width: 100%; height: 100%; object-fit: cover; display: block;
}

.av-0 { background: linear-gradient(#ff885e, #ff516a); }
.av-1 { background: linear-gradient(#ffcd6a, #ffa85c); }
.av-2 { background: linear-gradient(#82b1ff, #665fff); }
.av-3 { background: linear-gradient(#a0de7e, #54cb68); }
.av-4 { background: linear-gradient(#53edd6, #28c9b7); }
.av-5 { background: linear-gradient(#72d5fd, #2a9ef1); }
.av-6 { background: linear-gradient(#e0a2f3, #d669ed); }

.avatar-wrap { position: relative; flex-shrink: 0; display: inline-flex; }

.online-dot {
    position: absolute; right: 0; bottom: 0;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--success);
    border: 2.5px solid var(--bg-sidebar);
}
.online-dot.large { width: 18px; height: 18px; right: 4px; bottom: 4px; border-width: 3px; }
.chat-item:hover .online-dot { border-color: var(--bg-hover); }
.chat-item.active .online-dot { border-color: var(--bg-active); }

.lock-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: rgba(236, 57, 66, 0.12); color: var(--danger);
    font-size: 10px; line-height: 1; margin-left: 4px;
    vertical-align: middle; transform: translateY(-1px);
}

.new-chat-actions {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px;
}
.new-chat-action, .report-option, .primary-button, .secondary-button {
    border-radius: 12px; transition: background var(--transition), opacity var(--transition);
}
.new-chat-action {
    background: var(--bg-hover); color: var(--text-main); padding: 10px 12px; font-weight: 500;
}
.new-chat-action:hover, .report-option:hover, .primary-button:hover, .secondary-button:hover {
    filter: brightness(1.05);
}
.contact-section-label {
    color: var(--text-secondary); font-size: 12px; text-transform: uppercase; margin: 8px 0 10px; letter-spacing: .08em;
}
.primary-button {
    background: var(--accent-btn); color: white; padding: 10px 14px; font-weight: 500;
}
.secondary-button {
    background: var(--bg-hover); color: var(--text-main); padding: 10px 14px; font-weight: 500;
}
.block-button.secondary {
    background: rgba(106, 179, 243, 0.12); color: var(--accent);
}
.report-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px;
}
.report-option {
    padding: 10px 8px; background: var(--bg-hover); color: var(--text-main); text-align: center;
}
.report-option.active {
    background: var(--accent); color: white;
}
#reportDetails {
    width: 100%; resize: vertical; min-height: 90px; border: 1px solid var(--border); border-radius: 12px;
    background: transparent; color: var(--text-main); padding: 10px 12px; margin-bottom: 12px;
}
.report-actions {
    display: flex; justify-content: flex-end; gap: 8px;
}
.avatar-group {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

/* =========================================================
   ЭКРАН ВХОДА
   ========================================================= */

.auth-screen {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    padding: 24px; overflow-y: auto;
    background: var(--bg-sidebar);
}

.auth-card { width: 100%; max-width: 360px; margin: auto; }

.auth-logo {
    display: flex; flex-direction: column; align-items: center;
    gap: 18px; margin-bottom: 8px;
}
.auth-logo .logo-icon {
    width: 128px; height: 128px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(#5fb4ff, #2b84e8);
    color: #fff; font-size: 64px; font-weight: 500;
}
.auth-logo span { font-size: 32px; font-weight: 500; }

.auth-subtitle {
    text-align: center; font-size: 15px; line-height: 1.4;
    color: var(--text-secondary); margin-bottom: 22px;
}

.auth-tabs {
    display: flex; gap: 4px; padding: 4px; margin-bottom: 20px;
    background: var(--bg-input); border-radius: 12px;
}
.auth-tab {
    flex: 1; height: 36px; border-radius: 9px;
    color: var(--text-secondary); font-size: 14px; font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.auth-tab:hover { color: var(--text-main); }
.auth-tab.active { background: var(--bg-sidebar); color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }

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

.auth-field { position: relative; display: block; }
.auth-field span {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%);
    padding: 0 4px;
    background: var(--bg-sidebar);
    color: var(--text-secondary);
    font-size: 16px; pointer-events: none;
    transition: top var(--transition), font-size var(--transition), color var(--transition);
}
.auth-field input {
    width: 100%; height: 54px; padding: 0 16px;
    border: 1px solid var(--text-muted); border-radius: 12px; outline: none;
    background: transparent; color: var(--text-main); font-size: 16px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.auth-field input:focus { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.auth-field:focus-within span,
.auth-field:has(input:not(:placeholder-shown)) span { top: 0; font-size: 12px; }
.auth-field:focus-within span { color: var(--accent); }

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

.auth-submit {
    height: 54px; border-radius: 12px;
    background: var(--accent-btn); color: #fff;
    font-size: 15px; font-weight: 500; letter-spacing: .2px;
    transition: background var(--transition);
}
.auth-submit:hover { background: var(--accent-btn-hover); }

.auth-lang { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.lang-chip {
    padding: 5px 12px; border-radius: 14px;
    color: var(--text-secondary); font-size: 13px; font-weight: 500;
}
.lang-chip:hover { background: var(--bg-hover); }
.lang-chip.active { color: var(--accent); }

/* =========================================================
   КАРКАС
   ========================================================= */

.app {
    width: 100%; height: 100vh; height: 100dvh;
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    overflow: hidden;
    background: var(--bg-sidebar);
}
.app.profile-open { grid-template-columns: 380px minmax(0, 1fr) 340px; }

/* =========================================================
   ЛЕВАЯ ПАНЕЛЬ
   ========================================================= */

.sidebar {
    position: relative;
    height: 100%; min-height: 0;
    display: flex; flex-direction: column;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.sidebar-header {
    flex-shrink: 0; height: 56px;
    display: flex; align-items: center; gap: 8px;
    padding: 0 10px;
}

.icon-button {
    width: 40px; height: 40px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}
.icon-button:hover { background: var(--bg-hover); color: var(--text-main); }
.icon-button svg.i { width: 24px; height: 24px; }

.search { flex: 1; min-width: 0; }
.search-box { position: relative; }
.search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    display: flex; color: var(--text-secondary); pointer-events: none;
}
.search-icon svg.i { width: 20px; height: 20px; }
.search input {
    width: 100%; height: 42px; padding: 0 14px 0 42px;
    border: 2px solid transparent; border-radius: 22px; outline: none;
    background: var(--bg-input); color: var(--text-main); font-size: 15px;
    transition: border-color var(--transition), background var(--transition);
}
.search input:focus { border-color: var(--accent); background: var(--bg-sidebar); }
.search input::placeholder { color: var(--text-secondary); }

/* меню-бургер */
.menu {
    position: absolute; top: 52px; left: 10px; z-index: 30;
    min-width: 240px; padding: 6px 0;
    background: var(--bg-menu);
    border-radius: 12px;
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.35);
    transform-origin: top left;
    animation: pop 0.14s ease;
}
.menu-item {
    width: 100%; height: 42px;
    display: flex; align-items: center; gap: 18px;
    padding: 0 18px; text-align: left;
    font-size: 15px; font-weight: 500; color: var(--text-main);
    cursor: pointer;
    transition: background var(--transition);
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item svg.i { width: 22px; height: 22px; color: var(--text-secondary); }
.menu-item span { flex: 1; }

.chat-list {
    flex: 1; min-height: 0; overflow-y: auto;
    padding: 2px 8px 90px;
}
.chat-list-empty {
    padding: 28px 14px;
    font-size: 14px; color: var(--text-muted); text-align: center;
}

.chat-item {
    width: 100%; height: 72px;
    display: flex; align-items: center; gap: 12px;
    padding: 0 10px; margin: 0;
    border-radius: 12px; text-align: left;
    transition: background var(--transition);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item:focus-visible { outline-offset: -2px; }

.chat-info { min-width: 0; flex: 1; }
.chat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-name {
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 16px; font-weight: 500;
}
.chat-time { flex-shrink: 0; font-size: 12.5px; color: var(--text-secondary); }
.chat-bottom { margin-top: 3px; }
.chat-preview {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 15px; color: var(--text-secondary);
}
.chat-preview.is-typing { color: var(--accent); }

.chat-item.active .chat-name { color: #fff; }
.chat-item.active .chat-time,
.chat-item.active .chat-preview { color: rgba(255, 255, 255, 0.78); }
.chat-item.active .chat-preview.is-typing { color: #fff; }

/* «печатает…» с бегущими точками */
.is-typing::after {
    content: "..."; display: inline-block; overflow: hidden;
    vertical-align: bottom; width: 0;
    animation: typing-dots 1.2s steps(4) infinite;
}
@keyframes typing-dots { to { width: 0.95em; } }

.fab {
    position: absolute; right: 16px; bottom: 16px;
    width: 56px; height: 56px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-btn); color: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.32);
    transition: background var(--transition), transform var(--transition);
}
.fab:hover { background: var(--accent-btn-hover); }
.fab:active { transform: scale(0.94); }

/* =========================================================
   ЧАТ
   ========================================================= */

.chat {
    position: relative;
    display: flex; flex-direction: column;
    height: 100%; min-width: 0; overflow: hidden;
    background-color: var(--bg-chat);
    background-size: 180px 180px;
}

[data-theme="dark"] .chat {
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180' fill='none' stroke='%23ffffff' stroke-opacity='.045' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='24' cy='26' r='8'/%3E%3Cpath d='M78 18v14M71 25h14'/%3E%3Cpath d='M132 20l4 9 10 1-7.5 6.5 2.5 10-9-5.5-9 5.5 2.5-10L118 30l10-1z'/%3E%3Cpath d='M30 86c6-10 12 10 18 0s12 10 18 0'/%3E%3Cpath d='M104 84a12 12 0 1 0 14 14 9 9 0 0 1-14-14z'/%3E%3Cpath d='M26 142l8 14 8-14z'/%3E%3Ccircle cx='88' cy='148' r='5'/%3E%3Cpath d='M138 146c-8-8-14 2-6 8l6 5 6-5c8-6 2-16-6-8z'/%3E%3C/svg%3E");
}
[data-theme="light"] .chat {
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180' fill='none' stroke='%23305030' stroke-opacity='.10' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='24' cy='26' r='8'/%3E%3Cpath d='M78 18v14M71 25h14'/%3E%3Cpath d='M132 20l4 9 10 1-7.5 6.5 2.5 10-9-5.5-9 5.5 2.5-10L118 30l10-1z'/%3E%3Cpath d='M30 86c6-10 12 10 18 0s12 10 18 0'/%3E%3Cpath d='M104 84a12 12 0 1 0 14 14 9 9 0 0 1-14-14z'/%3E%3Cpath d='M26 142l8 14 8-14z'/%3E%3Ccircle cx='88' cy='148' r='5'/%3E%3Cpath d='M138 146c-8-8-14 2-6 8l6 5 6-5c8-6 2-16-6-8z'/%3E%3C/svg%3E"),
        linear-gradient(160deg, #c9dcb4 0%, #a6cfae 48%, #c4d9a6 100%);
    background-size: 180px 180px, cover;
}

.chat-placeholder {
    display: none; flex: 1; align-items: center; justify-content: center;
    padding: 20px;
}
.chat-placeholder span {
    padding: 6px 16px; border-radius: 16px;
    background: var(--pill-bg); color: #fff;
    font-size: 14px; font-weight: 500;
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.chat.no-chat .chat-placeholder { display: flex; }
.chat.no-chat .chat-header,
.chat.no-chat .messages,
.chat.no-chat .composer { display: none; }

.chat-header {
    flex-shrink: 0; height: 56px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 0 10px 0 8px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    position: relative; z-index: 3;
}
.back-button { display: none; }

.chat-user {
    display: flex; align-items: center; gap: 12px;
    min-width: 0; flex: 1; padding: 4px 8px 4px 6px;
    border-radius: 10px; cursor: pointer;
}
.chat-user-info { display: flex; flex-direction: column; min-width: 0; }
.chat-user-name {
    font-size: 16px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-user-status { font-size: 13.5px; color: var(--text-secondary); margin-top: 1px; }
.chat-user-status.is-typing { color: var(--accent); }
.chat-user .online-dot { width: 12px; height: 12px; border-width: 2px; }

.chat-actions { display: flex; gap: 2px; }

/* сообщения */
.messages {
    flex: 1; min-height: 0; overflow-y: auto;
    padding: 8px max(12px, calc((100% - 780px) / 2)) 10px;
    display: flex; flex-direction: column;
}

.messages-loading,
.messages-error,
.messages-empty {
    margin: auto; padding: 6px 16px; border-radius: 16px;
    background: var(--pill-bg); color: #fff;
    font-size: 14px; font-weight: 500; text-align: center;
}
.messages-error { background: var(--danger); }

.day-group { display: flex; flex-direction: column; }

.date-pill {
    position: sticky; top: 8px; z-index: 2;
    align-self: center; margin: 8px 0 6px;
    padding: 3px 12px; border-radius: 14px;
    background: var(--pill-bg); color: #fff;
    font-size: 13.5px; font-weight: 500;
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

.message {
    --bubble: var(--msg-other);
    position: relative;
    max-width: min(480px, 85%);
    margin-top: 2px;
    padding: 6px 10px 7px;
    border-radius: 14px;
    background: var(--bubble);
    font-size: 15.5px; line-height: 1.35;
    box-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.13);
}
.message.first { margin-top: 8px; }
.message.fresh { animation: msg-in 0.16s ease; }

@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.message-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; }

.meta-spacer { display: inline-block; width: 46px; height: 1px; }
.message.sent .meta-spacer { width: 64px; }

.message-meta {
    position: absolute; right: 9px; bottom: 4px;
    display: flex; align-items: center; gap: 3px;
    font-size: 12px; line-height: 1; color: var(--meta-other);
    user-select: none;
}

.message.received { align-self: flex-start; color: var(--text-main); --bubble: var(--msg-other); }
.message.sent     { align-self: flex-end;   color: var(--text-main); --bubble: var(--msg-own); }
.message.sent .message-meta { color: var(--meta-own); }

.message-check { width: 16px; height: 11px; stroke: var(--check); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* группировка: углы со стороны автора */
.message.received:not(.first) { border-top-left-radius: 5px; }
.message.received:not(.last)  { border-bottom-left-radius: 5px; }
.message.sent:not(.first)     { border-top-right-radius: 5px; }
.message.sent:not(.last)      { border-bottom-right-radius: 5px; }
.message.received.last        { border-bottom-left-radius: 0; }
.message.sent.last            { border-bottom-right-radius: 0; }

/* хвостик */
.message.last::after {
    content: ""; position: absolute; bottom: 0;
    width: 9px; height: 20px;
    background: var(--bubble);
}
.message.sent.last::after {
    right: -8px;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 20'%3E%3Cpath d='M0 0C0 12 2.5 17.5 8.6 20H0Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 20'%3E%3Cpath d='M0 0C0 12 2.5 17.5 8.6 20H0Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}
.message.received.last::after {
    left: -8px;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 20'%3E%3Cpath d='M9 0C9 12 6.5 17.5 0.4 20H9Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 20'%3E%3Cpath d='M9 0C9 12 6.5 17.5 0.4 20H9Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}

/* поле ввода */
.composer {
    flex-shrink: 0;
    display: flex; align-items: flex-end;
    padding: 8px max(12px, calc((100% - 780px) / 2)) 14px;
}

.composer-box {
    flex: 1; min-width: 0;
    display: flex; align-items: flex-end;
    min-height: 50px;
    background: var(--bg-composer);
    border-radius: 25px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.composer-box textarea {
    flex: 1; min-width: 0; resize: none;
    height: 50px; max-height: 160px;
    padding: 14px 20px;
    border: none; outline: none; background: transparent;
    color: var(--text-main); font-size: 16px; line-height: 22px;
}
.composer-box textarea::placeholder { color: var(--text-secondary); }
.composer-box textarea:disabled { opacity: 0.5; }

.send-button {
    width: 0; height: 50px; margin-left: 0; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; opacity: 0; transform: scale(0.6);
    background: var(--accent-btn); color: #fff;
    transition: width 0.18s ease, margin-left 0.18s ease, opacity 0.18s ease, transform 0.18s ease, background var(--transition);
}
.send-button.visible { width: 50px; margin-left: 8px; opacity: 1; transform: none; }
.send-button:hover { background: var(--accent-btn-hover); }
.send-button svg.i { width: 24px; height: 24px; margin-left: 2px; }

/* =========================================================
   ПРАВАЯ ПАНЕЛЬ (профиль)
   ========================================================= */

.profile-panel {
    display: none; flex-direction: column;
    height: 100%; min-width: 0; overflow-y: auto;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
}
.app.profile-open .profile-panel { display: flex; }

.profile-header {
    flex-shrink: 0; height: 56px;
    display: flex; align-items: center; gap: 18px;
    padding: 0 10px 0 18px;
}
.profile-header span { flex: 1; font-size: 18px; font-weight: 500; }

.profile-content {
    display: flex; flex-direction: column; align-items: center;
    padding: 8px 0 0;
}

.profile-avatar {
    width: 110px; height: 110px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; margin-bottom: 14px;
    color: #fff; font-size: 44px; font-weight: 500; user-select: none;
}
.profile-content h2 { font-size: 20px; font-weight: 500; padding: 0 16px; text-align: center; word-break: break-word; }
.profile-content .username { display: none; }
.profile-content .status { font-size: 14px; color: var(--text-secondary); margin: 4px 0 18px; }

.profile-section { width: 100%; padding: 10px 0 8px; border-top: 8px solid var(--bg-gap); }
.section-title { padding: 6px 20px 4px; font-size: 14px; font-weight: 500; color: var(--accent); }
.profile-row {
    display: flex; flex-direction: column-reverse; gap: 2px;
    padding: 9px 20px;
}
.profile-row span { font-size: 13px; color: var(--text-secondary); }
.profile-row strong { font-size: 15.5px; font-weight: 400; word-break: break-word; }

.block-button {
    width: 100%; height: 48px; padding: 0 20px; text-align: left;
    font-size: 15.5px; font-weight: 400; color: var(--danger);
    transition: background var(--transition);
}
.block-button:hover { background: var(--bg-hover); }
.block-button.danger { color: var(--accent); }

/* =========================================================
   МОДАЛКИ
   ========================================================= */

.modal {
    position: fixed; inset: 0; z-index: 90;
    display: flex; align-items: center; justify-content: center;
    padding: 20px; background: var(--overlay);
}

.modal-card {
    width: 100%; max-width: 420px; max-height: 88vh;
    display: flex; flex-direction: column;
    background: var(--bg-sidebar);
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    animation: pop 0.16s ease;
}

.modal-header {
    flex-shrink: 0; height: 56px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 10px 0 22px;
}
.modal-header span { font-size: 19px; font-weight: 500; }

.modal-body {
    flex: 1; min-height: 0;
    display: flex; flex-direction: column; gap: 10px;
    padding: 4px 12px 14px; overflow-y: auto;
}

.modal-body > input {
    height: 44px; padding: 0 16px;
    border: 2px solid transparent; border-radius: 22px; outline: none;
    background: var(--bg-input); color: var(--text-main); font-size: 15px;
}
.modal-body > input:focus { border-color: var(--accent); background: var(--bg-sidebar); }
.modal-body > input::placeholder { color: var(--text-secondary); }

.contact-list { display: flex; flex-direction: column; min-height: 120px; }

.contact-item {
    display: flex; align-items: center; gap: 12px;
    height: 64px; padding: 0 10px; border-radius: 12px; text-align: left;
    transition: background var(--transition);
}
.contact-item:hover { background: var(--bg-hover); }
.contact-item .avatar { width: 46px; height: 46px; font-size: 18px; }
.contact-item .online-dot { width: 12px; height: 12px; border-width: 2px; }
.contact-info { min-width: 0; flex: 1; }
.contact-name {
    font-size: 16px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-username { display: none; }
.contact-status { margin-top: 2px; font-size: 14px; color: var(--text-secondary); }
.contact-status.is-online { color: var(--accent); }
.contact-empty { padding: 28px; font-size: 14px; color: var(--text-muted); text-align: center; }

/* =========================================================
   НАСТРОЙКИ
   ========================================================= */

#settingsModal .modal-card { max-width: 440px; }
.settings-body { gap: 0; padding: 0 0 6px; }

.settings-profile {
    display: flex; align-items: center; gap: 16px;
    padding: 6px 22px 18px;
}
.settings-account { min-width: 0; }
.settings-account-name { font-size: 20px; font-weight: 500; word-break: break-word; }
.settings-account-username { font-size: 15px; color: var(--text-secondary); margin-top: 3px; }

.settings-group {
    display: flex; flex-direction: column;
    padding: 10px 0 6px; border-top: 8px solid var(--bg-gap);
}
.settings-label { padding: 6px 22px 6px; font-size: 14.5px; font-weight: 500; color: var(--accent); }
.settings-options { display: flex; flex-direction: column; }

.option-button {
    width: 100%; height: 46px; padding: 0 22px;
    display: flex; align-items: center; gap: 20px;
    text-align: left; font-size: 15.5px; color: var(--text-main);
    transition: background var(--transition);
}
.option-button:hover { background: var(--bg-hover); }
.option-button::before {
    content: ""; width: 20px; height: 20px; flex-shrink: 0;
    border-radius: 50%; border: 2px solid var(--text-secondary);
    transition: border-color var(--transition);
}
.option-button.active::before {
    border-color: var(--accent);
    background: radial-gradient(circle, var(--accent) 0 4.5px, transparent 5.5px);
}

.settings-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    height: 50px; padding: 0 22px; cursor: pointer; user-select: none;
    transition: background var(--transition);
}
.settings-toggle:hover { background: var(--bg-hover); }
.settings-toggle span { font-size: 15.5px; }
.settings-hint { padding: 2px 22px 8px; font-size: 13px; line-height: 1.4; color: var(--text-secondary); }

input.switch,
.settings-toggle input[type="checkbox"] {
    appearance: none; -webkit-appearance: none;
    position: relative; flex-shrink: 0; order: 2;
    width: 38px; height: 22px; border-radius: 11px;
    background: var(--switch-off); cursor: pointer;
    transition: background 0.2s ease;
}
input.switch::after,
.settings-toggle input[type="checkbox"]::after {
    content: ""; position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}
input.switch:checked,
.settings-toggle input[type="checkbox"]:checked { background: var(--accent-btn); }
input.switch:checked::after,
.settings-toggle input[type="checkbox"]:checked::after { transform: translateX(16px); }

.settings-logout {
    width: 100%; height: 52px; padding: 0 22px; margin-top: 2px;
    text-align: left; font-size: 15.5px; color: var(--danger);
    border-top: 8px solid var(--bg-gap);
    transition: background var(--transition);
}
.settings-logout:hover { background: var(--bg-hover); }

/* =========================================================
   УВЕДОМЛЕНИЕ
   ========================================================= */

.legagram-notification {
    position: fixed; left: 50%; bottom: 32px;
    transform: translate(-50%, 20px);
    padding: 10px 18px; border-radius: 20px;
    background: rgba(20, 28, 38, 0.92); color: #fff;
    font-size: 14px; z-index: 9999;
    opacity: 0; pointer-events: none;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* =========================================================
   АДАПТИВ
   ========================================================= */

@media (max-width: 1100px) {
    .app, .app.profile-open { grid-template-columns: 320px minmax(0, 1fr); }
    .app.profile-open .profile-panel {
        position: fixed; top: 0; right: 0; bottom: 0;
        width: 340px; max-width: 100%; z-index: 50;
        box-shadow: -16px 0 40px rgba(0, 0, 0, 0.4);
    }
}

@media (max-width: 760px) {
    .app, .app.profile-open { grid-template-columns: minmax(0, 1fr); }
    .chat { display: none; }
    .app.chat-open .chat { display: flex; }
    .app.chat-open .sidebar { display: none; }
    .back-button { display: flex; }
    .app.profile-open .profile-panel { width: 100%; }
    .message { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}


/* =========================================================
   ГАЛОЧКА, БОТ, ОШИБКИ ВХОДА
   ========================================================= */

.name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-name, .chat-user-name, .contact-name {
    display: flex; align-items: center; gap: 4px;
}
.profile-content h2 {
    display: flex; align-items: center; justify-content: center; gap: 6px;
}

svg.verified { width: 17px; height: 17px; flex-shrink: 0; }
.profile-content h2 svg.verified { width: 20px; height: 20px; }
.verified .v-bg { fill: var(--accent); }
.verified .v-check {
    fill: none; stroke: #fff; stroke-width: 2.2;
    stroke-linecap: round; stroke-linejoin: round;
}
.chat-item.active .verified .v-bg { fill: #fff; }
.chat-item.active .verified .v-check { stroke: var(--bg-active); }

.chat.is-bot .composer { display: none; }

.auth-error { white-space: pre-line; }
.auth-error:not(:empty) {
    padding: 10px 14px; border-radius: 12px;
    background: rgba(236, 57, 66, 0.12);
}
