:root {
  --bg-app: #0b141a;
  --bg-sidebar: #111b21;
  --bg-header: #202c33;
  --bg-panel: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --text-main: #e9edef;
  --text-muted: #8696a0;
  --accent: #00a884;
  --border: #222d34;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* --- Login --- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #14232b, #0b141a 60%);
}
.login-card {
  background: var(--bg-header);
  padding: 40px;
  border-radius: 12px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .subtitle { margin: 0 0 12px; color: var(--text-muted); font-size: 13px; }
.login-card input {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #2a3942;
  color: var(--text-main);
  font-size: 14px;
}
.login-card button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #05221c;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.login-card button:hover { filter: brightness(1.05); }
.login-error { color: #ff6b6b; font-size: 13px; min-height: 16px; margin: 0; }

/* --- App layout --- */
.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-header);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7b85; display: inline-block; }
.dot.online { background: var(--accent); }
.icon-btn {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 6px;
}
.icon-btn:hover { color: var(--text-main); }

.search-box { padding: 8px 12px; }
.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: none;
  background: #202c33;
  color: var(--text-main);
  font-size: 14px;
}

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.chat-item:hover { background: #202c33; }
.chat-item.active { background: #2a3942; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: #6b7b85; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #0b141a; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-meta { flex: 1; min-width: 0; }
.chat-meta-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.chat-time { font-size: 11px; color: var(--text-muted); }
.chat-preview { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.chat-last { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.unread-badge {
  background: var(--accent); color: #05221c; font-size: 11px; font-weight: 700;
  border-radius: 999px; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

/* --- Panel --- */
.panel { position: relative; background: var(--bg-panel); display: flex; flex-direction: column; }
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }

.conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conv-header {
  background: var(--bg-header);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.conv-title { display: flex; flex-direction: column; }
.conv-jid { font-size: 12px; color: var(--text-muted); }
.viewer-badge {
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 6%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-image: radial-gradient(rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 18px 18px;
}

.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 65%;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,0.3);
}
.bubble-row.in .bubble { background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble-row.out .bubble { background: var(--bubble-out); border-top-right-radius: 2px; }
.bubble .sender { font-size: 12px; font-weight: 600; color: #8fd6c4; margin-bottom: 2px; display: block; }
.bubble .text { white-space: pre-wrap; word-break: break-word; }
.bubble .meta { display: block; text-align: right; font-size: 10px; color: var(--text-muted); margin-top: 3px; }
.bubble .media-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.06); padding: 6px 10px; border-radius: 6px;
  cursor: pointer; font-size: 13px;
}
.bubble .media-tag:hover { background: rgba(255,255,255,0.1); }
.bubble img.loaded-media { max-width: 260px; border-radius: 6px; display: block; margin-top: 4px; }
.bubble audio.loaded-media { margin-top: 4px; width: 240px; }

.day-divider {
  align-self: center;
  background: #182229;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  margin: 10px 0;
}
