:root {
    --bg: #111b21;
    --bg-sidebar: #202c33;
    --bg-card: #202c33;
    --bg-bubble-mine: #005c4b;
    --bg-bubble-theirs: #202c33;
    --bg-input: #2a3942;
    --border: #313d45;
    --text: #e9edef;
    --text-muted: #8696a0;
    --primary: #00a884;
    --primary-dim: #005c4b;
    --danger: #f15c6d;
    --unread: #00a884;
    --radius: 8px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: "Inter", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

#app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 360px; flex-shrink: 0; background: var(--bg-sidebar); border-right: 1px solid var(--border);
           display: flex; flex-direction: column; }
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); position: relative; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh;
                background: var(--bg); }
.login-card { background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 14px;
              padding: 2rem 2.5rem; width: 380px; display: flex; flex-direction: column; gap: 1rem;
              text-align: center; }
.login-logo { font-size: 3rem; }
.login-card h1 { font-size: 1.5rem; font-weight: 600; color: var(--primary); }
.login-card input { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
                    padding: 0.75rem 1rem; color: var(--text); font-size: 0.9rem; outline: none; }
.login-card input:focus { border-color: var(--primary); }
.login-card button { background: var(--primary); color: #111; font-weight: 700; border: none;
                     border-radius: var(--radius); padding: 0.8rem; font-size: 1rem; cursor: pointer; }

/* Sidebar header */
.sidebar-header { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem;
                  background: var(--bg-card); border-bottom: 1px solid var(--border); }
.my-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-dim);
             display: flex; align-items: center; justify-content: center; font-weight: 700;
             font-size: 1rem; color: var(--primary); flex-shrink: 0; }
.my-info { flex: 1; display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; font-weight: 500; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.online  { background: var(--primary); box-shadow: 0 0 5px var(--primary); }
.status-dot.offline { background: var(--text-muted); }

/* Langue */
.lang-selector { display: flex; align-items: center; gap: 0.4rem; }
.lang-selector select { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px;
                         padding: 0.3rem 0.5rem; color: var(--text); font-size: 0.8rem; cursor: pointer; outline: none; }
.lang-selector select:focus { border-color: var(--primary); }
.lang-status-dot { width: 8px; height: 8px; border-radius: 50%; transition: all 0.3s; }
.lang-status-dot.synced  { background: var(--primary); }
.lang-status-dot.syncing { background: #f59e0b; animation: pulse 1s ease-in-out infinite; }
.lang-status-dot.pending { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Search */
.search-bar { padding: 0.5rem 0.75rem; background: var(--bg-sidebar); border-bottom: 1px solid var(--border); }
.search-bar input { width: 100%; background: var(--bg-input); border: none; border-radius: 8px;
                    padding: 0.5rem 0.75rem; color: var(--text); font-size: 0.875rem; outline: none; }

/* Conversations */
.conv-list { flex: 1; overflow-y: auto; }
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.conv-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem;
             cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.03); transition: background 0.1s; }
.conv-item:hover { background: rgba(255,255,255,0.04); }
.conv-item.active { background: rgba(0,168,132,0.08); border-left: 3px solid var(--primary); }
.conv-avatar { width: 46px; height: 46px; border-radius: 50%; background: #2a3942;
               display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
               font-weight: 600; color: var(--text-muted); flex-shrink: 0; }
.group-avatar { background: #1a2d36; border: 2px dashed var(--border); }
.conv-info { flex: 1; min-width: 0; }
.conv-name-row { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-weight: 500; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 0.72rem; color: var(--text-muted); flex-shrink: 0; margin-left: 0.5rem; }
.conv-preview-row { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.conv-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap;
                overflow: hidden; text-overflow: ellipsis; flex: 1; }
.unread-badge { background: var(--unread); color: #111; border-radius: 99px; font-size: 0.7rem;
                font-weight: 700; padding: 1px 6px; margin-left: 0.5rem; flex-shrink: 0; }
.conv-placeholder { color: var(--text-muted); text-align: center; padding: 2rem; font-size: 0.875rem; }
.sidebar-footer { padding: 0.75rem 1rem; display: flex; justify-content: space-between;
                  border-top: 1px solid var(--border); }
.btn-icon { background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 0.4rem;
            border-radius: 50%; color: var(--text-muted); transition: background 0.15s; }
.btn-icon:hover { background: rgba(255,255,255,0.08); }

/* Chat header */
.chat-header { display: flex; align-items: center; justify-content: space-between;
               padding: 0.6rem 1rem; background: var(--bg-card); border-bottom: 1px solid var(--border); }
.chat-peer-info { display: flex; align-items: center; gap: 0.75rem; }
.peer-avatar { width: 38px; height: 38px; border-radius: 50%; background: #2a3942;
               display: flex; align-items: center; justify-content: center; font-weight: 600;
               color: var(--text-muted); }
.peer-name { font-weight: 600; font-size: 0.9rem; }
.peer-status { font-size: 0.75rem; color: var(--text-muted); }
.translation-badge { font-size: 0.75rem; color: var(--primary); background: rgba(0,168,132,0.12);
                      border-radius: 99px; padding: 0.25rem 0.65rem; }

/* Messages */
.messages-container { flex: 1; overflow-y: auto; padding: 1rem 1.5rem; display: flex;
                      flex-direction: column; gap: 0.35rem; }
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.chat-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center;
                    height: 100%; color: var(--text-muted); gap: 0.75rem; }
.placeholder-icon { font-size: 3rem; opacity: 0.5; }
.loading-messages { text-align: center; color: var(--text-muted); padding: 2rem; }

/* Bulles */
.bubble { max-width: 65%; padding: 0.5rem 0.75rem; border-radius: 7.5px; position: relative;
           word-break: break-word; line-height: 1.4; font-size: 0.9rem; }
.bubble.mine   { align-self: flex-end; background: var(--bg-bubble-mine); border-bottom-right-radius: 2px; }
.bubble.theirs { align-self: flex-start; background: var(--bg-bubble-theirs); border-bottom-left-radius: 2px; }
.bubble-text { color: var(--text); }
.bubble-translation { font-size: 0.8rem; color: var(--primary); margin-top: 0.25rem;
                       padding-top: 0.25rem; border-top: 1px solid rgba(0,168,132,0.3); font-style: italic; }
.bubble-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.bubble-time { font-size: 0.68rem; color: var(--text-muted); }
.bubble-status { font-size: 0.7rem; color: var(--text-muted); }
.bubble-translated-tag { font-size: 0.7rem; }

/* Input */
.input-area { padding: 0.5rem 1rem 0.75rem; background: var(--bg-card); border-top: 1px solid var(--border); }
.typing-indicator { font-size: 0.78rem; color: var(--primary); padding: 0.25rem 0.5rem; font-style: italic; }
.input-row { display: flex; align-items: flex-end; gap: 0.5rem; }
.input-row textarea { flex: 1; background: var(--bg-input); border: none; border-radius: 10px;
                      padding: 0.65rem 1rem; color: var(--text); font-size: 0.9rem; outline: none;
                      resize: none; max-height: 150px; font-family: inherit; line-height: 1.4; }
.send-btn { width: 40px; height: 40px; background: var(--primary); border: none; border-radius: 50%;
            color: #111; font-size: 1rem; cursor: pointer; display: flex; align-items: center;
            justify-content: center; flex-shrink: 0; transition: background 0.15s; }
.send-btn:hover { background: #008f6f; }

/* Side panel */
.side-panel { position: absolute; top: 0; right: 0; bottom: 0; width: 320px; background: var(--bg-sidebar);
              border-left: 1px solid var(--border); z-index: 20; display: flex; flex-direction: column; }
.side-panel.hidden { display: none; }
.panel-header { display: flex; align-items: center; justify-content: space-between;
                padding: 1rem; border-bottom: 1px solid var(--border); }
.panel-header h3 { font-size: 1rem; }
.panel-header button { background: none; border: none; color: var(--text-muted); font-size: 1.1rem;
                       cursor: pointer; padding: 0.25rem; }
#nc-search { margin: 0.75rem; background: var(--bg-input); border: none; border-radius: 8px;
             padding: 0.5rem 0.75rem; color: var(--text); font-size: 0.875rem; outline: none; display: block; width: calc(100% - 1.5rem); }
.nc-result { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem;
             cursor: pointer; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.nc-result:hover { background: rgba(255,255,255,0.04); }

/* Reconnect banner */
.reconnect-banner { position: fixed; top: 0; left: 0; right: 0; background: #f59e0b; color: #111;
                    text-align: center; padding: 0.4rem; font-size: 0.85rem; font-weight: 600; z-index: 100; }
.reconnect-banner.hidden { display: none; }

/* Misc */
.error  { color: var(--danger); font-size: 0.8rem; }
.hidden { display: none !important; }
.muted  { color: var(--text-muted); font-size: 0.8rem; }
/* Reply preview */
.reply-preview { display:flex; align-items:center; gap:0.4rem; margin-bottom:0.3rem; opacity:0.7;
                cursor:pointer; font-size:0.8rem; }
.reply-line { width:3px; height:18px; background:var(--primary); border-radius:2px; flex-shrink:0; }
.reply-text { color:var(--text-muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.reply-bar { padding:0.5rem 1rem; background:var(--bg-card); border-top:1px solid var(--primary);
             display:flex; justify-content:space-between; align-items:center; }
.reply-label { font-size:0.75rem; color:var(--primary); font-weight:600; }
.reply-preview-text { font-size:0.8rem; color:var(--text-muted); }
#location-panel { display:flex; flex-direction:column; }
.location-item:hover { background:rgba(255,255,255,0.03); }
.location-bubble { max-width:250px; }
.location-bubble iframe { border-radius:8px; }
#btn-location.active { color: var(--primary); }
.bubble-sender { font-size:0.75rem; color:var(--primary); margin-bottom:2px; font-weight:600; }

/* ── Mobile responsive ── */
@media (max-width: 768px) {
    .app-layout { position: relative; overflow: hidden; }
    .sidebar { width: 100%; position: absolute; top: 0; left: 0; height: 100%; z-index: 10; transition: transform 0.2s; }
    .sidebar.hidden { transform: translateX(-100%); }
    .chat-panel { width: 100%; display: flex; flex-direction: column; height: 100%; }
    .chat-panel .btn-back { display: flex !important; }
    .app-layout { height: 100vh; }
}

@media (max-width: 768px) and (orientation: portrait) {
    .app-layout { flex-direction: column; height: 100dvh; }
    .chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
    .messages-container { flex: 1; overflow-y: auto; min-height: 0; }
    .input-area { flex-shrink: 0; }
    .sidebar { height: 100dvh; }
}

@media (max-width: 768px) {
    #app { position: relative; overflow: hidden; height: 100dvh; }
    .sidebar { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; transition: transform 0.25s ease; }
    .sidebar.hidden { transform: translateX(-100%); }
    #chat-header, #messages-container, #input-area { display: flex; flex-direction: column; }
    #messages-container { flex: 1; min-height: 0; overflow-y: auto; }
    #input-area { flex-shrink: 0 !important; display: flex !important; }
}
