:root {
    --bg:          #EEECEA;
    --surface:     #FFFFFF;
    --surface-2:   #F8F7F4;
    --border:      #E6E3DC;
    --border-mid:  #D2CFC7;
    --border-dark: #B2AFA6;
    --text-1:      #15130E;
    --text-2:      #504D47;
    --text-3:      #98958E;
    --accent:      #15130E;
    --accent-fg:   #FFFFFF;
    --danger:      #C0392B;
    --success:     #19793E;
    --panel-bg:    #15130E;
    --wa-green:    #25D366;
    --wa-green-dk: #128C7E;
    --font:        'Geist', system-ui, sans-serif;
    --font-mono:   'Geist Mono', monospace;
    --radius:      7px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --t:           0.16s ease;

    --sidebar-w:   264px;
    --list-w:      340px;
}

*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html { height:100%; font-size:16px; }
body {
    height:100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-1);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

/* ══════════════ APP SHELL ══════════════ */
.app { height:100vh; min-height:100dvh; display:flex; }

/* ══════════════ SIDEBAR ══════════════ */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.sidebar::before {
    content:'';
    position:absolute; inset:0;
    background-image:
        linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
    background-size: 36px 36px;
    pointer-events: none;
}

.sidebar-top {
    position: relative; z-index: 1;
    padding: 26px 0;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: auto;
}

.sidebar-logo {
    height: 24px;
    width: auto;
    filter: brightness(0) invert(1);
    opacity: 0.92;
    display: block;
    margin-bottom: 16px;
}

/* ── Avaliações (rating) ── */
.sidebar-rating {
    margin-top: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 90%;
    padding: 5px 14px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
}

.rating-stars {
    display: flex;
    gap: 3px;
    color: #F4F4F4;
    font-size: 11px;
}

.rating-score { display:flex; align-items:center; gap:4px; }
.rating-score strong { font-size: 15px; line-height: 1; color: #FFF; }
.rating-score span { font-size: 11px; color: rgba(255,255,255,0.5); }

.rating-content small {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: rgba(255,255,255,0.45);
}

.sidebar-nav {
    position: relative; z-index: 1;
    flex: 1;
    overflow-y: auto;
    padding: 18px 14px 14px;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; }

.nav-section { margin-bottom: 20px; }
.nav-section-label {
    display: block;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.13em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
    padding: 0 10px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.56);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--t), color var(--t);
    margin-bottom: 2px;
    touch-action: manipulation;
}

.nav-item i { font-size: 17px; width: 18px; text-align:center; flex-shrink:0; }

.nav-item:hover { background: rgba(255,255,255,0.055); color: rgba(255,255,255,0.85); }

.nav-item.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.nav-badge {
    margin-left: auto;
    font-size: 10.5px;
    font-weight: 600;
    color: #0b1f13;
    background: var(--wa-green);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 99px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.sidebar-footer {
    position: relative; z-index: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border-top: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: #fff;
    display: flex; align-items:center; justify-content:center;
    font-size: 12px; font-weight: 600;
    flex-shrink: 0;
}

.user-info { flex:1; min-width:0; line-height:1.3; }
.user-info strong { display:block; font-size:12.5px; font-weight:600; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-info span { font-size:11px; color: rgba(255,255,255,0.35); }

.logout-btn {
    width: 30px; height: 30px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.4);
    display:flex; align-items:center; justify-content:center;
    cursor: pointer;
    font-size: 15px;
    flex-shrink: 0;
    transition: background var(--t), color var(--t);
}
.logout-btn:hover { background: rgba(255,255,255,0.08); color:#fff; }

/* ══════════════ MAIN CONTENT ══════════════ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
}

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 26px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.content-header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-1);
    white-space: nowrap;
}

.header-actions { display:flex; align-items:center; gap:10px; }

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box i {
    position: absolute; left: 12px;
    font-size: 14px; color: var(--border-dark);
}
.search-box input {
    width: 230px;
    height: 38px;
    padding: 0 12px 0 34px;
    font-family: var(--font);
    font-size: 13px;
    color: var(--text-1);
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color var(--t), background var(--t);
}
.search-box input:focus { border-color: var(--text-1); background: var(--surface); }
.search-box input::placeholder { color: var(--border-dark); }

.btn-primary {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-fg);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--t), transform var(--t);
    touch-action: manipulation;
}
.btn-primary i { font-size: 15px; }
.btn-primary:hover { background: #000; }
.btn-primary:active { transform: scale(0.97); }

/* ══════════════ CONTENT BODY (Conversas) ══════════════ */
.content-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ── Lista de conversas ── */
.conversation-list {
    width: var(--list-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    background: var(--surface);
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--t);
    position: relative;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); }
.conv-item.active::before {
    content:'';
    position:absolute; left:0; top:0; bottom:0; width:3px;
    background: var(--text-1);
}

.conv-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--panel-bg);
    color: #fff;
    display:flex; align-items:center; justify-content:center;
    font-size: 13px; font-weight: 600;
    flex-shrink: 0;
}

.conv-body { flex:1; min-width:0; }
.conv-top-row { display:flex; align-items:baseline; justify-content:space-between; gap:8px; margin-bottom:2px; }
.conv-name { font-size: 13.5px; font-weight: 600; color: var(--text-1); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.conv-time { font-size: 10.5px; color: var(--text-3); flex-shrink:0; }
.conv-preview-row { display:flex; align-items:center; gap:6px; }
.conv-preview { font-size: 12px; color: var(--text-3); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; flex:1; }
.conv-preview i { font-size: 13px; color: var(--wa-green-dk); margin-right:2px; }

.conv-unread {
    min-width: 18px; height: 18px;
    padding: 0 5px;
    border-radius: 99px;
    background: var(--wa-green);
    color: #0b1f13;
    font-size: 10.5px;
    font-weight: 700;
    display:flex; align-items:center; justify-content:center;
    flex-shrink: 0;
}

/* ── Janela de chat ── */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background:
        radial-gradient(circle at 1px 1px, rgba(0,0,0,0.035) 1px, transparent 0) 0 0/22px 22px,
        var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-back {
    display: none;
    width: 32px; height: 32px;
    border: none; background: transparent;
    color: var(--text-2);
    font-size: 17px;
    align-items:center; justify-content:center;
    cursor: pointer;
    border-radius: 8px;
    flex-shrink: 0;
}
.chat-back:hover { background: var(--surface-2); }

.chat-avatar-wrap { position: relative; flex-shrink:0; }
.chat-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--panel-bg);
    color: #fff;
    display:flex; align-items:center; justify-content:center;
    font-size: 12.5px; font-weight: 600;
}
.online-dot {
    position: absolute; right: -1px; bottom: -1px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--wa-green);
    border: 2px solid var(--surface);
}

.chat-id { flex: 1; min-width: 0; }
.chat-id strong { display:block; font-size: 13.5px; font-weight: 600; color: var(--text-1); }
.chat-id span { font-size: 11.5px; color: var(--text-3); }

.chat-actions { display:flex; align-items:center; gap:4px; }
.icon-btn {
    width: 34px; height: 34px;
    border: none; background: transparent;
    color: var(--text-3);
    font-size: 17px;
    display:flex; align-items:center; justify-content:center;
    cursor: pointer;
    border-radius: 8px;
    transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-1); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 26px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.msg-date-sep {
    align-self: center;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-3);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 99px;
    margin: 8px 0 14px;
}

.bubble-row { display:flex; margin-bottom: 9px; }
.bubble-row.out { justify-content: flex-end; }

.bubble {
    max-width: 62%;
    padding: 9px 13px 8px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    line-height: 1.5;
    position: relative;
}
.bubble-row.in .bubble {
    background: var(--surface);
    color: var(--text-1);
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.bubble-row.out .bubble {
    background: var(--accent);
    color: var(--accent-fg);
    border-bottom-right-radius: 3px;
}

.bubble-meta {
    display: flex; align-items:center; gap:4px;
    justify-content: flex-end;
    margin-top: 3px;
    font-size: 10px;
}
.bubble-row.in .bubble-meta { color: var(--text-3); }
.bubble-row.out .bubble-meta { color: rgba(255,255,255,0.55); }
.bubble-meta .ph-checks { color: var(--wa-green); font-size: 13px; }

.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input-bar input {
    flex: 1;
    height: 42px;
    padding: 0 14px;
    font-family: var(--font);
    font-size: 13.5px;
    color: var(--text-1);
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color var(--t), background var(--t);
}
.chat-input-bar input:focus { border-color: var(--text-1); background: var(--surface); }
.chat-input-bar input::placeholder { color: var(--border-dark); }

.send-btn {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    display:flex; align-items:center; justify-content:center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--t), transform var(--t);
}
.send-btn:hover { background: #000; }
.send-btn:active { transform: scale(0.94); }

/* ══════════════ MOBILE FAB + DRAWER ══════════════ */
.mobile-fab {
    display: none;
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 54px; height: 54px;
    border-radius: 50%;
    border: none;
    background: var(--panel-bg);
    color: #fff;
    font-size: 21px;
    align-items:center; justify-content:center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,0.28);
    z-index: 60;
    touch-action: manipulation;
}

.mobile-overlay {
    display:none;
    position: fixed; inset:0;
    background: rgba(0,0,0,0.4);
    z-index: 50;
    opacity: 0;
    transition: opacity var(--t);
}
.mobile-overlay.vis { display:block; opacity:1; }

/* ══════════════ RESPONSIVE ══════════════ */
@media (max-width: 980px) {
    :root { --list-w: 300px; }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top:0; bottom:0; left:0;
        z-index: 55;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 0 0 30px rgba(0,0,0,0.3);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-fab { display:flex; }

    .search-box input { width: 160px; }
}

@media (max-width: 720px) {
    :root { --list-w: 100%; }

    .content-body { position: relative; overflow: hidden; }

    .conversation-list {
        width: 100%;
        border-right: none;
        position: absolute; inset: 0;
        z-index: 2;
        transition: transform 0.2s ease;
    }
    .chat-window {
        position: absolute; inset: 0;
        transform: translateX(100%);
        transition: transform 0.2s ease;
    }

    .content-body.chat-open .conversation-list { transform: translateX(-100%); }
    .content-body.chat-open .chat-window { transform: translateX(0); }

    .chat-back { display: flex; }

    .content-header h1 { display:none; }
    .search-box input { width: 100%; }
    .header-actions { flex:1; }
    .btn-primary span { display:none; }
    .btn-primary { width: 42px; height:42px; padding:0; justify-content:center; border-radius: 50%; }
    .btn-primary i { font-size: 17px; }

    .bubble { max-width: 78%; }
}