/* Cochicho — chat 1:1. Grade de 8px; tipografia 12/16/20/24.
   Tema escuro índigo com acento violeta (#7c6cf0). */

:root {
    --ink: #1b1d29;
    --slate: #2a2d3a;
    --brand: #7c6cf0;
    --paper: #eef0f6;

    --bg: var(--ink);
    --bg-panel: #21242f;
    --bg-elev: var(--slate);
    --border: #363a4a;
    --text: var(--paper);
    --text-dim: #9aa0b4;
    --accent: var(--brand);
    --accent-strong: #8f80ff;
    --accent-soft: rgba(124, 108, 240, 0.16);
    --bubble-own: #3a3568;
    --bubble-other: var(--slate);
    --danger: #e06c75;
    --ok: #5fbf82;
    --warn: #d9b25a;
    --radius: 16px;
    --composer-h: 72px;
}

* { box-sizing: border-box; }

/* [hidden] precisa vencer displays de classe (ex.: .modal-backdrop { display:flex }) */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    /* degradê preto→verde, discreto, como no manual */
    background-image:
        radial-gradient(120% 90% at 100% 0%, rgba(124, 108, 240, 0.22) 0%, rgba(124, 108, 240, 0) 55%),
        radial-gradient(100% 80% at 0% 100%, rgba(124, 108, 240, 0.12) 0%, rgba(124, 108, 240, 0) 50%);
    background-attachment: fixed;
    color: var(--text);
    font-family: "Century Gothic", CenturyGothic, "URW Gothic", Futura, "Trebuchet MS",
        -apple-system, "Segoe UI", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    overflow: hidden;
}

.chat-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 840px;
    margin: 0 auto;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

/* Telas (lista de conversas / conversa) */
.view {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* Header — degradê preto→verde da marca */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(100deg, var(--ink) 30%, #2c2a52 78%, #3a3568 100%);
    flex-shrink: 0;
}

.chat-header__brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

/* Wordmark */
.chat-header__logo {
    margin: 0;
    line-height: 1;
}

.wordmark {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.wordmark::first-letter {
    color: var(--accent-strong);
}

.chat-header__titles {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chat-header__badge {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(249, 249, 249, 0.72);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header__status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: rgba(249, 249, 249, 0.72);
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warn);
    flex-shrink: 0;
}

.status-dot[data-state="online"] { background: var(--accent-strong); }
.status-dot[data-state="offline"] { background: var(--danger); }

/* Header da conversa (contato) */
.chat-header--conv {
    gap: 8px;
    padding: 8px 8px 8px 4px;
}

.conv-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--paper);
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    flex-shrink: 0;
}

.chat-header__contact {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header__name {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header__sub {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: rgba(249, 249, 249, 0.72);
    white-space: nowrap;
    overflow: hidden;
}

/* Lista de conversas */
.conv-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.conv-item:hover { background: rgba(124, 108, 240, 0.10); }

.conv-item__avatar {
    width: 48px;
    height: 48px;
    font-size: 20px;
}

.conv-item__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conv-item__name {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item__preview {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item__time {
    font-size: 12px;
    color: var(--text-dim);
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 4px;
}

.conv-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    text-align: center;
}

.conv-empty__icon { font-size: 48px; }

.conv-empty__title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.conv-empty__text {
    margin: 0;
    max-width: 320px;
    font-size: 16px;
    color: var(--text-dim);
}

/* FAB nova conversa */
.fab {
    position: absolute;
    right: 24px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--brand);
    color: var(--paper);
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    -webkit-tap-highlight-color: transparent;
}

.fab:hover { background: var(--accent-strong); }

/* Banner de convite (conversa aguardando o outro participante) */
.invite-banner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--accent-soft);
    font-size: 12px;
    flex-shrink: 0;
}

.invite-banner__text { color: var(--text-dim); }

.invite-banner__code {
    flex: 1;
    min-width: 120px;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--ink);
    color: var(--accent-strong);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn--small {
    padding: 4px 16px;
    font-size: 12px;
}

/* Mensagens */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-messages__loader {
    display: flex;
    justify-content: center;
    padding-bottom: 8px;
}

.msg {
    display: flex;
    flex-direction: column;
    max-width: 72%;
    align-self: flex-start;
    margin-bottom: 4px;
}

.msg--own { align-self: flex-end; }

/* nome só nas mensagens do outro, acima da bolha (estilo apps de conversa) */
.msg__name {
    padding: 0 12px;
    margin-bottom: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-strong);
}

.msg__bubble {
    position: relative;
    padding: 8px 12px 4px;
    border-radius: var(--radius);
    border-bottom-left-radius: 4px;
    background: var(--bubble-other);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
    font-size: 16px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.msg--own .msg__bubble {
    background: var(--bubble-own);
    border-radius: var(--radius);
    border-bottom-right-radius: 4px;
}

/* hora dentro da bolha, canto inferior direito */
.msg__time {
    display: block;
    margin-top: 2px;
    text-align: right;
    font-size: 12px;
    line-height: 1.2;
    color: rgba(249, 249, 249, 0.55);
    white-space: nowrap;
}

.msg__bubble img {
    display: block;
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    margin: 2px 0 4px;
    cursor: zoom-in;
}

.msg__caption { margin-top: 4px; }

.file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    margin: 2px 0 4px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--text);
    text-decoration: none;
}

.file-card__icon { font-size: 20px; }

.file-card__info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.file-card__name {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

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

/* Player de áudio (nota de voz) */
.audio-msg {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 232px;
    max-width: 288px;
    margin: 2px 0 4px;
}

.audio-play {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: var(--paper);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s;
}

.audio-play:hover { background: var(--accent-strong); }

.audio-play.is-loading {
    background: var(--accent-soft);
}

.audio-play.is-loading::after {
    content: "";
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: var(--paper);
    animation: audio-spin 0.7s linear infinite;
}

@keyframes audio-spin { to { transform: rotate(360deg); } }

.audio-mic {
    flex-shrink: 0;
    font-size: 16px;
    opacity: 0.7;
    align-self: flex-end;
    margin-bottom: 2px;
}

.audio-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.audio-track {
    position: relative;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.16);
    cursor: pointer;
    touch-action: none;
    /* alvo de toque maior sem crescer o visual */
    padding: 10px 0;
    margin: -10px 0;
    background-clip: content-box;
}

.audio-fill {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    width: 0;
    border-radius: 3px;
    background: var(--accent-strong);
}

.audio-thumb {
    position: absolute;
    top: 50%;
    left: 0;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--paper);
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.audio-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.audio-time { font-variant-numeric: tabular-nums; }

.audio-speed {
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1px 8px;
    background: transparent;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.audio-speed:hover { color: var(--text); border-color: var(--accent); }

.msg--system {
    align-self: center;
    max-width: 90%;
    margin: 8px 0;
    padding: 4px 16px;
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.3);
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
}

/* Typing */
.chat-typing {
    padding: 0 24px 4px;
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
    flex-shrink: 0;
}

/* Composer — pílula estilo apps de conversa */
.chat-composer {
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.composer-pill {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    min-width: 0;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--ink);
}

.composer-pill:focus-within { border-color: var(--brand); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }

.icon-btn--header {
    width: 32px;
    height: 32px;
    color: rgba(249, 249, 249, 0.72);
}

.icon-btn--header:hover {
    background: rgba(214, 106, 106, 0.16);
    color: var(--danger);
}

.composer-input {
    flex: 1;
    min-width: 0;
    resize: none;
    max-height: 120px;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    outline: none;
}

.composer-input::placeholder { color: #7a7a7a; }

.send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--brand);
    color: var(--paper);
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    -webkit-tap-highlight-color: transparent;
}

.send-btn svg { margin-left: 2px; }

.send-btn:hover { background: var(--accent-strong); }

.send-btn:disabled { opacity: 0.5; cursor: default; }

/* barra de gravação de áudio */
.composer-recording {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 48px;
    padding: 0 8px 0 4px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--ink);
}

.icon-btn--danger { color: var(--danger); }
.icon-btn--danger:hover { background: rgba(224, 108, 117, 0.16); color: var(--danger); }

.rec-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    flex-shrink: 0;
    animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.rec-timer {
    font-variant-numeric: tabular-nums;
    font-size: 16px;
    color: var(--text);
    flex-shrink: 0;
}

.rec-hint {
    font-size: 12px;
    color: var(--text-dim);
    flex: 1;
}

.composer-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 8px 8px;
    padding: 8px 16px;
    border: 1px dashed #4a4487;
    border-radius: 12px;
    background: var(--accent-soft);
    font-size: 12px;
}

.composer-attachment__name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.composer-attachment__remove {
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
}

.composer-attachment__remove:hover { color: var(--paper); }

/* Emoji popover — sem rolagem lateral: grade fluida, só rolagem vertical */
.emoji-popover {
    position: absolute;
    bottom: calc(var(--composer-h) + env(safe-area-inset-bottom));
    left: 16px;
    z-index: 30;
    width: 320px;
    max-height: 264px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    overscroll-behavior: contain;
}

.emoji-popover__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 2px;
}

.emoji-popover__grid button {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 22px;
    padding: 0;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.emoji-popover__grid button:hover { background: var(--accent-soft); }

/* Bloqueio da conversa protegida */
.lock-overlay {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg-panel);
}

.lock-overlay__box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 320px;
    text-align: center;
    color: var(--text-dim);
}

.lock-overlay__box svg { color: var(--brand); }

.lock-overlay__title {
    margin: 8px 0 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.lock-overlay__text {
    margin: 0 0 8px;
    font-size: 16px;
}

.lock-overlay__error {
    margin: 0;
    font-size: 12px;
    color: var(--danger);
}

.lock-overlay__btn {
    width: 100%;
    margin-top: 8px;
}

.icon-btn--lock.icon-btn--protected { color: var(--accent-strong); }

.icon-btn--lock:hover {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.modal__input + .modal__input { margin-top: 8px; }

/* Modais */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(33, 33, 33, 0.8);
}

.modal {
    width: 100%;
    max-width: 400px;
    padding: 24px;
    border: 1px solid var(--border);
    border-top: 2px solid var(--brand);
    border-radius: var(--radius);
    background: var(--bg-elev);
}

.modal--camera { max-width: 560px; }

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

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

.modal__input {
    width: 100%;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--ink);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    outline: none;
}

.modal__input:focus { border-color: var(--brand); }

.modal__actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.btn {
    padding: 8px 24px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn--primary {
    background: var(--brand);
    color: var(--paper);
}

.btn--primary:hover { background: var(--accent-strong); }

.btn--danger {
    background: var(--danger);
    color: var(--paper);
}

.btn--danger:hover { background: #c25555; }

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

.btn--ghost:hover { color: var(--text); border-color: var(--brand); }

.camera-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.camera-stage video,
.camera-stage img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-switch {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.camera-switch:hover { background: rgba(0, 0, 0, 0.75); }

/* Toast */
.toast {
    position: fixed;
    bottom: calc(var(--composer-h) + 24px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    max-width: calc(100vw - 32px);
    padding: 8px 24px;
    border-radius: 8px;
    background: var(--danger);
    color: var(--paper);
    font-size: 12px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.toast--info {
    background: var(--bg-elev);
    border: 1px solid #4a4487;
    color: var(--text);
}

/* ===== Celular: layout estilo WhatsApp/Telegram ===== */
@media (max-width: 600px) {
    .chat-shell {
        max-width: none;
        border: none;
    }

    .chat-header {
        padding: 8px 8px 8px 16px;
        gap: 8px;
    }

    .chat-header__logo img { height: 24px; }

    .chat-header__badge { letter-spacing: 0.04em; }

    .chat-messages {
        padding: 8px 12px;
    }

    .msg { max-width: 84%; }

    .msg__bubble { font-size: 16px; }

    .file-card__name { max-width: 160px; }

    .chat-typing { padding: 0 16px 4px; }

    .chat-composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }

    /* painel de emojis vira bottom sheet de borda a borda */
    .emoji-popover {
        left: 0;
        right: 0;
        width: auto;
        max-height: 40dvh;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }

    .emoji-popover__grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }

    .modal { padding: 16px; }

    .modal__actions .btn { flex: 1; padding: 8px 16px; }
}

/* telas muito estreitas */
@media (max-width: 360px) {
    .chat-header__badge { display: none; }
    .msg { max-width: 92%; }
}
