/* =========================================================
   Hotflixx — Conversas / Chat Hotflixx (FASE EXPERIMENTAL)
========================================================= */

.chat-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.chat-tabs button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.chat-tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent, #fff); }
.chat-tabs b {
    min-width: 20px; padding: 1px 6px; border-radius: 99px;
    background: #fff; color: var(--accent); font-size: 11px; text-align: center;
}
.chat-tabs b[hidden] { display: none; }
.chat-state { margin-left: auto; font-size: 13px; font-weight: 700; }
.chat-state.on { color: var(--success); }
.chat-state.off { color: var(--text-muted); }

/* ---------- Definições ---------- */

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 760px;
    padding: 20px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.chat-switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.chat-switch input { position: absolute; opacity: 0; pointer-events: none; }
.chat-switch-ui {
    flex: 0 0 46px; height: 26px; margin-top: 2px; border-radius: 99px; position: relative;
    background: var(--surface-3); border: 1px solid var(--border-strong); transition: background .15s;
}
.chat-switch-ui::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
    background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.chat-switch input:checked + .chat-switch-ui { background: var(--accent); border-color: var(--accent); }
.chat-switch input:checked + .chat-switch-ui::after { transform: translateX(20px); }
.chat-switch input:focus-visible + .chat-switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-switch strong { display: block; font-size: 15px; }
.chat-switch small, .chat-mode small { display: block; color: var(--text-muted); font-size: 13px; line-height: 1.45; margin-top: 2px; }

.chat-modes { margin: 0; padding: 0; border: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chat-modes legend { font-weight: 800; font-size: 14px; margin-bottom: 8px; }
.chat-mode {
    display: flex; gap: 10px; align-items: flex-start; padding: 14px; border-radius: 12px; cursor: pointer;
    border: 1.5px solid var(--border); background: var(--surface-2);
}
.chat-mode:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
.chat-mode input { margin-top: 3px; accent-color: var(--accent); }
.chat-mode em {
    font-style: normal; font-size: 10.5px; font-weight: 800; margin-left: 4px; padding: 1px 6px; border-radius: 99px;
    background: var(--accent); color: #fff; vertical-align: 2px;
}

.chat-auto { display: flex; flex-direction: column; gap: 8px; }
.chat-auto[hidden] { display: none; }
.chat-check { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 600; cursor: pointer; }
.chat-check input { accent-color: var(--accent); width: 17px; height: 17px; }
.chat-label { font-weight: 800; font-size: 14px; margin-top: 6px; }
.chat-auto textarea {
    width: 100%; box-sizing: border-box; padding: 10px 12px; border-radius: 10px; resize: vertical;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
}
.chat-auto textarea:focus { outline: none; border-color: var(--accent); }
.chat-auto code, .chat-info code {
    padding: 1px 6px; border-radius: 6px; background: var(--surface-3); font-size: 12.5px; word-break: break-all;
}
.chat-link-btn {
    margin-left: 6px; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer;
}
.chat-warn {
    margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 13px;
    background: color-mix(in srgb, var(--warning) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
}
.chat-warn a { color: inherit; font-weight: 700; }

.chat-preview { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.chat-preview-title { display: block; padding: 7px 12px; font-size: 12px; font-weight: 800; color: var(--text-muted); background: var(--surface-2); }
.chat-preview-wall { max-height: 300px; overflow: auto; }

.chat-info { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.chat-info p { margin: 0 0 6px; }
.chat-info strong { color: var(--warning); }
.chat-form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-msg { font-size: 13px; font-weight: 600; }
.chat-msg[data-kind="ok"] { color: var(--success); }
.chat-msg[data-kind="error"] { color: var(--danger, #e5484d); }

/* ---------- Conversas ---------- */

.chat-panes {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    height: max(440px, calc(100dvh - 320px));
    border-radius: 14px;
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--surface);
}

.chat-list { overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface); }

.chat-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0;
    border-bottom: 1px solid var(--border); background: transparent; color: var(--text); text-align: left; font: inherit; cursor: pointer;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.chat-avatar {
    flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(135deg, #3a3a44, #22222a); color: #fff; font-weight: 800; font-size: 15px; letter-spacing: .02em;
}
.chat-item.unread .chat-avatar { background: linear-gradient(135deg, #ff3b3b, #b20710); }
.chat-item-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.chat-item-top { display: flex; align-items: center; gap: 6px; }
.chat-item-top strong { font-size: 14.5px; }
.chat-item-top time { margin-left: auto; font-size: 11.5px; color: var(--text-muted); }
.chat-item-product, .chat-item-last { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-product { color: var(--text); opacity: .85; }
.chat-item.unread .chat-item-last { color: var(--text); font-weight: 600; }
.chat-item-last em { color: var(--accent); font-style: normal; font-weight: 700; }
.chat-count { flex: 0 0 auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 11.5px; }
.chat-tag { font-style: normal; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 99px; border: 1px solid currentColor; }
.chat-tag.sold { color: var(--success); }
.chat-tag.closed { color: var(--text-muted); }
.chat-tag.blocked { color: var(--danger, #e5484d); }

.chat-empty { padding: 28px 18px; text-align: center; color: var(--text-muted); font-size: 13.5px; }
.chat-empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.chat-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-thread-empty { flex: 1; display: grid; place-items: center; }
.chat-thread-empty span { padding: 6px 14px; border-radius: 99px; background: rgba(0, 0, 0, .35); color: #fff; font-size: 13px; }
.chat-thread-head {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--hfc-panel); border-bottom: 1px solid var(--hfc-line);
}
.chat-thread-head .chat-avatar { flex-basis: 40px; width: 40px; height: 40px; background: linear-gradient(135deg, #ff3b3b, #b20710); }
.chat-thread-title { min-width: 0; flex: 1; line-height: 1.25; }
.chat-thread-title strong { display: block; font-size: 15px; }
.chat-thread-title small { display: block; font-size: 12.5px; color: var(--hfc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-title small.typing { color: var(--hfc-red-2); font-weight: 600; }
.chat-back { display: none; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--hfc-text); font-size: 26px; line-height: 1; cursor: pointer; }
.chat-actions { display: flex; align-items: center; gap: 6px; }
.chat-actions select {
    height: 34px; padding: 0 8px; border-radius: 9px; border: 1px solid var(--hfc-line); background: var(--hfc-panel-2); color: var(--hfc-text); font: inherit; font-size: 13px;
}
.chat-del { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--hfc-line); background: var(--hfc-panel-2); cursor: pointer; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; }

@media (max-width: 820px) {
    .chat-panes { grid-template-columns: 1fr; height: calc(100dvh - 210px); min-height: 420px; }
    .chat-panes .chat-thread { display: none; }
    .chat-panes.has-thread .chat-list { display: none; }
    .chat-panes.has-thread .chat-thread { display: flex; }
    .chat-back { display: grid; place-items: center; }
    .chat-modes { grid-template-columns: 1fr; }
    .chat-form { padding: 16px; }
    .chat-actions select { max-width: 120px; }
}

/* No painel, o chat segue o tema do painel (escuro/claro/paletas) */
.chat-app .hfc {
    --hfc-bg: var(--bg);
    --hfc-panel: var(--surface);
    --hfc-panel-2: var(--surface-2);
    --hfc-line: var(--border);
    --hfc-text: var(--text);
    --hfc-muted: var(--text-muted);
    --hfc-in: var(--surface-3);
    --hfc-in-text: var(--text);
    --hfc-red: var(--accent);
    --hfc-red-2: var(--accent-hover, var(--accent));
}
.chat-app .hfc-wall { background-color: var(--bg); }
.hfc-row.out .hfc-label { color: rgba(255, 255, 255, .85); }
.chat-del { display: grid; place-items: center; color: var(--hfc-muted); }
.chat-del:hover { color: var(--danger, #e5484d); border-color: currentColor; }

/* Telemóvel: a conversa aberta ocupa o ecrã inteiro (como no Telegram) */
@media (max-width: 820px) {
    .chat-panes.has-thread .chat-thread {
        position: fixed;
        inset: 0;
        z-index: 1000;
        height: 100dvh;
        background: var(--bg);
    }
    .chat-panes.has-thread .chat-thread-head { padding-top: max(8px, env(safe-area-inset-top)); }
    .chat-panes.has-thread .hfc-compose { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* Notificações das Conversas */
.chat-notify {
    display: flex; flex-direction: column; gap: 8px;
    padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
}
.chat-notify.off strong { display: block; margin-bottom: 4px; }
.chat-notify.off p { margin: 0; color: var(--text-muted); font-size: 13.5px; }
.chat-device { margin: 0; font-size: 13px; font-weight: 600; }
.chat-device:empty { display: none; }
.chat-device[data-kind="ok"] { color: var(--success); }
.chat-device[data-kind="warn"] { color: var(--warning); }
.chat-device-btn { align-self: flex-start; }
.chat-device-btn[hidden] { display: none; }
