/* Chat entre autoescolas e laboratório (painel /parceiros e painel admin).
   Modo reduzido: janela flutuante no canto (.chat-dock). Modo expandido: área inteira. */
.chat {
    --chat-primary: #0056b3;
    --chat-primary-dark: #003d80;
    --chat-bg: #eef3f8;
    --chat-mine: #0056b3;
    --chat-mine-text: #ffffff;
    --chat-theirs: #ffffff;
    --chat-border: #e2e8f0;
    --chat-muted: #5b6b82;
    --chat-read: #bfff00;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    background: var(--chat-bg);
    font-family: inherit;
}

.chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 14px;
    background: #fff;
    border-bottom: 1px solid var(--chat-border);
}
.chat-avatar {
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #e8f0fb;
    color: var(--chat-primary);
    font-weight: 700;
    font-size: 0.875rem;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.chat-avatar .icon { width: 20px; height: 20px; }
.chat-title { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.chat-title strong { font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small { font-size: 0.75rem; color: var(--chat-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions { display: flex; gap: 2px; flex: none; }
.chat-action {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--chat-muted);
    cursor: pointer;
}
.chat-action:hover { background: #f1f5f9; color: var(--chat-primary); }
.chat-action:focus-visible { outline: 3px solid rgba(0, 86, 179, 0.3); outline-offset: 1px; }
.chat-action .icon { width: 18px; height: 18px; }
/* botões do cabeçalho conforme o modo: janela flutuante x área inteira */
.chat-host-expanded .chat-action[data-mode="docked"],
.chat-dock .chat-action[data-mode="expanded"] { display: none; }

.chat-body {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 12px 14px;
    overscroll-behavior: contain;
}
.chat-status { display: flex; justify-content: center; align-items: center; gap: 8px; min-height: 28px; font-size: 0.8125rem; color: var(--chat-muted); }
.chat-lock { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.7); font-size: 0.75rem; }
.chat-more { border: 1px solid var(--chat-border); background: #fff; border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 0.8125rem; color: var(--chat-primary); cursor: pointer; }
.chat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-empty { text-align: center; color: var(--chat-muted); font-size: 0.875rem; padding: 32px 12px; }
.chat-day, .chat-unread-sep { display: flex; justify-content: center; margin: 12px 0 8px; }
.chat-day span { padding: 3px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.85); font-size: 0.75rem; font-weight: 600; color: var(--chat-muted); box-shadow: 0 1px 1px rgba(15, 23, 42, 0.06); }
.chat-unread-sep span { padding: 3px 14px; border-radius: 999px; background: #fff7d6; color: #7a5b00; font-size: 0.75rem; font-weight: 600; }

.chat-msg { display: flex; margin-top: 8px; }
.chat-msg.is-grouped { margin-top: 2px; }
.chat-msg.is-mine { justify-content: flex-end; }
.chat-bubble {
    position: relative;
    max-width: min(78%, 560px);
    padding: 7px 10px 6px 12px;
    border-radius: 14px;
    box-shadow: 0 1px 1px rgba(15, 23, 42, 0.08);
    font-size: 0.9375rem;
    line-height: 1.45;
}
.is-theirs .chat-bubble { background: var(--chat-theirs); color: #0f172a; border-top-left-radius: 4px; }
.is-mine .chat-bubble { background: linear-gradient(135deg, var(--chat-mine), var(--chat-primary-dark)); color: var(--chat-mine-text); border-top-right-radius: 4px; }
.is-grouped.is-theirs .chat-bubble { border-top-left-radius: 14px; }
.is-grouped.is-mine .chat-bubble { border-top-right-radius: 14px; }
.chat-author { display: block; font-size: 0.75rem; font-weight: 700; color: var(--chat-primary); margin-bottom: 1px; }
.chat-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.chat-meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 2px; font-size: 0.6875rem; opacity: 0.8; font-variant-numeric: tabular-nums; }
.is-mine .chat-meta { color: rgba(255, 255, 255, 0.85); opacity: 1; }
.chat-tick { display: inline-flex; color: rgba(255, 255, 255, 0.85); }
.chat-tick.is-read { color: var(--chat-read); }
.chat-tick.is-pending { opacity: 0.8; }
.chat-tick .icon-xs { width: 15px; height: 15px; }
.chat-retry { display: inline-flex; align-items: center; gap: 4px; border: 0; padding: 2px 6px; border-radius: 6px; background: #fee2e2; color: #991b1b; font: inherit; font-size: 0.6875rem; font-weight: 600; cursor: pointer; }

.chat-jump {
    position: sticky;
    bottom: 4px;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 0;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--chat-primary);
    color: #fff;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(0, 61, 128, 0.3);
    cursor: pointer;
}
.chat-jump-icon { transform: rotate(90deg); width: 15px; height: 15px; }

.chat-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 4px; background: #fff; border-top: 1px solid var(--chat-border); }
.chat-compose textarea {
    flex: 1;
    min-height: 42px;
    max-height: 160px;
    padding: 10px 14px;
    border: 1.5px solid var(--chat-border);
    border-radius: 21px;
    resize: none;
    font: inherit;
    font-size: 0.9375rem;
    line-height: 1.4;
    color: #0f172a;
    background: #f8fafc;
}
.chat-compose textarea:focus { outline: none; border-color: var(--chat-primary); background: #fff; box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.15); }
.chat-send {
    flex: none;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 61, 128, 0.25);
}
.chat-send:focus-visible { outline: 3px solid #bfff00; outline-offset: 2px; }
.chat-send .icon { width: 18px; height: 18px; }
.chat-hint { display: flex; justify-content: space-between; gap: 8px; margin: 0; padding: 2px 16px 8px; background: #fff; font-size: 0.6875rem; color: var(--chat-muted); }

/* ---------- janela flutuante (modo reduzido) ---------- */
.chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 18px 0 14px;
    height: 52px;
    border: 0;
    border-radius: 26px;
    background: linear-gradient(135deg, #0056b3, #003d80);
    color: #fff;
    font: inherit;
    font-weight: 600;
    box-shadow: 0 10px 28px rgba(0, 61, 128, 0.35);
    cursor: pointer;
}
.chat-launcher .icon { width: 22px; height: 22px; }
.chat-launcher:focus-visible { outline: 3px solid #bfff00; outline-offset: 3px; }
.chat-launcher-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #bfff00;
    color: #1a2e05;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-grid;
    place-items: center;
}
.chat-dock {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 61;
    width: min(380px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 40px));
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.45);
    border: 1px solid #dbe3ee;
    background: #fff;
    animation: chat-pop 0.18s cubic-bezier(0.2, 0, 0, 1);
}
@keyframes chat-pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } }

@media (max-width: 640px) {
    .chat-launcher { right: 14px; bottom: calc(76px + env(safe-area-inset-bottom)); height: 50px; padding: 0 14px; }
    .chat-launcher-label { display: none; }
    .chat-dock { right: 0; left: 0; bottom: 0; width: 100%; height: min(78vh, 640px); border-radius: 18px 18px 0 0; }
    .chat-bubble { max-width: 86%; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-dock { animation: none; }
}
