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

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

a { color: var(--accent-2); }

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at top, #142229 0%, #0b141a 70%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border-radius: 14px;
  padding: 32px 26px;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
  border: 1px solid var(--border);
}
.auth-logo {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; margin: 0 auto 16px;
}
.auth-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.auth-card p.sub { text-align: center; color: var(--text-dim); font-size: 13px; margin: 0 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
  width: 100%; padding: 12px; border-radius: 10px; border: none;
  background: var(--accent-2); color: #04241c; font-weight: 600; font-size: 15px;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-dim); }
.auth-switch span { color: var(--accent-2); cursor: pointer; font-weight: 600; }
.error-msg { background: rgba(241,92,109,.12); color: var(--danger); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; display: none; }

/* ---------- App layout ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 360px 1fr;
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar.hide-mobile { display: none; }
  .chat-area.hide-mobile { display: none; }
}

.sidebar {
  background: var(--panel);
  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; border-bottom: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  color: var(--accent-2); flex-shrink: 0; font-size: 15px; overflow: hidden;
}
.me-info { min-width: 0; }
.me-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.my-id { font-size: 11px; color: var(--text-dim); cursor: pointer; user-select: none; }
.my-id:hover { color: var(--accent-2); }

.add-menu {
  position: absolute; top: 58px; right: 12px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; z-index: 40; box-shadow: 0 8px 24px rgba(0,0,0,.4); min-width: 200px;
}
.add-menu-item { padding: 12px 16px; font-size: 14px; cursor: pointer; }
.add-menu-item:hover { background: rgba(255,255,255,0.06); }

/* ---------- Modallar ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 900;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 22px; width: 100%; max-width: 380px;
}
.modal-box h3 { margin: 0 0 6px; font-size: 17px; }
.modal-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { width: auto; flex: 1; }

.item-badge-group {
  width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg,#3a6d5c,#274a3f);
  display:flex; align-items:center; justify-content:center; font-size:18px; flex-shrink:0;
}

.avatar img, .item-badge-group img { width:100%; height:100%; border-radius:50%; object-fit:cover; }
.avatar { overflow:hidden; }
#myAvatar, #peerAvatar { cursor: pointer; }

.profile-photo-row { display:flex; align-items:center; gap:12px; margin-bottom:16px; }
.profile-photo-preview {
  width: 64px; height: 64px; border-radius: 50%; background: var(--panel-2); overflow:hidden;
  display:flex; align-items:center; justify-content:center; font-size:22px; color:var(--accent-2); flex-shrink:0;
}
.profile-photo-preview img { width:100%; height:100%; object-fit:cover; }

.bubble .location-chip { display:flex; align-items:center; gap:8px; background: rgba(255,255,255,0.05); padding:8px 10px; border-radius:8px; text-decoration:none; color:inherit; }
.bubble .location-chip .loc-icon { font-size:20px; }

.pricing-card { background:var(--panel-2); border:1px solid var(--border); border-radius:10px; padding:14px; margin-bottom:10px; }
.pricing-card .pname { font-weight:700; font-size:15px; }
.pricing-card .pprice { color:var(--accent-2); font-weight:600; margin:4px 0; }
.pricing-card .pdesc { font-size:12.5px; color:var(--text-dim); margin-bottom:10px; }

.view-once-chip {
  display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:8px;
  background: rgba(255,255,255,0.05); min-width:180px;
}
.view-once-chip.locked { cursor:pointer; border:1px dashed var(--accent-2); }
.view-once-chip.locked:hover { background: rgba(37,211,102,.08); }
.view-once-chip.viewed { color: var(--text-dim); font-style: italic; }
.view-once-chip .loc-icon { font-size:22px; flex-shrink:0; }
.view-once-badge {
  position:absolute; top:6px; left:6px; background:rgba(0,0,0,.55); color:#fff; font-size:10.5px;
  padding:2px 7px; border-radius:6px;
}
.bubble { position: relative; }
.del-msg-btn { cursor:pointer; opacity:.55; margin-right:6px; font-size:11px; }
.del-msg-btn:hover { opacity:1; }
.icon-btn {
  background: transparent; border: none; color: var(--text-dim); font-size: 18px;
  padding: 8px; border-radius: 50%; line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.search-box { padding: 10px 12px; }
.search-box input {
  width: 100%; padding: 9px 12px; border-radius: 20px; border: none;
  background: var(--panel-2); color: var(--text); font-size: 14px; outline: none;
}

.user-list { flex: 1; overflow-y: auto; }
.user-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.02);
}
.user-item:hover, .user-item.active { background: var(--panel-2); }
.user-item .info { min-width: 0; flex: 1; }
.user-item .row1 { display: flex; justify-content: space-between; align-items: center; }
.user-item .name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-item .time { font-size: 11px; color: var(--text-dim); }
.user-item .last-msg { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-online { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2); position: absolute; margin-left: 30px; margin-top: 28px; border: 2px solid var(--panel); }
.badge { background: var(--accent-2); color: #04241c; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }

.chat-area { display: flex; flex-direction: column; min-width: 0; background: #0b141a url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><rect width="60" height="60" fill="%230b141a"/></svg>'); }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-dim); flex-direction: column; gap: 10px; text-align: center; padding: 20px; }
.chat-empty .big-icon { font-size: 60px; opacity: .5; }

.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: var(--panel);
}
.chat-header .info { flex: 1; min-width: 0; }
.chat-header .name { font-weight: 600; font-size: 15px; }
.chat-header .status { font-size: 12px; color: var(--text-dim); }
.header-actions { display: flex; gap: 4px; }

.messages { flex: 1; overflow-y: auto; padding: 16px 6% ; display: flex; flex-direction: column; gap: 3px; }
.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }
.bubble {
  max-width: 72%; padding: 7px 10px; border-radius: 10px; font-size: 14.5px;
  line-height: 1.35; position: relative; margin: 2px 0; word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.3);
}
.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; }
.bubble .meta { display: flex; justify-content: flex-end; gap: 4px; font-size: 10.5px; color: var(--text-dim); margin-top: 3px; }
.bubble img, .bubble video { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; max-height: 320px; }
.bubble .file-chip { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); padding: 8px; border-radius: 8px; }
.day-sep { text-align: center; margin: 14px 0; }
.day-sep span { background: var(--panel-2); color: var(--text-dim); font-size: 12px; padding: 4px 12px; border-radius: 8px; }

.composer { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--border); }
.composer input[type=text] {
  flex: 1; padding: 12px 16px; border-radius: 22px; border: none; background: var(--panel-2);
  color: var(--text); font-size: 15px; outline: none;
}
.composer .icon-btn { font-size: 20px; }
.send-btn { background: var(--accent-2); color: #04241c; border: none; width: 42px; height: 42px; border-radius: 50%; font-size: 18px; flex-shrink: 0; }

.typing-indicator { font-size: 12px; color: var(--accent-2); padding: 2px 16px; height: 18px; }

/* ---------- Call overlay ---------- */
.call-overlay {
  position: fixed; inset: 0; background: rgba(4,10,14,.97); z-index: 999;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  color: var(--text); text-align: center; padding: 20px;
}
.call-overlay.show { display: flex; }
.call-avatar { width: 100px; height: 100px; border-radius: 50%; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-size: 38px; color: var(--accent-2); margin: 0 auto; }
.call-name { font-size: 21px; font-weight: 600; margin-top: 8px; }
.call-status { color: var(--text-dim); font-size: 14px; }

.call-video-grid {
  display: none; width: 100%; max-width: 1000px; flex: 1; max-height: 60vh;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; align-content: center;
}
.call-video-grid.show { display: grid; }
.video-tile { position: relative; background: #131f26; border-radius: 12px; overflow: hidden; aspect-ratio: 4/3; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; }
.video-tile .tile-name { position: absolute; bottom: 6px; left: 8px; font-size: 12px; background: rgba(0,0,0,.5); padding: 2px 8px; border-radius: 6px; }
.video-tile.audio-only { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px; }
.video-tile.audio-only .avatar { width: 60px; height: 60px; font-size: 22px; }

.local-video-tile {
  position: fixed; width: 110px; height: 150px; object-fit: cover; bottom: 130px; right: 16px;
  border-radius: 10px; border: 2px solid #222; z-index: 1000;
}

.call-participants-list { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; max-width: 500px; }
.call-participants-list .pchip { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }

.call-actions { display: flex; gap: 20px; }
.call-btn { width: 58px; height: 58px; border-radius: 50%; border: none; font-size: 22px; display: flex; align-items: center; justify-content: center; }
.call-btn.accept { background: var(--accent-2); color: #04241c; }
.call-btn.reject, .call-btn.end { background: var(--danger); color: #2b0006; }
.call-btn.mute { background: var(--panel-2); color: var(--text); }

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.upload-progress { font-size: 11px; color: var(--text-dim); }
.back-btn { display: none; }
@media (max-width: 820px) { .back-btn { display: inline-flex; } }

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); padding: 10px 18px;
  border-radius: 10px; z-index: 1200; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #2a3942; border-radius: 4px; }
