/* ─────────────────────────────────────────────────────────────────────────────
   Q-Ку — веб-клиент. Палитра совпадает с Android-приложением.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
    --deep:     #0A0E1A;
    --navy:     #12182B;
    --surface:  #1E2746;
    --purple:   #6B46FF;
    --cyan:     #00D4FF;
    --pink:     #FF00E5;

    --text:     #F0F0F0;
    --dim:      #8B9BB4;
    --border:   rgba(255, 255, 255, 0.08);
    --danger:   #FF5C77;

    --radius:   14px;
    --radius-sm: 9px;

    --sidebar-w: 340px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--deep);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 4px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.screen { height: 100dvh; }
[hidden] { display: none !important; }

/* ── Кнопки ──────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem; font-weight: 600;
    transition: transform 0.12s var(--ease), background 0.2s var(--ease), opacity 0.2s var(--ease);
    border: 1px solid transparent;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary { background: linear-gradient(135deg, var(--purple), #8B5CFF); color: #fff; }
.btn--ghost { background: rgba(255, 255, 255, 0.06); border-color: var(--border); }
.btn--ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.11); }
.btn--text { background: none; color: var(--dim); font-weight: 500; }
.btn--text:hover { color: var(--text); }
.btn--danger { background: rgba(255, 92, 119, 0.13); border-color: rgba(255, 92, 119, 0.35); color: var(--danger); }
.btn--block { width: 100%; }
.btn--sm { padding: 7px 14px; font-size: 0.85rem; }

.icon-btn {
    display: grid; place-items: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    color: var(--dim);
    flex-shrink: 0;
    transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

.icon-btn--send { background: linear-gradient(135deg, var(--purple), #8B5CFF); color: #fff; }
.icon-btn--send:hover { color: #fff; filter: brightness(1.12); }
.icon-btn--send svg { fill: currentColor; stroke: none; }

/* ── Поля ────────────────────────────────────────────────────────────────── */

.field { display: block; margin-bottom: 18px; }
.field__label { display: block; font-size: 0.82rem; color: var(--dim); margin-bottom: 7px; }

.field input, .field textarea, .sidebar__search input {
    width: 100%;
    padding: 13px 15px;
    background: var(--navy);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.18s var(--ease);
    resize: none;
}
.field input:focus, .field textarea:focus { border-color: var(--purple); outline: none; }
.field textarea { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9rem; }

.checkbox { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 0.9rem; color: var(--dim); cursor: pointer; }
.checkbox input { width: 17px; height: 17px; accent-color: var(--purple); cursor: pointer; }

/* ── Экран входа ─────────────────────────────────────────────────────────── */

.screen--auth { display: grid; place-items: center; padding: 24px; overflow-y: auto; }

.auth { width: 100%; max-width: 400px; }

.auth__logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 38px; }

.logo-mark {
    display: grid; place-items: center;
    width: 46px; height: 46px;
    background: linear-gradient(135deg, var(--purple), var(--cyan));
    border-radius: 13px;
    font-weight: 800; font-size: 1.5rem;
    box-shadow: 0 6px 26px rgba(107, 70, 255, 0.42);
}
.logo-text { font-size: 1.6rem; font-weight: 700; }

.auth h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 10px; }
.auth__hint { color: var(--dim); font-size: 0.94rem; margin-bottom: 26px; }
.auth__note { color: var(--dim); font-size: 0.85rem; margin-top: 20px; text-align: center; }

.auth__error {
    margin-top: 18px; padding: 13px 15px;
    background: rgba(255, 92, 119, 0.1);
    border: 1px solid rgba(255, 92, 119, 0.3);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 0.9rem;
}

.auth__warning {
    margin-top: 34px; padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--dim); font-size: 0.8rem; text-align: center;
}

.recovery {
    background: var(--navy);
    border: 1px solid rgba(107, 70, 255, 0.4);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 20px;
    text-align: center;
}
.recovery code {
    display: block;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.83rem;
    line-height: 1.75;
    word-break: break-all;
    color: #C4B5FF;
    margin-bottom: 14px;
    user-select: all;
}

/* ── Раскладка приложения ────────────────────────────────────────────────── */

.screen--app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; }

/* ── Боковая панель ──────────────────────────────────────────────────────── */

.sidebar {
    display: flex; flex-direction: column;
    background: var(--navy);
    border-right: 1px solid var(--border);
    min-height: 0;
}

.sidebar__head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar__me { flex: 1; min-width: 0; }
.sidebar__name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__status { font-size: 0.78rem; color: var(--dim); }
.sidebar__status.is-online { color: var(--cyan); }
.sidebar__status.is-offline { color: var(--danger); }

.sidebar__search { padding: 12px 16px; }
.sidebar__search input { padding: 10px 14px; font-size: 0.9rem; }

.tabs { display: flex; padding: 0 16px; gap: 6px; border-bottom: 1px solid var(--border); }

.tab {
    padding: 10px 14px;
    font-size: 0.88rem; font-weight: 600; color: var(--dim);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.tab:hover { color: var(--text); }
.tab--active { color: var(--text); border-bottom-color: var(--purple); }

.list { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }

.list__empty { padding: 40px 20px; text-align: center; color: var(--dim); font-size: 0.88rem; }

/* ── Строка чата ─────────────────────────────────────────────────────────── */

.row {
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background 0.15s var(--ease);
}
.row:hover { background: rgba(255, 255, 255, 0.05); }
.row--active { background: rgba(107, 70, 255, 0.18); }
.row--active:hover { background: rgba(107, 70, 255, 0.24); }

.row__body { flex: 1; min-width: 0; }
.row__top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row__name { font-weight: 600; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__time { font-size: 0.72rem; color: var(--dim); flex-shrink: 0; }
.row__preview {
    font-size: 0.84rem; color: var(--dim);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: flex; align-items: center; gap: 5px;
}

.badge {
    min-width: 20px; height: 20px;
    padding: 0 6px;
    background: var(--purple);
    border-radius: 10px;
    font-size: 0.72rem; font-weight: 700;
    display: grid; place-items: center;
    flex-shrink: 0;
}

/* ── Аватары ─────────────────────────────────────────────────────────────── */

.avatar {
    position: relative;
    display: grid; place-items: center;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--purple), var(--cyan));
    font-weight: 700; font-size: 1rem;
    flex-shrink: 0;
    overflow: hidden;
    color: #fff;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 34px; height: 34px; font-size: 0.85rem; }
.avatar--btn { cursor: pointer; }

.avatar[data-online="true"]::after {
    content: "";
    position: absolute; right: 1px; bottom: 1px;
    width: 11px; height: 11px;
    background: var(--cyan);
    border: 2px solid var(--navy);
    border-radius: 50%;
}

/* ── Область чата ────────────────────────────────────────────────────────── */

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--deep); }

.chat__empty { flex: 1; display: grid; place-content: center; justify-items: center; gap: 18px; color: var(--dim); }
.chat__empty-mark {
    display: grid; place-items: center;
    width: 76px; height: 76px;
    background: var(--navy);
    border: 1px solid var(--border);
    border-radius: 22px;
    font-size: 2.1rem; font-weight: 800;
    color: var(--purple);
}

.chat__inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat__head {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: var(--navy);
    border-bottom: 1px solid var(--border);
}
.chat__back { display: none; }
.chat__title { flex: 1; min-width: 0; }
.chat__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__sub { font-size: 0.78rem; color: var(--dim); }
.chat__sub.is-typing { color: var(--cyan); }

/* ── Сообщения ───────────────────────────────────────────────────────────── */

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex; flex-direction: column; gap: 3px;
    scroll-behavior: smooth;
}

.day {
    align-self: center;
    margin: 16px 0 10px;
    padding: 4px 13px;
    background: var(--surface);
    border-radius: 100px;
    font-size: 0.74rem;
    color: var(--dim);
}

.msg {
    max-width: min(72%, 560px);
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
    animation: msg-in 0.22s var(--ease);
}

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

.msg--in {
    align-self: flex-start;
    background: var(--surface);
    border-bottom-left-radius: 5px;
}
.msg--out {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--purple), #7C5CFF);
    border-bottom-right-radius: 5px;
}

.msg + .msg--in  { margin-top: 0; }
.msg--in  + .msg--out,
.msg--out + .msg--in { margin-top: 10px; }

.msg__author { font-size: 0.78rem; font-weight: 600; color: var(--cyan); margin-bottom: 3px; }

.msg__quote {
    border-left: 3px solid rgba(255, 255, 255, 0.4);
    padding-left: 9px;
    margin-bottom: 6px;
    font-size: 0.84rem;
    opacity: 0.8;
}

.msg__media { max-width: 100%; border-radius: 10px; margin-bottom: 6px; display: block; }

.msg__meta {
    display: flex; align-items: center; justify-content: flex-end; gap: 5px;
    font-size: 0.68rem;
    opacity: 0.72;
    margin-top: 3px;
}

.msg__tick { letter-spacing: -2px; }
.msg--read .msg__tick { color: var(--cyan); opacity: 1; }
.msg--failed .msg__meta { color: #FFD4DA; }

.msg--service {
    align-self: center;
    background: none;
    color: var(--dim);
    font-size: 0.8rem;
    max-width: 80%;
    text-align: center;
}

/* ── Поле ввода ──────────────────────────────────────────────────────────── */

.composer {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 12px 16px;
    background: var(--navy);
    border-top: 1px solid var(--border);
}

.composer textarea {
    flex: 1;
    max-height: 140px;
    padding: 11px 15px;
    background: var(--surface);
    border: 1px solid transparent;
    border-radius: 20px;
    resize: none;
    overflow-y: auto;
}
.composer textarea:focus { outline: none; border-color: var(--purple); }

/* ── Модальные окна ──────────────────────────────────────────────────────── */

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }

.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(3px); }

.modal__box {
    position: relative;
    width: 100%; max-width: 430px;
    max-height: 86dvh;
    background: var(--navy);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex; flex-direction: column;
    animation: modal-in 0.2s var(--ease);
}

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

.modal__head {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.modal__head h2 { font-size: 1.05rem; font-weight: 650; }

.modal__body { padding: 20px; overflow-y: auto; }
.modal__body p { color: var(--dim); font-size: 0.9rem; margin-bottom: 14px; }
.modal__body .btn + .btn { margin-top: 9px; }

.member {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 4px;
}
.member__name { flex: 1; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member__role { font-size: 0.76rem; color: var(--dim); }

.picker { max-height: 260px; overflow-y: auto; margin-bottom: 18px; }
.picker label { display: flex; align-items: center; gap: 11px; padding: 9px 4px; cursor: pointer; }
.picker input { width: 17px; height: 17px; accent-color: var(--purple); }

/* ── Уведомления ─────────────────────────────────────────────────────────── */

.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 9px; align-items: center; }

.toast {
    padding: 11px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.88rem;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    animation: toast-in 0.25s var(--ease);
    max-width: 90vw;
}
.toast--error { background: rgba(255, 92, 119, 0.16); border-color: rgba(255, 92, 119, 0.4); color: #FFC2CC; }
.toast--ok { border-color: rgba(0, 212, 255, 0.4); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}

/* ── Мобильная раскладка ─────────────────────────────────────────────────── */

@media (max-width: 780px) {
    .screen--app { grid-template-columns: 1fr; }

    .sidebar { grid-area: 1 / 1; }
    .chat { grid-area: 1 / 1; }

    .screen--app:not(.is-chat-open) .chat { display: none; }
    .screen--app.is-chat-open .sidebar { display: none; }

    .chat__back { display: grid; }

    .msg { max-width: 84%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
    .messages { scroll-behavior: auto; }
}
