/* ==========================================================================
   The chat with the organiser (Views/Chat) and the two tabs of the inbox (also on Notification/All).
   The calm look chosen on 26.11.2026 (variant В): soft white cards, the other side's messages cream, one's own mint,
   no pitch. chat.js fits the chat to the window; without it the heights below are used.
   ========================================================================== */

.chat-page { max-width: 1180px; margin: 0 auto; }
.chat-page--person,
.chat-page--notes { max-width: 900px; }

/* ---------- 1. The tabs: the chat | notifications ---------- */
.chat-tabs {
    display: inline-flex;
    gap: .35rem;
    max-width: 100%;
    margin: 0 0 1.25rem;
    padding: .35rem;
    border: var(--tg-bw) solid var(--tg-ink);
    border-radius: var(--tg-pill);
    background: var(--tg-surface);
    box-shadow: var(--tg-pop);
}
.chat-tab {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .55rem 1.1rem;
    border-radius: var(--tg-pill);
    color: var(--tg-ink);
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .15s;
}
.chat-tab:hover { color: var(--tg-ink); background: var(--tg-paper); }
.chat-tab.is-active,
.chat-tab.is-active:hover { background: var(--tg-ink); color: #fff; }
.chat-tab__n,
.chat-person__n {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 20px;
    padding: 0 .4rem;
    border-radius: var(--tg-pill);
    background: var(--tg-coral);
    color: #fff;
    font-size: .7rem;
    font-weight: 900;
}

/* ---------- 2. The chat: a heading, the messages (they scroll), the writing box ---------- */
.chat-box {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-radius: var(--tg-r-lg);
    background: var(--tg-surface);
    box-shadow: var(--tg-soft);
    overflow: hidden;
}
.chat-page--person .chat-box { height: min(78vh, 780px); }

.chat-box__bar {
    position: relative;
    z-index: 1;
    flex: none;
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem 1.25rem;
    background: var(--tg-surface);
    box-shadow: 0 10px 18px -16px rgba(13, 31, 23, .5);
}
.chat-box__crest { position: relative; flex: none; display: inline-flex; font-size: 1.7rem; line-height: 1; color: var(--tg-pitch); }
.chat-box__crest::after { content: ""; position: absolute; right: -3px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--tg-grass); border: 2px solid #fff; }
.chat-box__heading { flex: 1; min-width: 0; }
.chat-box__label { display: block; font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--tg-muted); }
.chat-box__title {
    margin: .1rem 0 0;
    font-family: var(--tg-display);
    font-weight: 800;
    font-size: clamp(1.1rem, 2.6vw, 1.6rem);
    line-height: 1.05;
    letter-spacing: -.035em;
    text-transform: uppercase;
    overflow-wrap: anywhere;
}
.chat-box__sub { display: block; margin: .25rem 0 0; font-size: .82rem; font-weight: 600; color: var(--tg-ink-2); overflow-wrap: anywhere; }
a.chat-box__mail { color: var(--tg-ink-2); text-decoration: none; }
a.chat-box__mail:hover { color: var(--tg-ink); text-decoration: underline; }
.chat-box__back {
    display: none;
    place-items: center;
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: var(--tg-bw) solid var(--tg-ink);
    background: var(--tg-paper);
    color: var(--tg-ink);
    font-size: 1.05rem;
}
.chat-box__back:hover { color: var(--tg-ink); background: var(--tg-sun); }

.chat-scroll-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: clamp(1rem, 3vw, 1.75rem) clamp(.75rem, 3vw, 1.75rem);
    scrollbar-width: thin;
    scrollbar-color: #cfc8b8 transparent;
}
.chat-scroll:focus-visible { outline: 2px solid var(--tg-pitch); outline-offset: -2px; }
.chat-thread { display: flex; flex-direction: column; gap: .9rem; min-height: 100%; }

.chat-day { display: flex; justify-content: center; }
.chat-day > span { padding: .2rem .8rem; border-radius: var(--tg-pill); background: var(--tg-paper); color: var(--tg-ink-2); font-size: .72rem; font-weight: 800; }

.chat-start { align-self: center; display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .25rem 0 .4rem; color: var(--tg-muted); font-size: .78rem; font-weight: 700; text-align: center; }
.chat-start .bi { font-size: 1.35rem; color: var(--tg-pitch); }

.chat-more { display: flex; justify-content: center; }
.chat-more__btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem .9rem;
    border: 1px solid var(--tg-line-2);
    border-radius: var(--tg-pill);
    background: #fff;
    color: var(--tg-ink-2);
    font-size: .78rem;
    font-weight: 800;
}
.chat-more__btn:hover { border-color: var(--tg-ink); color: var(--tg-ink); }
.chat-more.is-loading .chat-more__btn { opacity: .55; pointer-events: none; }

.chat-empty { align-self: center; max-width: 440px; margin: auto; padding: 1.4rem 1.5rem; border-radius: var(--tg-r); background: var(--tg-paper); text-align: center; line-height: 1.55; }
.chat-empty__title { display: block; margin-bottom: .35rem; font-size: 1.05rem; }
.chat-empty__text { margin: 0; color: var(--tg-ink-2); }

/* One message: the other side on the left, one's own on the right */
.chat-turn { display: flex; align-items: flex-end; gap: .6rem; max-width: min(80%, 600px); }
.chat-turn--theirs { align-self: flex-start; }
.chat-turn--mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-turn__ava {
    display: grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: var(--tg-bw) solid var(--tg-ink);
    background: #fff;
    color: var(--tg-ink);
    font-size: .9rem;
}
.chat-turn--mine .chat-turn__ava { background: var(--tg-ink); color: var(--tg-sun); }
.chat-bubble { min-width: 0; padding: .7rem 1rem .5rem; border-radius: 20px 20px 20px 6px; background: var(--tg-paper); color: var(--tg-ink); }
.chat-turn--mine .chat-bubble { border-radius: 20px 20px 6px 20px; background: var(--tg-mint); }
.chat-turn.is-new .chat-bubble { animation: chat-in .45s var(--tg-spring) both; }
.chat-bubble__label { display: flex; align-items: center; gap: .35rem; margin-bottom: .2rem; font-size: .72rem; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; color: var(--tg-ink-2); overflow-wrap: anywhere; }
.chat-bubble--report .chat-bubble__label .bi { color: var(--tg-coral); }
.chat-bubble__text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; line-height: 1.55; font-size: .98rem; }
.chat-bubble__text--gone { font-style: italic; color: var(--tg-muted); }
.chat-bubble__time { display: block; margin-top: .2rem; font-size: .7rem; font-weight: 700; color: var(--tg-ink-2); opacity: .75; }
.chat-turn--mine .chat-bubble__time { text-align: right; }

@keyframes chat-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

/* Scrolled up into the history: back to the newest message */
.chat-down {
    position: absolute;
    left: 50%;
    bottom: 14px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem .95rem;
    border: 0;
    border-radius: var(--tg-pill);
    background: var(--tg-ink);
    color: #fff;
    font-size: .78rem;
    font-weight: 800;
    box-shadow: var(--tg-soft);
    transform: translateX(-50%);
}

/* The writing box */
.chat-write { position: relative; flex: none; margin: 0; padding: .75rem .85rem .8rem; border-top: 1px solid var(--tg-line); background: var(--tg-surface); }
.chat-write__row { display: flex; align-items: flex-end; gap: .7rem; }
textarea.form-control.chat-write__input { flex: 1; min-width: 0; min-height: 50px; max-height: 180px; padding: .75rem 1rem; border-radius: 22px; line-height: 1.45; resize: none; }
.chat-write__send {
    display: grid;
    place-items: center;
    flex: none;
    width: 50px;
    height: 50px;
    border: 0;
    border-radius: 50%;
    background: var(--tg-pitch);
    color: #fff;
    font-size: 1.1rem;
    transition: transform .25s var(--tg-spring), opacity .15s;
}
.chat-write__send:hover { transform: translateY(-2px) rotate(-10deg); }
.chat-write.is-sending .chat-write__send { opacity: .55; pointer-events: none; }
.chat-write__error { margin: 0 0 .55rem; padding: .45rem .8rem; border-radius: var(--tg-r-sm); background: #ffe7e0; color: var(--tg-ink); font-size: .85rem; font-weight: 700; }
.chat-write__count { display: block; margin: .2rem 4rem 0 0; text-align: right; font-size: .7rem; font-weight: 700; color: var(--tg-muted); }
.chat-write__count:empty { display: none; }
.chat-write__count.is-over { color: var(--tg-red); }

/* ---------- 3. The organiser: the people on the left, the chat on the right ---------- */
.chat-two {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 1.25rem;
    height: min(78vh, 780px);
}
.chat-people { display: flex; flex-direction: column; min-height: 0; border-radius: var(--tg-r-lg); background: var(--tg-surface); box-shadow: var(--tg-soft); overflow: hidden; }
.chat-find { flex: none; display: flex; flex-direction: column; gap: .6rem; padding: 1rem; border-bottom: 1px solid var(--tg-line); }
.chat-find__input.form-control { border-radius: var(--tg-pill); }
.chat-filter { display: flex; flex-wrap: wrap; gap: .4rem; }
.chat-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .75rem;
    border: 1px solid var(--tg-line-2);
    border-radius: var(--tg-pill);
    background: #fff;
    color: var(--tg-ink);
    font-size: .78rem;
    font-weight: 800;
    text-decoration: none;
}
.chat-chip:hover { color: var(--tg-ink); border-color: var(--tg-ink); }
.chat-chip.is-on,
.chat-chip.is-on:hover { background: var(--tg-ink); border-color: var(--tg-ink); color: #fff; }
.chat-chip__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tg-coral); }

.chat-people__list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #cfc8b8 transparent; }
.chat-person {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    column-gap: .75rem;
    row-gap: .1rem;
    align-items: center;
    padding: .8rem 1rem;
    border-top: 1px solid var(--tg-line);
    color: var(--tg-ink);
    text-decoration: none;
    transition: background-color .15s;
}
.chat-person:first-child { border-top: 0; }
.chat-person:hover,
.chat-person.is-open { background: var(--tg-paper); color: var(--tg-ink); }
.chat-person.is-wait { box-shadow: inset 4px 0 0 var(--tg-coral); }
.chat-person .chat-ava { grid-row: span 2; }
.chat-person__name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-person__time { font-size: .75rem; font-weight: 700; color: var(--tg-muted); white-space: nowrap; }
.chat-person__last { grid-column: 2; color: var(--tg-ink-2); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-person.is-new .chat-person__last { color: var(--tg-ink); font-weight: 800; }
.chat-person__n { grid-column: 3; justify-self: end; }
.chat-person__dot { grid-column: 3; justify-self: end; width: 12px; height: 12px; border-radius: 50%; background: var(--tg-coral); }
.chat-people__none { margin: 0; padding: 1.5rem 1rem; color: var(--tg-muted); text-align: center; }
/* the page-number bar at the end of the list (50 chats a page): smaller buttons, so "‹ 1 2 3 … 60 ›" fits on one line */
.chat-people__pager { padding: .9rem .5rem 1rem; border-top: 1px solid var(--tg-line); }
.chat-people__pager .pagination { gap: 6px; margin: 0; }
.chat-people__pager .page-link { min-width: 36px; height: 36px; font-size: .85rem; }

.chat-ava {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: var(--tg-bw) solid var(--tg-ink);
    color: var(--tg-ink);
    font-size: .88rem;
    font-weight: 900;
}
.chat-ava--sun { background: var(--tg-sun); }
.chat-ava--mint { background: var(--tg-mint); }
.chat-ava--lilac { background: var(--tg-lilac); }
.chat-ava--sky { background: #d8e4ff; }
.chat-ava--coral { background: #ffd2c6; }

.chat-pick {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    padding: 2rem;
    border-radius: var(--tg-r-lg);
    background: var(--tg-surface);
    box-shadow: var(--tg-soft);
    color: var(--tg-muted);
    text-align: center;
}
.chat-pick .bi { font-size: 2.4rem; color: var(--tg-line-2); }
.chat-pick p { margin: 0; font-weight: 700; }

/* ---------- 4. Phones ---------- */
@media (max-width: 767.98px) {
    /* One at a time: the list, or the chat with an arrow back to it */
    .chat-two { grid-template-columns: minmax(0, 1fr); }
    .chat-page--organiser.is-chat .chat-people { display: none; }
    .chat-page--organiser.is-list .chat-pick { display: none; }
    .chat-page--organiser.is-list .chat-two { height: auto !important; grid-template-rows: auto; }
    .chat-page--organiser.is-list .chat-people__list { overflow: visible; }
    .chat-box__back { display: grid; }
}

@media (max-width: 575.98px) {
    .chat-tabs { margin-bottom: .9rem; gap: .15rem; }
    .chat-tab { gap: .35rem; padding: .45rem .7rem; font-size: .82rem; }
    .chat-box__bar { gap: .65rem; padding: .8rem .9rem; }
    .chat-box__crest { display: none; }
    .chat-box__bar .chat-ava { width: 38px; height: 38px; font-size: .8rem; }
    .chat-turn { max-width: 88%; gap: .45rem; }
    .chat-turn__ava { width: 30px; height: 30px; font-size: .8rem; }
    .chat-write { padding: .6rem; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-turn.is-new .chat-bubble { animation: none; }
}
