:root {
  --green: #128C7E;
  --green-dark: #075E54;
  --green-light: #DCF8C6;
  --bg-chat: #ECE5DD;
  --bg-panel: #ffffff;
  --border: #e2e2e2;
  --text: #111b21;
  --muted: #667781;
  --danger: #b00020;
  --mention: #d9fdd3;
}

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

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--green-dark); padding: 16px;
}
.login-card {
  background: #fff; border-radius: 12px; padding: 32px 28px;
  width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.login-card h1 { margin: 0 0 4px; color: var(--green-dark); font-size: 1.5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.login-card form label, .admin-wrap form label {
  display: block; margin-top: 14px; font-size: .85rem; color: var(--muted);
}
.login-card input, .admin-wrap input, .admin-wrap select {
  width: 100%; padding: 12px; margin-top: 4px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; min-height: 44px;
}
.login-card button, .btn {
  display: inline-block; margin-top: 18px; padding: 12px 18px; min-height: 44px;
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  font-size: 1rem; cursor: pointer; text-decoration: none; text-align: center;
}
.btn-ghost { background: transparent; color: var(--green-dark); border: 1px solid var(--green); }
.err { color: var(--danger); font-size: .9rem; }

/* ---------- App shell ---------- */
.app-body { height: 100vh; overflow: hidden; }
.app { display: flex; height: 100vh; }

.sidebar {
  width: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: #f0f2f5; 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(--green);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0;
}
.me-name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.me-role { font-size: .75rem; color: var(--muted); text-transform: capitalize; }
.sidebar-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: transparent; font-size: 1.2rem; padding: 8px;
  min-width: 44px; min-height: 44px; cursor: pointer; border-radius: 50%;
  color: var(--green-dark); text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }

.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  cursor: pointer; border-bottom: 1px solid #f5f5f5; min-height: 60px;
}
.conv-item:hover, .conv-item.active { background: #f0f2f5; }
.conv-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--green-dark);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0;
}
.conv-avatar.group { background: #8696a0; }
.conv-meta { min-width: 0; flex: 1; }
.conv-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-empty { padding: 24px; color: var(--muted); text-align: center; font-size: .9rem; }

.chat-pane {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  background: var(--bg-chat);
}
.chat-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: #f0f2f5; border-bottom: 1px solid var(--border); min-height: 56px;
}
.chat-header-title { font-weight: 600; }
.back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg-empty { margin: auto; color: var(--muted); font-size: .9rem; text-align: center; }

.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 8px 10px; border-radius: 10px; background: #fff;
  box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: .92rem; line-height: 1.35;
  word-wrap: break-word;
}
.bubble-row.mine .bubble { background: var(--green-light); }
.bubble-sender { font-size: .78rem; font-weight: 700; color: var(--green-dark); margin-bottom: 2px; }
.bubble-time { font-size: .68rem; color: var(--muted); text-align: right; margin-top: 4px; }
.mention { background: var(--mention); border-radius: 4px; padding: 0 2px; font-weight: 600; }

.file-card {
  display: flex; align-items: center; gap: 10px; padding: 6px; background: #f7f7f7;
  border-radius: 8px; text-decoration: none; color: var(--text);
}
.file-card .file-icon { font-size: 1.6rem; }
.file-card .file-info { min-width: 0; }
.file-card .file-name { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.file-card .file-size { font-size: .75rem; color: var(--muted); }
.bubble img.msg-image, .bubble video.msg-video { max-width: 100%; border-radius: 8px; display: block; }
.bubble audio { width: 220px; max-width: 100%; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  background: #f0f2f5; border-top: 1px solid var(--border); position: relative;
}
.composer textarea {
  flex: 1; resize: none; border: none; border-radius: 20px; padding: 10px 14px;
  font-size: .95rem; max-height: 120px; min-height: 44px; font-family: inherit;
}
.send-btn {
  border: none; background: var(--green); color: #fff; width: 44px; height: 44px;
  border-radius: 50%; font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}
.file-preview {
  position: absolute; bottom: 60px; left: 10px; right: 10px; background: #fff;
  border-radius: 8px; padding: 8px 10px; display: flex; align-items: center;
  justify-content: space-between; box-shadow: 0 2px 8px rgba(0,0,0,.15); font-size: .85rem;
}
.file-preview button { border: none; background: transparent; color: var(--danger); font-size: 1rem; cursor: pointer; }

.mention-box {
  position: absolute; bottom: 60px; left: 10px; right: 10px; background: #fff;
  border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.15); max-height: 200px;
  overflow-y: auto; z-index: 5;
}
.mention-item { padding: 10px 12px; cursor: pointer; font-size: .9rem; border-bottom: 1px solid #f2f2f2; }
.mention-item:hover, .mention-item.sel { background: #f0f2f5; }

/* ---------- Modal (new DM) ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px;
}
.modal-card { background: #fff; border-radius: 10px; padding: 20px; width: 100%; max-width: 420px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-card h3 { margin: 0 0 4px; }
.modal-card input[type=text] {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  margin: 10px 0; min-height: 44px; font-size: 1rem;
}
.user-pick-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.user-pick-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 6px; cursor: pointer;
  border-bottom: 1px solid #f2f2f2; min-height: 48px;
}
.user-pick-item:hover { background: #f7f7f7; }
.user-pick-name { font-weight: 600; font-size: .92rem; }
.user-pick-sub { font-size: .78rem; color: var(--muted); }

/* ---------- Admin ---------- */
.admin-body { background: #f7f7f7; }
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.admin-narrow { max-width: 480px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: 16px; background: #fff; }
.admin-table th, .admin-table td { text-align: left; padding: 10px; border-bottom: 1px solid #eee; font-size: .9rem; }
.role-badge { padding: 2px 8px; border-radius: 10px; font-size: .75rem; background: #eef; text-transform: capitalize; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.checkbox-row input { width: auto; min-height: auto; }

/* ================= Mobile-first: single pane, slide the chat in ================= */
.sidebar { position: relative; z-index: 1; }
.chat-pane { display: none; }
.app.chat-open .sidebar { display: none; }
.app.chat-open .chat-pane { display: flex; }
.back-btn { display: inline-flex; }

/* ================= Tablet & up: two panes side by side ================= */
@media (min-width: 768px) {
  .sidebar { width: 340px; flex-shrink: 0; display: flex !important; }
  .chat-pane { display: flex !important; flex: 1; }
  .app.chat-open .sidebar { display: flex !important; }
  .back-btn { display: none !important; }
}

@media (min-width: 1024px) {
  .sidebar { width: 380px; }
}
