/*
 * Messaging, as a proper chat (Vibemakr). Everything reads the app's own look from theme.css:
 * colours, corners, shadows and typefaces. Classes are used by the Messages pages; see the markup
 * these are built for in the app's messaging pages.
 */

/* Read by screen readers, not shown (the message box's label). */
.chat-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- The top of Messages: the heading and New message ---------- */
.chat-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 44rem;
}
.chat-new {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-button, 999px);
    background: var(--color-accent);
    color: var(--color-accent-text);
    font-weight: 700;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
}
.chat-new:hover { box-shadow: var(--shadow-hover); }
.chat-new:focus-visible { outline: 3px solid var(--color-text); outline-offset: 2px; }

/* ---------- The conversation list ---------- */
.chat-list {
    list-style: none;
    margin: 1.25rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.5rem;
    max-width: 44rem;
}
.chat-list > li { margin: 0; padding: 0; }
.chat-list > li::before { content: none; }
.chat-row {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    background: var(--color-surface);
    border: var(--border-width, 1px) solid var(--border-color, rgba(0, 0, 0, 0.08));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--color-text);
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-row:hover { transform: translateY(-1px); box-shadow: var(--shadow-hover); }
.chat-row:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.chat-row-main { flex: 1; min-width: 0; display: grid; gap: 0.2rem; }
.chat-row-top, .chat-row-bottom { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.chat-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { flex: none; font-size: 0.8125rem; color: var(--color-muted); }
.chat-preview { flex: 1; min-width: 0; color: var(--color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row--unread .chat-preview { color: var(--color-text); font-weight: 600; }
.chat-unread {
    flex: none;
    min-width: 1.5rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--color-accent);
    color: var(--color-accent-text);
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
}
.chat-empty {
    max-width: 44rem;
    margin-top: 1.25rem;
    padding: 2rem 1.25rem;
    text-align: center;
    color: var(--color-muted);
    background: var(--color-surface);
    border-radius: var(--radius);
}

/* ---------- Avatars: initials in the app's colours ---------- */
.chat-avatar {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    background: var(--color-accent);
    color: var(--color-accent-text);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
}

/* ---------- One conversation ---------- */
.chat {
    max-width: 44rem;
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 10rem);
}
.chat-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: var(--border-width, 1px) solid var(--border-color, rgba(0, 0, 0, 0.08));
}
.chat-head > div { flex: 1; min-width: 0; }
.chat-back { color: var(--color-text); text-decoration: none; font-size: 1.25rem; padding: 0.25rem 0.5rem 0.25rem 0; }
.chat-title { margin: 0; font-size: 1.125rem; line-height: 1.2; }
.chat-note { margin: 0.1rem 0 0; font-size: 0.8125rem; color: var(--color-muted); }
.chat-head-action button,
.chat-head-action a { font-size: 0.875rem; }

.chat-thread {
    list-style: none;
    flex: 1;
    margin: 0;
    padding: 1.25rem 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.chat-thread > li { margin: 0; padding: 0; }
.chat-thread > li::before { content: none; }
.chat-day {
    align-self: center;
    margin: 0.75rem 0 0.5rem;
    padding: 0.2rem 0.75rem;
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-muted);
    font-size: 0.75rem;
    font-weight: 600;
}
.chat-msg { display: flex; flex-direction: column; max-width: min(78%, 32rem); }
.chat-msg--mine { align-self: flex-end; align-items: flex-end; }
.chat-msg--theirs { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
    margin: 0;
    padding: 0.6rem 0.9rem;
    border-radius: 1.15rem;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.chat-msg--mine .chat-bubble {
    background: var(--color-accent);
    color: var(--color-accent-text);
    border-bottom-right-radius: 0.35rem;
}
.chat-msg--theirs .chat-bubble {
    background: var(--color-surface);
    color: var(--color-text);
    border: var(--border-width, 1px) solid var(--border-color, rgba(0, 0, 0, 0.08));
    border-bottom-left-radius: 0.35rem;
}
.chat-meta {
    margin: 0.2rem 0.4rem 0.35rem;
    font-size: 0.75rem;
    color: var(--color-muted);
}
.chat-meta form { display: inline; }
.chat-report {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--color-muted);
    text-decoration: underline;
    cursor: pointer;
}
.chat-report:hover, .chat-report:focus-visible { color: var(--color-text); }

/* ---------- The message box, pinned to the bottom ---------- */
.chat-composer {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom));
    background: var(--color-bg);
}
.chat-input {
    flex: 1;
    min-height: 2.75rem;
    max-height: 9rem;
    padding: 0.65rem 1rem;
    resize: none;
    border-radius: 1.4rem;
    border: var(--border-width, 1px) solid var(--border-color, rgba(0, 0, 0, 0.15));
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    line-height: 1.4;
}
.chat-input:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 1px; }
.chat-send {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 999px;
    background: var(--color-accent);
    color: var(--color-accent-text);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.chat-send:disabled { opacity: 0.5; cursor: default; }
.chat-send svg { width: 1.2rem; height: 1.2rem; }
.chat-hint { margin: 0; font-size: 0.75rem; color: var(--color-muted); }
.chat-notice {
    margin: 0.5rem 0 0;
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    font-size: 0.875rem;
}

@media (max-width: 40rem) {
    .chat { min-height: calc(100dvh - 7rem); }
    .chat-msg { max-width: 85%; }
}
