/* ---------- The household chat ---------- */

/* The top bar's speech bubble (with the unread count, like the bell). */
.chat-button.active { color: var(--accent); }

.chat-page { max-width: 880px; padding-bottom: 0; }
/* The chat is the whole screen: only its message list scrolls, the page itself doesn't (no footer, no space below). */
main:has(.chat-page) { padding-bottom: 0; }
.shani:has(.chat-page) .app-footer { display: none; }

/* Fills the screen below the top bar (chatFit sets the height): head, the messages scrolling inside, the box to write in. */
.chat {
    position: relative;
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 140px);
    min-height: 280px;
    padding: 0;
    overflow: hidden;
}

.chat__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
}
.chat__people { display: flex; }
.chat__people .avatar + .avatar { margin-left: -8px; }
.chat__title { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.chat__title small { color: var(--ink-muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__offline { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; color: var(--ink-muted); font-size: 0.8rem; }

.chat__log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Pictures loading above what is on screen don't push it away (the browser's scroll anchoring; Safari: chatFit). */
    overflow-anchor: auto;
    padding: 8px 12px 12px;
    display: flex;
    flex-direction: column;
}
.chat__log > :first-child { margin-top: auto; }
.chat__log .endless__more { min-height: 44px; padding: 4px 0; }

.chat__empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--ink-muted); text-align: center; }
.chat__empty > .icon { width: 40px; height: 40px; color: var(--area, var(--accent)); }

.chat__day, .chat__unread-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 6px;
    color: var(--ink-muted);
    font-size: var(--text-xs);
    font-weight: 600;
}
.chat__day::before, .chat__day::after, .chat__unread-line::before, .chat__unread-line::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.chat__day span { padding: 2px 10px; border-radius: var(--radius-pill); background: var(--surface-2, var(--bg)); }
.chat__unread-line { color: var(--accent); }
.chat__unread-line::before, .chat__unread-line::after { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

/* One message: avatar column, then the bubble with its tools; one's own on the right in the accent colour. */
.chat-msg {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 6px;
    margin-top: 2px;
}
.chat-msg.is-first { margin-top: 10px; }
.chat-msg--mine { grid-template-columns: minmax(0, 1fr); }
.chat-msg--mine .chat-msg__avatar { display: none; }
.chat-msg__avatar { align-self: end; }
.chat-msg:not(.is-last) .chat-msg__avatar { visibility: hidden; }

.chat-msg__body { position: relative; display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.chat-msg--mine .chat-msg__body { align-items: flex-end; }
.chat-msg__name { margin: 0 0 2px 10px; color: var(--ink-muted); font-size: var(--text-xs); font-weight: 600; }

.chat-msg__bubble {
    --bubble: var(--surface-2, color-mix(in srgb, var(--ink) 7%, var(--surface)));
    position: relative;
    max-width: min(560px, 82%);
    padding: 7px 11px 6px;
    border-radius: var(--radius-lg);
    background: var(--bubble);
    color: var(--ink);
    overflow-wrap: anywhere;
    transition: box-shadow 0.3s;
}
.chat-msg.is-first:not(.chat-msg--mine) .chat-msg__bubble { border-top-left-radius: var(--radius-lg); }
.chat-msg:not(.chat-msg--mine):not(.is-last) .chat-msg__bubble { border-bottom-left-radius: 5px; }
.chat-msg:not(.chat-msg--mine):not(.is-first) .chat-msg__bubble { border-top-left-radius: 5px; }
.chat-msg--mine .chat-msg__bubble {
    --bubble: color-mix(in srgb, var(--accent) 88%, var(--surface));
    background: var(--bubble);
    color: var(--bg);
}
.chat-msg--mine:not(.is-last) .chat-msg__bubble { border-bottom-right-radius: 5px; }
.chat-msg--mine:not(.is-first) .chat-msg__bubble { border-top-right-radius: 5px; }
.chat-msg--mine .chat-msg__bubble a { color: inherit; }
.chat-msg__bubble--deleted { display: inline-flex; align-items: center; gap: 6px; background: transparent !important; color: var(--ink-muted) !important;
    border: 1px dashed var(--line); font-style: italic; font-size: 0.88rem; }
.chat-msg__bubble--deleted .icon { width: 14px; height: 14px; }
.chat-msg.is-highlighted .chat-msg__bubble { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); }

.chat-msg__text { margin: 0; white-space: pre-wrap; line-height: 1.4; }
.chat-msg__text a { text-decoration: underline; text-underline-offset: 2px; }

/* Time (and "edited") sits at the end of the last line, small. */
.chat-msg__meta { float: right; display: inline-flex; gap: 4px; margin: 6px 0 -2px 10px; font-size: 0.68rem; opacity: 0.7; line-height: 1; }

.chat-msg__picture { display: block; margin: -2px -6px 4px; }
.chat-msg__picture img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; object-fit: cover; }

.chat-quote {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0 0 5px;
    padding: 4px 8px;
    border: 0;
    border-left: 3px solid currentColor;
    border-radius: 6px;
    background: color-mix(in srgb, currentColor 10%, transparent);
    color: inherit;
    font: inherit;
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
}
.chat-quote span { opacity: 0.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-link, .chat-card {
    display: flex;
    gap: 10px;
    margin: 6px 0 2px;
    padding: 6px;
    border-radius: var(--radius-md);
    background: color-mix(in srgb, currentColor 8%, transparent);
    color: inherit;
    text-decoration: none;
}
.chat-link { flex-direction: column; max-width: 360px; }
.chat-link img { width: 100%; max-height: 180px; border-radius: 7px; object-fit: cover; }
.chat-link__text, .chat-card__text { display: flex; flex-direction: column; gap: 1px; min-width: 0; font-size: var(--text-sm); }
.chat-link__text small, .chat-card__text small { opacity: 0.7; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.chat-link__text span { opacity: 0.85; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chat-card { align-items: center; min-width: 220px; }
.chat-card img, .chat-card__icon { width: 52px; height: 52px; flex: none; border-radius: var(--radius-sm); object-fit: cover; }
.chat-card__icon { display: grid; place-items: center; background: color-mix(in srgb, currentColor 12%, transparent); }
.chat-card__icon .icon { width: 24px; height: 24px; }

/* The tools: next to the bubble on hover (mouse), after a tap (touch). */
.chat-msg__tools {
    position: absolute;
    top: -14px;
    right: 8px;
    z-index: 2;
    display: none;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.chat-msg.is-active .chat-msg__tools { display: flex; }
@media (hover: hover) {
    .chat-msg:hover .chat-msg__tools, .chat-msg__tools:focus-within { display: flex; }
}

.chat-picker {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    display: flex;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.chat-picker__item {
    width: 34px; height: 34px; display: grid; place-items: center; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer;
}
.chat-picker__item:hover, .chat-picker__item:focus-visible { background: var(--surface-2, var(--bg)); transform: scale(1.12); }
.chat-picker__item .icon { width: 20px; height: 20px; }
.chat-picker__item:nth-child(1) { color: var(--danger); }

.chat-msg__reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 6px 0; }
.chat-reaction {
    display: inline-flex; align-items: center; gap: 3px; height: 24px; padding: 0 7px;
    border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); color: var(--ink-muted);
    font: inherit; font-size: var(--text-xs); cursor: pointer;
}
.chat-reaction .icon { width: 14px; height: 14px; }
.chat-reaction.is-mine { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.chat-reaction--heart .icon { color: var(--danger); }

.chat-msg__seen { display: inline-flex; align-items: center; gap: 3px; margin: 2px 6px 0; color: var(--ink-muted); font-size: 0.7rem; }
.chat-msg__seen .icon { width: 12px; height: 12px; }

/* To the newest message (when scrolled up), with how many came meanwhile. */
.chat__jump {
    position: absolute;
    right: 18px;
    bottom: 96px;
    z-index: 3;
    width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
    border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink);
    box-shadow: var(--shadow); cursor: pointer;
}
.chat__jump .icon { width: 20px; height: 20px; }
.chat__jump-count {
    position: absolute; top: -6px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px;
    display: grid; place-items: center; border-radius: var(--radius-pill); background: var(--accent); color: var(--bg); font-size: 0.7rem; font-weight: 700;
}

.chat__typing { display: flex; align-items: center; gap: 6px; min-height: 20px; padding: 0 18px; color: var(--ink-muted); font-size: 0.78rem; }
.chat__dots { display: inline-flex; gap: 3px; }
.chat__dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: chat-dot 1.2s infinite ease-in-out; }
.chat__dots i:nth-child(2) { animation-delay: 0.15s; }
.chat__dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
[data-motion="reduced"] .chat__dots i { animation: none; }

.chat__compose { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.chat__context {
    display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px;
    border-left: 3px solid var(--accent); border-radius: var(--radius-sm); background: var(--surface-2, var(--bg)); font-size: 0.82rem;
}
.chat__context > .icon { width: 16px; height: 16px; flex: none; color: var(--accent); }
.chat__context > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__context > span > span { color: var(--ink-muted); }
.chat__row { display: flex; align-items: flex-end; gap: 8px; }
.chat__input { position: relative; flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 4px; }
.chat__input textarea { flex: 1; min-width: 0; min-height: var(--control-h); max-height: 180px; resize: none; }
.chat__input textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__file { cursor: pointer; flex: none; }
.chat__file input[type="file"] { display: none; }
.chat__send { width: 42px; height: 42px; flex: none; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.chat__send .icon { width: 20px; height: 20px; }

/* Up to 980px the menu button sits at the bottom left (pages.css), as on phones. */
@media (max-width: 980px) {
    .chat-page { padding-inline: 0; }
    .chat { border-radius: 0; border-inline: 0; }
    .chat-msg__bubble { max-width: 86%; }
    /* The menu button sits at the bottom left: the box to write in starts beside it. */
    .chat__compose { padding-left: 84px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .chat__jump { bottom: 104px; }
    .chat__row .chat__more { display: grid; }
    .chat__row .chat__attach { display: none; }
    .chat__row { position: relative; gap: 6px; }
    .chat__row .icon-button, .chat__row .chat__emoji-button { width: 36px; }
    .chat__row .chat__send { width: 40px; height: 40px; }
    /* "+" open: picture and GIF float above it. */
    .chat__row .chat__attach.is-open {
        position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 4; display: flex; gap: 4px; padding: 4px;
        border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--shadow);
    }
    .chat__row .chat__more.is-active { color: var(--accent); }
    .chat__row .chat__more .icon { transition: transform 0.15s; }
    .chat__row .chat__more.is-active .icon { transform: rotate(45deg); }
    /* The round mixer and quick access buttons would sit on the messages and the box to write in: on phones the chat
       does without them (the settings have the mixer, the other pages the quick links). */
    .shani:has(.chat-page) .quick-mixer, .shani:has(.chat-page) .quick-access { display: none; }
}

/* Narrow computer screens: the round buttons at the bottom left reach into the chat, the box to write in starts beside them. */
@media (min-width: 981px) and (max-width: 1140px) {
    .shani:has(.quick-mixer, .quick-access) .chat__compose { padding-left: 64px; }
    .shani:has(.quick-mixer):has(.quick-access) .chat__compose { padding-left: 112px; }
}

/* ---------- Emoji and GIFs (chat and notes) ---------- */

/* Emoji are text: the device's emoji font draws them. */
.emoji-picker__item, .emoji-suggest__emoji, .chat-reaction__emoji, .chat-picker__item, .chat-msg__bubble--jumbo .chat-msg__text {
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", var(--font-ui);
}

/* Only one to three emoji: big, without a bubble. */
.chat-msg__bubble--jumbo { background: transparent !important; padding-inline: 2px; }
.chat-msg__bubble--jumbo .chat-msg__text { font-size: 2.6rem; line-height: 1.15; }
.chat-msg--mine .chat-msg__bubble--jumbo { color: var(--ink); }

.chat-picker__item { font-size: 1.25rem; line-height: 1; }
.chat-picker__more { color: var(--ink-muted); font-size: inherit; }
.chat-reaction__emoji { font-size: 0.95rem; line-height: 1; }

/* The emoji and GIF buttons beside the box to write in, and their panel above it. */
.chat__gif-label, .note-toolbar__gif { font-size: var(--text-xs); font-weight: 800; letter-spacing: 0.04em; }
.chat__gif.is-active, .chat__emoji-button.is-active { color: var(--accent); }
.chat__emoji-button {
    flex: none; width: var(--control-h); height: var(--control-h); display: grid; place-items: center; padding: 0;
    border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--ink-muted); cursor: pointer;
}
.chat__emoji-button:hover { color: var(--accent); }
.chat__emoji-button .icon { width: 22px; height: 22px; }
.chat__attach { display: contents; }
.chat__more { display: none; }
.chat__panel { display: flex; }
.chat__panel > * { flex: 1; }

.emoji-picker, .gif-picker {
    display: flex; flex-direction: column; gap: var(--space-2); width: 100%; max-width: 420px; max-height: min(360px, 50vh);
    padding: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow);
}
.chat__panel .emoji-picker, .chat__panel .gif-picker, .note-editor__panel .emoji-picker, .note-editor__panel .gif-picker { max-width: none; }
.emoji-picker__tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.emoji-picker__tab {
    flex: none; width: 34px; height: 30px; display: grid; place-items: center; padding: 0;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-muted); cursor: pointer;
}
.emoji-picker__tab .icon { width: 18px; height: 18px; }
.emoji-picker__tab.is-active { background: var(--surface-2); color: var(--accent); }
.emoji-picker__grid { flex: 1; min-height: 120px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); align-content: start; }
.emoji-picker__item {
    height: 38px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--radius-sm);
    background: transparent; font-size: 1.45rem; line-height: 1; cursor: pointer;
}
.emoji-picker__item:hover, .emoji-picker__item:focus-visible { background: var(--surface-2); transform: scale(1.12); }
.emoji-picker__empty { grid-column: 1 / -1; margin: var(--space-3); text-align: center; }

/* ":herz" suggestions, above the text box. */
.emoji-suggest {
    position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 5; min-width: 220px; max-width: 100%; margin: 0; padding: 4px;
    list-style: none; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow);
}
.emoji-suggest__item { display: flex; align-items: center; gap: var(--space-2); padding: 4px 8px; border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; }
.emoji-suggest__item small { margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emoji-suggest__item.is-active, .emoji-suggest__item:hover { background: var(--surface-2); }
.emoji-suggest__emoji { font-size: 1.25rem; line-height: 1; }

.gif-picker { max-height: min(420px, 60vh); }
.gif-picker__grid { flex: 1; min-height: 120px; overflow-y: auto; columns: 3 110px; column-gap: 6px; }
.gif-picker__item {
    position: relative; display: block; width: 100%; margin: 0 0 6px; padding: 0; overflow: hidden; break-inside: avoid;
    border: 0; border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer;
}
.gif-picker__item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.gif-picker__item:hover, .gif-picker__item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.gif-picker__busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgb(0 0 0 / 35%); }
.gif-picker__more, .gif-picker__nothing { display: flex; justify-content: center; align-items: center; gap: var(--space-2); margin: 0; }
.gif-picker__credit { margin: 0; font-size: var(--text-xs); text-align: right; }
.gif-picker__empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: var(--space-4); text-align: center; }
.gif-picker__empty > .icon { width: 32px; height: 32px; color: var(--ink-muted); }
.gif-picker__empty p { margin: 0; }

/* Notes: the panel under the toolbar, and the box around the text for the suggestions. */
.note-editor__panel { display: flex; flex-basis: 100%; margin-top: var(--space-2); }
.note-editor__panel > * { flex: 1; }
.note-editor__write { position: relative; min-width: 0; }
.note-view img[src*="api/media/"] { max-width: 100%; border-radius: var(--radius-sm); }

/* ---------- The small floating chat window (computers) ---------- */

/* Bottom right, fixed to the screen from the shell (never inside .page, so nothing there becomes its containing block). */
.chat-window {
    position: fixed; right: 20px; bottom: 20px; z-index: 20;
    width: 360px; height: min(520px, calc(100vh - 110px));
    display: flex; border-radius: var(--radius-lg); box-shadow: 0 18px 50px rgb(0 0 0 / 35%);
}
.chat-window .chat { flex: 1; height: auto; min-height: 0; }
.chat--compact .chat__head { padding: 8px 10px 8px 14px; }
.chat--compact .chat__people .avatar { --avatar-size: 26px !important; }
.chat__window-tools { margin-left: auto; display: flex; gap: 2px; }
.chat--compact .chat__offline { margin-left: 0; }
.chat--compact .chat-msg__bubble { max-width: 86%; }
.chat--compact .chat-msg__picture img { max-height: 220px; }
.chat--compact .chat-link { max-width: 260px; }
.chat--compact .emoji-picker, .chat--compact .gif-picker { max-height: 240px; }
.chat--compact .chat__jump { bottom: 84px; right: 12px; }
/* The round buttons at the bottom left are far away: the box to write in uses the whole width. */
.shani .chat-window .chat.chat--compact .chat__compose { padding-left: 12px; }

/* Minimised: a round bubble with the unread count. */
.chat-bubble {
    position: fixed; right: 20px; bottom: 20px; z-index: 20;
    width: 56px; height: 56px; display: grid; place-items: center; padding: 0;
    border: 1px solid var(--line); border-radius: 50%; background: var(--accent); color: var(--bg);
    box-shadow: 0 10px 30px rgb(0 0 0 / 35%); cursor: pointer; transition: transform 0.15s;
}
.chat-bubble:hover, .chat-bubble:focus-visible { transform: translateY(-2px); }
.chat-bubble .icon { width: 26px; height: 26px; }
.chat-bubble .bell__badge { top: -2px; right: -2px; }

/* Room for what else sits at the bottom right: the shopping list's cart, the music player. */
.shani:has(.fabs) :is(.chat-window, .chat-bubble) { bottom: 92px; }
.shani:has(.mini-player) :is(.chat-window, .chat-bubble) { right: 400px; }
.shani:has(.mini-player-bubble) :is(.chat-window, .chat-bubble) { right: 88px; }

/* Below 981px there's no window (the chat is its page there); the component doesn't draw it, this is the safety net. */
@media (max-width: 980px) {
    .chat-window, .chat-bubble { display: none; }
}
/* Narrow like a phone: picture and GIF behind "+" here too. */
.chat--compact .chat__row { position: relative; gap: 6px; }
.chat--compact .chat__row .chat__more { display: grid; }
.chat--compact .chat__row .chat__attach { display: none; }
.chat--compact .chat__row .chat__attach.is-open {
    position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 4; display: flex; gap: 4px; padding: 4px;
    border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--shadow);
}
.chat--compact .chat__row .chat__more.is-active { color: var(--accent); }
.chat--compact .chat__row .chat__more.is-active .icon { transform: rotate(45deg); }
