/* chat.4inc.ru — тёмная тема, один файл на весь сайт */

:root {
    --bg: #12141a;
    --bg-soft: #181b23;
    --bg-raised: #1f232d;
    --line: #272c38;
    --text: #e9ecf3;
    --text-dim: #98a0b3;
    --accent: #4a86e8;
    --accent-soft: rgba(74, 134, 232, .16);
    --own: #2f5ea8;
    --danger: #e05d78;
    --radius: 16px;
    --shadow: 0 12px 32px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
    font: inherit;
    color: inherit;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── кнопки и поля ───────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--bg-raised);
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, transform .05s;
}

.btn:hover {
    background: #262b36;
}

.btn:active {
    transform: translateY(1px);
}

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

.btn--primary:hover {
    background: #5b93ec;
}

.btn--ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--text-dim);
}

.btn--ghost:hover {
    color: var(--text);
    background: var(--bg-raised);
}

.btn--wide {
    width: 100%;
}

.btn--small {
    padding: 7px 12px;
    font-size: 13px;
    border-radius: 10px;
}

.field {
    display: block;
}

.field--grow {
    flex: 1;
}

.field__label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-dim);
}

.field__input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
    outline: none;
    transition: border-color .15s, background .15s;
}

.field__input:focus {
    border-color: var(--accent);
    background: #161a22;
}

.field__input::placeholder {
    color: #626b7e;
}

.form {
    display: grid;
    gap: 14px;
}

.form--row {
    grid-auto-flow: column;
    grid-template-columns: 1fr auto;
    align-items: end;
}

.alert {
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(224, 93, 120, .12);
    border: 1px solid rgba(224, 93, 120, .35);
    color: #ffb3c2;
    font-size: 14px;
}

/* ── первый экран ────────────────────────────────────────────────────────── */

.start {
    max-width: 520px;
    margin: 0 auto;
    padding: 48px 20px 64px;
    display: grid;
    gap: 28px;
}

.start__card {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--bg-soft);
    box-shadow: var(--shadow);
}

.start__logo {
    font-size: 40px;
    line-height: 1;
}

.start__title {
    margin: 14px 0 8px;
    font-size: 26px;
    letter-spacing: -.02em;
}

.start__lead {
    margin: 0 0 22px;
    color: var(--text-dim);
}

.start__divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 22px 0;
    color: var(--text-dim);
    font-size: 13px;
}

.start__divider::before,
.start__divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

.start__hint {
    margin: 18px 0 0;
    font-size: 13px;
    color: var(--text-dim);
}

.start__subtitle {
    margin: 0 0 12px;
    font-size: 15px;
    color: var(--text-dim);
    font-weight: 500;
}

.rooms {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.rooms__link {
    display: grid;
    gap: 3px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg-soft);
    color: inherit;
    text-decoration: none;
    transition: border-color .15s, background .15s;
}

.rooms__link:hover {
    border-color: var(--accent);
    background: var(--bg-raised);
}

.rooms__title {
    font-weight: 500;
}

.rooms__meta {
    font-size: 12px;
    color: var(--text-dim);
}

/* ── каркас чата ─────────────────────────────────────────────────────────── */

.chat {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    height: 100dvh;
    max-width: 860px;
    margin: 0 auto;
    background: var(--bg-soft);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
}

.chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}

.chat__back {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 18px;
}

.chat__back:hover {
    background: var(--bg-raised);
    color: var(--text);
}

.chat__about {
    flex: 1;
    min-width: 0;
}

.chat__title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat__status {
    font-size: 12px;
    color: var(--text-dim);
}

.chat__status[data-state='online'] {
    color: #5cc98b;
}

.chat__status[data-state='offline'] {
    color: var(--danger);
}

.chat__members {
    display: flex;
    flex-direction: row-reverse;
}

.member {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-left: -8px;
    border-radius: 50%;
    border: 2px solid var(--bg);
    font-size: 12px;
    font-weight: 600;
    color: #fff;
}

.member--rest {
    background: var(--bg-raised);
    color: var(--text-dim);
}

.chat__body {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat__empty {
    margin: auto;
    color: var(--text-dim);
    font-size: 14px;
}

.chat__typing {
    min-height: 18px;
    padding: 0 18px;
    font-size: 12px;
    color: var(--text-dim);
}

.chat__footer {
    position: relative;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--bg);
}

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

.msg {
    position: relative;
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    margin-top: 10px;
    max-width: 100%;
}

.msg--stacked {
    margin-top: 2px;
}

/* своё сообщение зеркалится порядком колонок: кнопка реакции слева, аватар справа */
.msg--own {
    grid-template-columns: auto minmax(0, 1fr) 32px;
}

.msg--own .msg__react {
    order: 1;
}

.msg--own .msg__bubble {
    order: 2;
}

.msg--own .msg__avatar {
    order: 3;
}

.msg__avatar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
}

.msg--stacked .msg__avatar,
.msg--own .msg__avatar {
    visibility: hidden;
}

.msg__bubble {
    justify-self: start;
    max-width: min(560px, 78%);
    padding: 8px 12px 6px;
    border-radius: 16px 16px 16px 6px;
    background: var(--bg-raised);
    word-wrap: break-word;
}

.msg--own .msg__bubble {
    justify-self: end;
    border-radius: 16px 16px 6px 16px;
    background: var(--own);
}

.msg--stacked .msg__bubble {
    border-bottom-left-radius: 16px;
}

.msg--own.msg--stacked .msg__bubble {
    border-bottom-right-radius: 16px;
}

.msg__name {
    margin-bottom: 2px;
    font-size: 13px;
    font-weight: 600;
}

.msg--stacked .msg__name {
    display: none;
}

.msg__text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg__time {
    margin-top: 2px;
    font-size: 11px;
    color: rgba(233, 236, 243, .45);
    text-align: right;
}

/* сообщение из одного эмодзи: без подложки и крупно, как в телеграме */
.msg__bubble--emoji {
    background: transparent !important;
    padding: 0 4px;
}

.msg__text--emoji {
    font-size: 58px;
    line-height: 1.15;
}

.msg__bubble--emoji .msg__time {
    color: var(--text-dim);
}

.msg--system {
    grid-template-columns: 1fr;
    justify-items: center;
    margin: 14px 0;
}

.msg__system-text {
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .05);
    font-size: 12px;
    color: var(--text-dim);
}

.msg__react {
    align-self: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--bg-raised);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
}

.msg:hover .msg__react {
    opacity: .8;
}

.msg__react:hover {
    opacity: 1 !important;
}

@media (hover: none) {
    .msg__react {
        opacity: .55;
    }
}

/* ── реакции ─────────────────────────────────────────────────────────────── */

.msg__reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.msg__reactions:not(:empty) {
    margin-top: 6px;
}

.reaction {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.reaction:hover {
    background: rgba(255, 255, 255, .14);
}

.reaction.is-mine {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.reaction__count {
    font-size: 12px;
    color: var(--text-dim);
}

.reaction.is-mine .reaction__count {
    color: #a9c8ff;
}

.reactbar {
    position: fixed;
    z-index: 30;
    display: flex;
    gap: 2px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-raised);
    box-shadow: var(--shadow);
}

/* у панели свой display, поэтому атрибут hidden гасим явно */
.reactbar[hidden] {
    display: none;
}

.reactbar__item {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, transform .1s;
}

.reactbar__item:hover {
    background: rgba(255, 255, 255, .1);
    transform: scale(1.15);
}

/* ── поле ввода и пикер ──────────────────────────────────────────────────── */

.composer {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: end;
    gap: 8px;
}

.composer__emoji,
.composer__send {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    background: var(--bg-raised);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s;
}

.composer__emoji:hover {
    background: #2b313d;
}

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

.composer__send:hover {
    background: #5b93ec;
}

.composer__input {
    width: 100%;
    max-height: 160px;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg-soft);
    resize: none;
    outline: none;
    overflow-y: auto;
}

.composer__input:focus {
    border-color: var(--accent);
}

.picker {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(100% - 4px);
    max-width: 420px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--bg-raised);
    box-shadow: var(--shadow);
    z-index: 20;
}

.picker__tabs {
    display: flex;
    gap: 4px;
    padding-bottom: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.picker__tab {
    width: 34px;
    height: 30px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-size: 16px;
    cursor: pointer;
    opacity: .55;
}

.picker__tab.is-active {
    background: var(--accent-soft);
    opacity: 1;
}

.picker__grid {
    display: none;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    max-height: 210px;
    overflow-y: auto;
}

.picker__grid.is-active {
    display: grid;
}

.picker__emoji {
    aspect-ratio: 1;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.picker__emoji:hover {
    background: rgba(255, 255, 255, .08);
}

/* ── модалка имени и тост ────────────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(10, 12, 16, .72);
    backdrop-filter: blur(3px);
}

.modal[hidden] {
    display: none;
}

.modal__window {
    width: 100%;
    max-width: 360px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--bg-soft);
    box-shadow: var(--shadow);
}

.modal__title {
    margin: 0 0 8px;
    font-size: 20px;
}

.modal__text {
    margin: 0 0 18px;
    font-size: 14px;
    color: var(--text-dim);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 88px;
    transform: translateX(-50%);
    z-index: 60;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(31, 35, 45, .96);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 14px;
}

.toast[hidden] {
    display: none;
}

/* ── 404 ─────────────────────────────────────────────────────────────────── */

.page404 {
    display: grid;
    place-items: center;
    gap: 12px;
    height: 100dvh;
    text-align: center;
}

.page404__code {
    font-size: 64px;
    font-weight: 700;
    letter-spacing: -.04em;
}

.page404__text {
    margin: 0;
    color: var(--text-dim);
}

@media (max-width: 560px) {
    .msg__bubble {
        max-width: 84%;
    }

    .msg__text--emoji {
        font-size: 48px;
    }

    .picker__grid {
        grid-template-columns: repeat(8, 1fr);
    }

    .start {
        padding-top: 28px;
    }
}
