:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --panel-3: #2a3942;
  --accent: #00a884;
  --accent-2: #25d366;
  --text: #e9edef;
  --text-muted: #8696a0;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --danger: #f15c6d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }

/* ===== Auth ===== */
.auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0b141a, #111b21);
  padding: 20px;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--panel-3);
  border-radius: 16px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-logo { font-size: 56px; }
.auth-card h1 { margin-top: 8px; font-size: 26px; }
.auth-sub { color: var(--text-muted); font-size: 14px; margin: 8px 0 22px; }
.auth-tabs { display: flex; background: var(--panel-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.auth-tab { flex: 1; padding: 10px; border: none; background: transparent; color: var(--text-muted); border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; }
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  background: var(--panel-2);
  border: 1px solid var(--panel-3);
  color: var(--text);
  padding: 13px 14px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-error { color: var(--danger); font-size: 13px; min-height: 16px; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 13px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: #06997a; }

/* ===== App layout ===== */
.app { display: flex; height: 100%; }
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 17px;
  flex-shrink: 0;
  background: #6b7c85;
}
.avatar.large { width: 110px; height: 110px; font-size: 44px; }
.icon-btn {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; padding: 8px; border-radius: 50%;
  line-height: 1;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }

/* ===== Sidebar ===== */
.sidebar {
  width: 360px;
  background: var(--panel);
  border-right: 1px solid var(--panel-3);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--panel-2);
}
.me { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.search-box { padding: 8px 12px; }
.search-box input {
  width: 100%; background: var(--panel-2); border: none; color: var(--text);
  padding: 10px 14px; border-radius: 8px; outline: none; font-size: 14px;
}
.contacts { flex: 1; overflow-y: auto; }
.contact {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.04);
}
.contact:hover { background: var(--panel-2); }
.contact.active { background: var(--panel-3); }
.contact .c-main { flex: 1; min-width: 0; }
.contact .c-name { font-weight: 600; display: flex; justify-content: space-between; }
.contact .c-preview { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); }
.dot.online { background: var(--accent-2); }
.badge { background: var(--accent-2); color: #04231b; border-radius: 12px; font-size: 11px; font-weight: 700; padding: 1px 7px; }

/* ===== Chat area ===== */
.chat-area { flex: 1; display: flex; flex-direction: column; background: #0b141a; }
.empty-chat {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 12px;
}
.empty-icon { font-size: 64px; opacity: .5; }
.chat { flex: 1; display: flex; flex-direction: column; height: 100%; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel-2);
}
.back-btn { display: none; }
.peer-info { flex: 1; display: flex; flex-direction: column; }
.peer-info small { color: var(--text-muted); font-size: 12px; }
.chat-actions { display: flex; gap: 4px; }

.messages {
  flex: 1; overflow-y: auto; padding: 20px 8%;
  display: flex; flex-direction: column; gap: 4px;
  background-image: linear-gradient(rgba(11,20,26,.94), rgba(11,20,26,.94));
}
.msg {
  max-width: 65%; padding: 7px 11px; border-radius: 10px;
  font-size: 14.5px; line-height: 1.4; position: relative; word-wrap: break-word;
}
.msg .time { font-size: 10.5px; color: rgba(233,237,239,.5); margin-left: 8px; float: right; margin-top: 4px; }
.msg.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.msg img { max-width: 260px; border-radius: 8px; display: block; cursor: pointer; }
.msg .file-att {
  display: flex; align-items: center; gap: 10px; padding: 6px;
  background: rgba(0,0,0,.2); border-radius: 8px; color: var(--text); text-decoration: none;
}
.msg .file-att .fi-icon { font-size: 26px; }
.msg .file-att small { color: var(--text-muted); }
.typing-indicator { color: var(--accent-2); font-size: 12px; }

.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--panel-2);
}
.composer input[type="text"] {
  flex: 1; background: var(--panel-3); border: none; color: var(--text);
  padding: 12px 16px; border-radius: 22px; outline: none; font-size: 15px;
}
.send-btn { color: var(--accent-2); font-size: 22px; }

/* ===== Call overlay ===== */
.call-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: #0a0a0a; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.call-remote { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-peer-info { position: absolute; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.call-peer-info.hidden { display: none; }
.call-peer-info h2 { font-size: 24px; }
.call-peer-info p { color: var(--text-muted); }
.call-local {
  position: absolute; top: 20px; right: 20px;
  width: 120px; height: 160px; object-fit: cover;
  border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: #222; z-index: 2;
}
.call-controls {
  position: absolute; bottom: 40px; display: flex; gap: 22px; z-index: 3;
}
.call-btn {
  width: 62px; height: 62px; border-radius: 50%; border: none;
  font-size: 24px; cursor: pointer; color: #fff; background: var(--panel-3);
  display: flex; align-items: center; justify-content: center;
}
.call-btn.hangup { background: var(--danger); }
.call-btn.accept { background: var(--accent-2); }
.call-btn.active { background: #fff; color: #111; }

/* ===== Incoming call ===== */
.incoming-call {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center;
}
.incoming-card {
  background: var(--panel); border-radius: 20px; padding: 40px;
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.incoming-actions { display: flex; gap: 40px; margin-top: 10px; }

/* ===== Responsive (mobile) ===== */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat-area { display: none; }
  .back-btn { display: inline-block; }
  .messages { padding: 16px 12px; }
  .msg { max-width: 80%; }
}
