@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=DM+Serif+Display:ital@0;1&display=swap');

:root {
    --bg:        #07090f;
    --surface:   #0d1117;
    --surface2:  #111722;
    --border:    rgba(255,255,255,0.06);
    --border2:   rgba(255,255,255,0.11);
    --accent:    #c8a84b;
    --accent2:   #e8c96a;
    --green:     #67e8b4;
    --text:      #e2e6f0;
    --muted:     #5a6480;
    --radius:    14px;
    --radius-sm: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Outfit', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(200,168,75,.18); border-radius: 3px; }

/* ── HEADER ── */
.topbar {
    height: 68px; padding: 0 32px;
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(7,9,15,0.92); backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100;
}
.header-left, .header-right { display: flex; align-items: center; gap: 16px; }
.logo-header img { height: 36px; display: block; opacity: 1; transition: opacity .2s; }
.logo-header img:hover { opacity: .7; }
.btn-header {
    color: var(--muted); text-decoration: none; font-size: .83rem; font-weight: 500;
    padding: 7px 14px; border: 1px solid var(--border2); border-radius: 6px;
    display: flex; align-items: center; gap: 6px; transition: all .2s;
}
.btn-header:hover { color: var(--text); border-color: rgba(200,168,75,.35); background: rgba(200,168,75,.06); }

/* ── LAYOUT PRINCIPAL ── */
.chat-container {
    display: flex;
    height: calc(100vh - 68px);
    max-width: 1280px;
    margin: 0 auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

/* ── SIDEBAR ── */
.chat-sidebar {
    width: 340px;
    min-width: 340px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
}
.sidebar-header {
    padding: 28px 28px 18px;
}
.sidebar-eyebrow {
    font-size: .66rem;
    letter-spacing: .28em;
    text-transform: uppercase;
    color: var(--accent-ink, var(--accent));
    font-weight: 600;
    margin-bottom: 8px;
}
.sidebar-header h2 {
    font-family: 'DM Serif Display', serif;
    font-size: 1.85rem;
    font-weight: 400;
    color: #fff;
    line-height: 1;
    letter-spacing: -.01em;
    display: flex; align-items: baseline; gap: 10px;
}
.sidebar-header h2 i { display: none; }

/* botões pílula de ação */
.sidebar-actions {
    padding: 0 28px 14px;
    display: flex; gap: 8px;
}
.btn-pill {
    flex: 1;
    padding: 9px 14px;
    background: transparent;
    border: 1px solid var(--border2);
    border-radius: 999px;
    color: var(--text);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: all .15s;
}
.btn-pill:hover { background: rgba(200,168,75,.08); border-color: rgba(200,168,75,.4); color: var(--accent-ink, var(--accent)); }
.btn-pill.primary {
    background: var(--accent);
    color: #0a0c12;
    border-color: var(--accent);
}
.btn-pill.primary:hover { background: var(--accent2); border-color: var(--accent2); color: #0a0c12; }

/* botão circular antigo escondido — substituído pelos pills */
.btn-new-chat { display: none; }

/* Busca nova conversa */
.new-chat-search {
    padding: 4px 28px 14px;
}
.new-chat-search input {
    width: 100%;
    padding: 10px 0 10px 22px;
    background: transparent;
    border: none; outline: none;
    border-bottom: 1px solid var(--border2);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: .85rem;
    transition: border-color .2s;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235a6480' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>");
    background-repeat: no-repeat;
    background-position: 0 center;
}
.new-chat-search input:focus { border-color: var(--accent); }
.new-chat-search input::placeholder { color: var(--muted); }
.search-user-results { margin-top: 8px; max-height: 240px; overflow-y: auto; }
.search-user-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 4px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .15s;
}
.search-user-item:hover { background: rgba(200,168,75,.05); }
.search-user-avatar {
    width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.04); color: var(--muted); font-size: 1.4rem;
    border: 1px solid var(--border);
}
.search-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.search-user-name { font-size: .88rem; font-weight: 500; color: var(--text); }
.search-empty { color: var(--muted); font-size: .8rem; padding: 12px 0; text-align: center; }

/* Lista de conversas */
.conversas-list { flex: 1; overflow-y: auto; padding: 0 16px 24px; }
.conversas-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px 20px; color: var(--muted); text-align: center;
}
.conversas-empty i { font-size: 2.2rem; margin-bottom: 14px; opacity: .25; }
.conversas-empty p { font-size: .9rem; margin-bottom: 4px; color: var(--text); }
.conversas-empty small { font-size: .76rem; opacity: .7; }

.conversa-item {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .15s;
    position: relative;
}
.conversa-item:hover { background: rgba(255,255,255,.025); }
.conversa-item.active { background: rgba(200,168,75,.04); }
.conversa-item.active::before {
    content: '';
    position: absolute; left: -16px; top: 14px; bottom: 14px;
    width: 2px; background: var(--accent);
}

.conversa-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border2);
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 1.4rem;
    flex-shrink: 0;
}
.conversa-avatar img { width: 100%; height: 100%; object-fit: cover; }

.conversa-info { flex: 1; min-width: 0; }
.conversa-top {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 3px;
}
.conversa-nome {
    font-size: .92rem; font-weight: 500;
    color: #fff;
    letter-spacing: -.005em;
}
.conversa-time {
    font-size: .7rem; color: var(--muted);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.conversa-bottom { display: flex; justify-content: space-between; align-items: center; }
.conversa-preview {
    font-size: .8rem; color: var(--muted); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.conversa-badge {
    background: var(--accent); color: #0a0c12;
    font-size: .66rem; font-weight: 700;
    padding: 2px 7px; border-radius: 10px;
    flex-shrink: 0; margin-left: 8px;
    line-height: 1.4;
}

/* ── AREA DE CHAT PRINCIPAL ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
}

.chat-empty {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--muted); text-align: center; padding: 40px;
}
.chat-empty-icon { font-size: 2.6rem; margin-bottom: 18px; opacity: .2; }
.chat-empty h3 {
    font-family: 'DM Serif Display', serif;
    font-size: 1.6rem; font-weight: 400;
    color: rgba(255,255,255,.6);
    margin-bottom: 8px; letter-spacing: -.01em;
}
.chat-empty p { font-size: .88rem; }

/* Header conversa */
.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.chat-header-user { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.chat-header-avatar {
    width: 44px; height: 44px; border-radius: 50%; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border2);
    color: var(--muted); font-size: 1.5rem;
    flex-shrink: 0;
}
.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-name {
    font-family: 'DM Serif Display', serif;
    font-size: 1.2rem; font-weight: 400;
    color: #fff; display: block;
    line-height: 1.1; letter-spacing: -.01em;
}
.chat-header-status {
    font-size: .72rem; color: var(--muted);
    margin-top: 4px;
    display: flex; align-items: center; gap: 6px;
}
.chat-header-status:not(:empty)::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px rgba(103,232,180,.5);
}
.btn-chat-back {
    display: none;
    background: transparent; border: none; color: var(--muted);
    font-size: 1rem; cursor: pointer;
    width: 36px; height: 36px; border-radius: 50%;
    transition: all .2s;
    align-items: center; justify-content: center;
}
.btn-chat-back:hover { color: var(--text); background: rgba(255,255,255,.04); }

/* Mensagens */
.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 28px 32px 16px;
    display: flex; flex-direction: column; gap: 4px;
    background: var(--bg);
}
.chat-start {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--muted); text-align: center;
}
.chat-start i {
    font-size: 1.8rem; margin-bottom: 12px; opacity: .3;
    color: var(--accent-ink, var(--accent));
}
.chat-start p {
    font-family: 'DM Serif Display', serif;
    font-size: 1.1rem; font-style: italic;
}

.msg-date-divider {
    text-align: center;
    font-size: .68rem; color: var(--muted);
    letter-spacing: .25em; text-transform: uppercase;
    padding: 18px 0 10px;
    font-weight: 500;
}
.msg-date-divider::before { content: '— '; opacity: .6; }
.msg-date-divider::after  { content: ' —'; opacity: .6; }

.msg-bubble {
    max-width: 64%;
    padding: 11px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.5;
    margin-top: 2px;
}
.msg-outra {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border2);
    border-bottom-left-radius: 6px;
}
.msg-minha {
    align-self: flex-end;
    background: var(--accent);
    color: #0a0c12;
    border: 1px solid var(--accent);
    border-bottom-right-radius: 6px;
}
.msg-minha .msg-text { color: #0a0c12; }

/* agrupamento de bolhas consecutivas — bordas reduzem entre vizinhas */
.msg-bubble + .msg-bubble.msg-outra { border-top-left-radius: 6px; }
.msg-outra + .msg-bubble.msg-outra:not(:last-child) { border-bottom-left-radius: 6px; }
.msg-bubble + .msg-bubble.msg-minha { border-top-right-radius: 6px; }
.msg-minha + .msg-bubble.msg-minha:not(:last-child) { border-bottom-right-radius: 6px; }

.msg-text { font-size: .9rem; line-height: 1.5; margin: 0; color: var(--text); }
.msg-time {
    display: block; text-align: right;
    font-size: .62rem; color: var(--muted);
    margin-top: 4px;
    letter-spacing: .04em;
    font-variant-numeric: tabular-nums;
}
.msg-minha .msg-time { color: rgba(10,12,18,.55); }

/* Input area — pill com tools internas */
.chat-input-area {
    display: flex; flex-direction: column;
    padding: 16px 32px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.chat-input-row {
    display: flex; align-items: flex-end; gap: 12px;
}
.chat-input-area textarea {
    flex: 1; resize: none;
    padding: 12px 18px;
    background: rgba(255,255,255,.03);
    border: 1px solid var(--border2);
    border-radius: 22px;
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: .9rem;
    line-height: 1.4;
    outline: none;
    max-height: 120px;
    transition: border-color .15s, background .15s;
}
.chat-input-area textarea:focus {
    border-color: rgba(200,168,75,.4);
    background: rgba(255,255,255,.05);
}
.chat-input-area textarea::placeholder { color: var(--muted); }

.btn-send {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #0a0c12;
    border: none;
    cursor: pointer;
    font-size: .9rem;
    display: flex; align-items: center; justify-content: center;
    transition: all .2s;
    flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--accent2); transform: scale(1.05); }
.btn-send:disabled { opacity: .3; cursor: not-allowed; }

.input-hint {
    margin-top: 10px;
    text-align: center;
    font-size: .68rem; color: var(--muted);
    letter-spacing: .04em;
}
.input-hint kbd {
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border2);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: inherit;
    font-size: .65rem;
    color: var(--text);
}

/* ── LOADING ── */
.loading-placeholder {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 60px 20px; color: var(--muted);
}
.spinner-sm {
    width: 26px; height: 26px;
    border: 2px solid rgba(200,168,75,.15); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ── */
.toast {
    position: fixed; bottom: 28px; right: 28px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border2); padding: 13px 22px; border-radius: var(--radius-sm);
    box-shadow: 0 8px 32px rgba(0,0,0,.5); z-index: 1000;
    opacity: 0; transform: translateY(16px); transition: all .28s;
    font-size: .88rem; font-weight: 500;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: rgba(74,222,128,.3); color: #4ade80; }
.toast.error   { border-color: rgba(248,113,113,.3); color: #f87171; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
    .chat-container { border: none; }
    .chat-sidebar {
        position: absolute; inset: 68px 0 0 0;
        width: 100%; min-width: unset; z-index: 50;
        transition: transform .25s ease;
    }
    .chat-sidebar.sidebar-hidden { transform: translateX(-100%); }
    .chat-main { width: 100%; }
    .btn-chat-back { display: flex; }
    .msg-bubble { max-width: 82%; }
    .chat-header, .chat-messages, .chat-input-area { padding-left: 18px; padding-right: 18px; }
    .input-hint { display: none; }
}

/* ── LIGHT THEME ── */
body.light-theme, html.light-theme-early body {
    --bg:        #f4f1ea;
    --surface:   #fbf9f4;
    --surface2:  rgba(255,255,255,0.7);
    --border:    rgba(0,0,0,0.07);
    --border2:   rgba(0,0,0,0.12);
    --text:      #1c1a16;
    --muted:     #6b6960;
}
body.light-theme .conversa-nome,
html.light-theme-early body .conversa-nome,
body.light-theme .chat-header-name,
html.light-theme-early body .chat-header-name,
body.light-theme .sidebar-header h2,
html.light-theme-early body .sidebar-header h2 {
    color: #1c1a16;
}
body.light-theme .msg-outra,
html.light-theme-early body .msg-outra {
    background: #fff;
    border-color: rgba(0,0,0,.08);
}
body.light-theme .msg-text,
html.light-theme-early body .msg-text { color: #1c1a16; }
body.light-theme .msg-minha .msg-text,
html.light-theme-early body .msg-minha .msg-text { color: #0a0c12; }
body.light-theme .chat-input-area textarea,
html.light-theme-early body .chat-input-area textarea {
    background: #fff;
}
body.light-theme .input-hint kbd,
html.light-theme-early body .input-hint kbd {
    background: #fff;
}


/* Tema claro: navegação, busca e mensagens usam o mesmo contraste. */
:is(html.light-theme-early body, body.light-theme) {
    color-scheme: light;
    --bg: #f4f1ea;
    --surface: #fff;
    --surface2: #ece9e2;
    --text: #1e293b;
    --muted: #526070;
    --border: rgba(30,41,59,.14);
    --border2: rgba(30,41,59,.22);
    --green: #047857;
}
:is(html.light-theme-early, body.light-theme) :is(.conversa-item:hover, .btn-chat-back:hover, .search-user-avatar, .conversa-avatar, .chat-header-avatar, .input-hint kbd) { background: var(--surface2); }
:is(html.light-theme-early, body.light-theme) .conversa-item.active { background: rgba(200,168,75,.15); }
:is(html.light-theme-early, body.light-theme) .conversa-time { color: var(--muted); }
:is(html.light-theme-early, body.light-theme) .chat-input-area textarea { color: var(--text); border-color: var(--border2); }
:is(html.light-theme-early, body.light-theme) .chat-input-area textarea::placeholder { color: var(--muted); }
:is(html.light-theme-early, body.light-theme) .toast.success { color: #047857; }
:is(html.light-theme-early, body.light-theme) .toast.error { color: #b42318; }
:is(html.light-theme-early, body.light-theme) .chat-empty h3 { color: var(--text); }
:is(html.light-theme-early, body.light-theme) .sidebar-eyebrow { color: #806117; }
:is(html.light-theme-early, body.light-theme) .msg-minha .msg-time { color: #3b3120; }
