*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0d16;
  --sidebar:    #111120;
  --surface:    #181828;
  --border:     #252540;
  --primary:    #7c6df0;
  --primary-hv: #6659d8;
  --text:       #ddddf0;
  --muted:      #6868a0;
  --sent-bg:    #4a3fa8;
  --recv-bg:    #1c1c30;
  --green:      #4db882;
  --radius:     12px;
}

html, body { height: 100%; height: 100dvh; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ─── Layout ─── */
.app { display: flex; height: 100vh; height: 100dvh; }

/* ─── Sidebar ─── */
.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 18px 14px 14px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  margin-bottom: 14px;
}

.my-identity {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 4px;
}

.nick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

#my-nick {
  font-size: 15px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); background: var(--border); }

.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.conn-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
  flex-shrink: 0;
}
.conn-status.connected .dot   { background: var(--green); }
.conn-status.connected #conn-label { color: var(--green); }

/* ─── User list ─── */
.section-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 12px 16px 6px;
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 6px;
}
.user-list::-webkit-scrollbar { width: 3px; }
.user-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.empty-list {
  padding: 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
}
.user-item:hover  { background: var(--surface); }
.user-item.active { background: rgba(124,109,240,.18); }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #9c6fd0);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.user-nick {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

/* ─── Sidebar footer ─── */
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

.sidebar-footer input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}
.sidebar-footer input::placeholder { color: var(--muted); }
.sidebar-footer input:focus { border-color: var(--primary); }

#start-chat-btn {
  background: var(--primary);
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
#start-chat-btn:hover { background: var(--primary-hv); }

/* ─── Main area ─── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Empty state ─── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px;
  text-align: center;
}
.empty-lock { color: var(--primary); opacity: .5; margin-bottom: 6px; }
.empty-state h2 { font-size: 22px; font-weight: 700; }
.empty-state p  { color: var(--muted); font-size: 13px; }
.empty-state .hint { max-width: 280px; }
.e2e-pill {
  margin-top: 12px;
  background: rgba(77,184,130,.1);
  border: 1px solid rgba(77,184,130,.25);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--green);
}

/* ─── Chat window ─── */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar);
}
.back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.back-btn:hover { background: var(--border); }
.chat-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
}
.e2e-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--green);
  background: rgba(77,184,130,.09);
  border: 1px solid rgba(77,184,130,.2);
  border-radius: 12px;
  padding: 3px 9px;
}

/* ─── Messages ─── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.messages::-webkit-scrollbar { width: 3px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  display: flex;
  flex-direction: column;
  max-width: 68%;
}
.message.sent     { align-self: flex-end;   align-items: flex-end; }
.message.received { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 9px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}
.message.sent     .bubble { background: var(--sent-bg); color: #fff; border-bottom-right-radius: 4px; }
.message.received .bubble { background: var(--recv-bg); color: var(--text); border-bottom-left-radius: 4px; }

.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  padding: 0 2px;
}

/* ─── Input area ─── */
.input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--sidebar);
}

#msg-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
#msg-input::placeholder { color: var(--muted); }
#msg-input:focus { border-color: var(--primary); }

#send-btn {
  background: var(--primary);
  border: none;
  border-radius: 10px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#send-btn:hover  { background: var(--primary-hv); }
#send-btn:active { transform: scale(.93); }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 18px;
  font-size: 13px;
  color: var(--text);
  z-index: 9999;
  pointer-events: none;
  animation: toastIn .25s ease, toastOut .3s ease 2.7s forwards;
}

@keyframes toastIn  { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(-50%) translateY(-6px); } }

/* ─── Mobile ─── */
@media (max-width: 700px) {
  .app {
    flex-direction: column;
    height: 100dvh;
  }

  .sidebar {
    width: 100%;
    height: 100dvh;
    position: absolute;
    top: 0; left: 0;
    z-index: 10;
    transition: transform .25s ease;
  }

  .main {
    width: 100%;
    height: 100dvh;
    position: absolute;
    top: 0; left: 0;
  }

  .chat-window {
    height: 100dvh;
  }

  /* Chat açıkken sidebar'ı sola kaydır */
  .app.chat-open .sidebar {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .back-btn { display: flex; }

  .e2e-badge span { display: none; }

  .message { max-width: 85%; }

  /* iOS zoom engellemek için input font-size 16px olmalı */
  #msg-input,
  .sidebar-footer input {
    font-size: 16px;
  }

  .sidebar-footer {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
