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

:root {
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-hover: #1a1a1a;
  --bg-input: #1e1e1e;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-dim: #888;
  --text-muted: #555;
  --accent: #f59e0b;
  --accent-dim: rgba(245, 158, 11, 0.15);
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --ron: #3b82f6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Layout ── */
.app {
  display: flex;
  height: 100%;
  width: 100%;
}

/* ── Sidebar ── */
.sidebar {
  width: 320px;
  min-width: 320px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

.sidebar-header {
  padding: 16px 20px;
  padding-top: calc(16px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); opacity: 0.5; }

.online-count {
  font-size: 13px;
  color: var(--text-dim);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--accent-dim); }

.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  margin-right: 12px;
  flex-shrink: 0;
  color: #fff;
}

.conv-info { flex: 1; min-width: 0; }

.conv-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.conv-preview {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta {
  text-align: right;
  flex-shrink: 0;
  margin-left: 8px;
}

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
}

.conv-badge {
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-top: 4px;
  display: inline-block;
}

/* ── Chat area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

.chat-header {
  padding: 14px 20px;
  padding-top: calc(14px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px 4px 0;
}

.chat-header-info h2 {
  font-size: 16px;
  font-weight: 600;
}

.chat-header-info .role {
  font-size: 12px;
  color: var(--text-dim);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 12px 0 6px;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}

.message.sent {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.received {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .sender-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.message .msg-time {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  margin-top: 4px;
  text-align: right;
}

.message.received .msg-time {
  color: var(--text-muted);
}

/* ── Input bar ── */
.chat-input-bar {
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
}

.chat-input-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--accent);
}

.chat-input-bar input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.3; cursor: default; }

.send-btn svg {
  width: 18px;
  height: 18px;
  fill: #000;
}

/* ── Empty state ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 8px;
}

.empty-state .logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.empty-state h3 {
  font-size: 18px;
  color: var(--text-dim);
}

/* ── Broadcast bar ── */
.broadcast-bar {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  gap: 10px;
  align-items: center;
}

.broadcast-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.broadcast-bar input:focus { border-color: var(--accent); }
.broadcast-bar input::placeholder { color: var(--text-muted); }

.broadcast-bar button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 16px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
  }

  .chat-area {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: none;
  }

  .chat-area.visible {
    display: flex;
  }

  .chat-header .back-btn {
    display: block;
  }

  .message { max-width: 85%; }
}

/* ── Voice button ── */
.voice-btn, .voice-broadcast-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 50%;
  transition: background 0.15s;
  flex-shrink: 0;
}

.voice-btn:hover, .voice-broadcast-btn:hover {
  background: var(--bg-hover);
}

.voice-btn.listening, .voice-broadcast-btn.listening {
  background: var(--red);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
