* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0b141a; --panel: #111b21; --panel-2: #202c33; --panel-3: #2a3942;
  --hover: #202c33; --active: #2a3942; --green: #00a884; --green-d: #005c4b;
  --bubble-in: #202c33; --bubble-out: #005c4b; --text: #e9edef; --text-2: #8696a0;
  --divider: #222d34; --tick: #53bdeb;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", system-ui, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; font-size: 15px;
}
.hidden { display: none !important; }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--panel-3); flex-shrink: 0; }
.icon-btn { background: none; border: none; color: var(--text-2); font-size: 19px; cursor: pointer; padding: 7px 10px; border-radius: 8px; line-height: 1; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--panel-3); color: var(--text); }

/* ---------- LAYOUT ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 32%; min-width: 330px; max-width: 480px; background: var(--panel); border-right: 1px solid var(--divider); display: flex; flex-direction: column; }
.side-header { height: 60px; background: var(--panel-2); padding: 0 12px 0 16px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.me { display: flex; align-items: center; gap: 12px; min-width: 0; }
.me-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.me-info span:first-child { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: 12px; color: var(--text-2); }
.me-status.on { color: var(--green); } .me-status.off { color: #f15c6d; }
.side-actions { display: flex; gap: 2px; }

.conn-banner { background: #182b2f; color: #8fd0c4; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; font-size: 13px; border-bottom: 1px solid var(--divider); }
.conn-banner button { background: var(--green); color: #04231c; border: none; padding: 7px 16px; border-radius: 18px; font-weight: 600; cursor: pointer; }

.search-bar { padding: 7px 12px; background: var(--panel); display: flex; align-items: center; position: relative; }
.search-bar .search-ico { position: absolute; left: 26px; font-size: 13px; opacity: .6; }
.search-bar input { width: 100%; background: var(--panel-2); border: none; color: var(--text); padding: 9px 14px 9px 40px; border-radius: 8px; font-size: 14px; outline: none; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item { display: flex; align-items: center; gap: 14px; padding: 10px 14px; cursor: pointer; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item .ci-body { flex: 1; min-width: 0; border-top: 1px solid var(--divider); padding: 10px 0; margin-top: -10px; }
.chat-item:first-child .ci-body, .chat-item:hover .ci-body, .chat-item.active .ci-body { border-color: transparent; }
.ci-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ci-name { font-size: 16px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.ci-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; gap: 8px; }
.ci-preview { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ci-badge { background: var(--green); color: #04231c; font-size: 11.5px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; display: flex; align-items: center; justify-content: center; }

/* ---------- CONVERSATION ---------- */
.conversation { flex: 1; display: flex; flex-direction: column; background: var(--bg); }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 16px; border-bottom: 6px solid var(--green); padding: 20px; }
.empty-state h2 { font-weight: 300; font-size: 30px; }
.empty-state p { color: var(--text-2); font-size: 14px; line-height: 1.6; }

.chat-view { flex: 1; display: flex; flex-direction: column; height: 100%; }
.conv-header { height: 60px; background: var(--panel-2); padding: 0 16px; display: flex; align-items: center; gap: 13px; flex-shrink: 0; }
.back-btn { display: none; font-size: 26px; padding: 4px 8px; }
.conv-info { display: flex; flex-direction: column; line-height: 1.3; flex: 1; min-width: 0; }
.conv-info span:first-child { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub { font-size: 12px; color: var(--text-2); }
.conv-actions { position: relative; }
#export-btn { font-size: 14px; white-space: nowrap; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 42px; background: var(--panel-2); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.5); overflow: hidden; z-index: 20; min-width: 190px; }
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 13px 18px; font-size: 14px; cursor: pointer; }
.menu-pop button:hover { background: var(--panel-3); }

.messages { flex: 1; overflow-y: auto; padding: 16px 7%; display: flex; flex-direction: column; gap: 2px;
  background-color: #0b141a;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Crect width='60' height='60' fill='%230b141a'/%3E%3Ccircle cx='30' cy='30' r='1.2' fill='%23172530'/%3E%3C/svg%3E"); }
.msg-row { display: flex; max-width: 100%; margin-top: 2px; }
.msg-row.out { justify-content: flex-end; }
.bubble { max-width: 65%; padding: 6px 9px 8px; border-radius: 8px; font-size: 14.2px; line-height: 1.38; position: relative; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; box-shadow: 0 1px .5px rgba(0,0,0,.25); }
.msg-row.in .bubble { background: var(--bubble-in); border-top-left-radius: 2px; }
.msg-row.out .bubble { background: var(--bubble-out); border-top-right-radius: 2px; }
.b-sender { font-size: 12.8px; font-weight: 600; color: #06cf9c; margin-bottom: 2px; }
.b-meta { font-size: 11px; color: var(--text-2); float: right; margin: 6px 0 -3px 12px; user-select: none; }
.b-tick { color: var(--tick); font-size: 11px; margin-left: 2px; }
.b-media { max-width: 330px; width: 100%; border-radius: 6px; margin-bottom: 3px; display: block; cursor: pointer; }
.bubble audio { width: 280px; max-width: 62vw; margin: 3px 0; height: 40px; }
.b-trans { font-size: 13px; color: #cfe9e2; background: rgba(0,0,0,.18); border-left: 2px solid var(--green); padding: 5px 8px; border-radius: 4px; margin-top: 4px; font-style: italic; }
.b-trans.pending { color: var(--text-2); border-color: var(--text-2); }
.b-file { color: var(--tick); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,.18); padding: 9px 12px; border-radius: 6px; margin-bottom: 3px; }
.b-loading { color: var(--text-2); font-style: italic; font-size: 13px; }
.day-sep { align-self: center; background: var(--panel-2); color: var(--text-2); font-size: 12px; padding: 5px 12px; border-radius: 7px; margin: 12px 0 6px; box-shadow: 0 1px .5px rgba(0,0,0,.2); }

.empty-msgs { margin: auto; text-align: center; max-width: 420px; color: var(--text-2); padding: 24px; }
.empty-msgs .em-ico { font-size: 46px; margin-bottom: 8px; }
.empty-msgs p { margin: 6px 0; font-size: 15px; color: var(--text); }
.empty-msgs .hint { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.sync-btn { margin-top: 16px; background: var(--green); color: #04231c; border: none; padding: 10px 22px; border-radius: 20px; font-weight: 600; cursor: pointer; font-size: 14px; }
.sync-btn:hover { background: #06cf9c; }
.sync-note { margin-top: 12px; font-size: 13px; color: var(--text-2); min-height: 16px; }

.composer { background: var(--panel-2); padding: 8px 16px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.composer input { flex: 1; background: var(--panel-3); border: none; color: var(--text); padding: 11px 16px; border-radius: 8px; font-size: 15px; outline: none; }
.send-btn { background: none; border: none; color: var(--text-2); cursor: pointer; width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.send-btn:hover { color: var(--green); }

/* ---------- QR ---------- */
.qr-modal { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; z-index: 50; }
.qr-card { background: var(--panel); border-radius: 14px; padding: 30px; width: 380px; max-width: 92vw; text-align: center; }
.qr-card h3 { margin-bottom: 10px; }
.qr-card p { font-size: 13px; color: var(--text-2); margin-bottom: 18px; line-height: 1.6; }
#qr-img { width: 264px; height: 264px; background: #fff; border-radius: 10px; object-fit: contain; }
.qr-status { margin: 16px 0; font-size: 13px; color: var(--text-2); }
#qr-close { background: var(--panel-3); color: var(--text); border: none; padding: 10px 22px; border-radius: 8px; cursor: pointer; }

::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-thumb { background: #3a474e; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 760px) {
  .sidebar { width: 100%; max-width: none; min-width: 0; }
  .conversation { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .conversation { display: flex; }
  .back-btn { display: block !important; }
  .bubble { max-width: 82%; }
}
