:root {
  --bg-app: #0b141a;
  --bg-sidebar: #111b21;
  --bg-panel-header: #202c33;
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  --bg-input: #2a3942;
  --bg-bubble-out: #005c4b;
  --bg-bubble-in: #202c33;
  --accent: #00a884;
  --accent-soft: #00a88433;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --border: #222e35;
  --danger: #e0607a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

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

/* ---------- LOGIN ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(circle at 30% 20%, #0f2027 0%, #0b141a 55%, #060a0d 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}

.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 12px; }
.login-brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.3px; }
.login-brand p { margin: 4px 0 0; color: var(--text-secondary); font-size: 13.5px; }

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.login-form input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text-primary);
  font-size: 14.5px;
  outline: none;
}
.login-form input:focus { border-color: var(--accent); }

.login-error {
  background: #e0607a1f;
  color: var(--danger);
  border: 1px solid #e0607a55;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.btn-primary {
  background: var(--accent);
  color: #06231d;
  border: none;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14.5px;
  font-weight: 600;
  transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14.5px;
}
.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-secondary); }

/* ---------- APP LAYOUT ---------- */
.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  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: 12px 16px;
  background: var(--bg-panel-header);
}

.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-info { display: flex; flex-direction: column; min-width: 0; }
.me-info strong { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-role { font-size: 12px; color: var(--text-secondary); text-transform: capitalize; }

.sidebar-actions { display: flex; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px;
  color: #06231d;
  flex-shrink: 0;
  background: var(--accent);
}

.search-box { padding: 8px 12px; }
.search-box input {
  width: 100%;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13.5px;
  outline: none;
}

.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-top strong { font-size: 14.5px; font-weight: 500; }
.chat-item-time { font-size: 11.5px; color: var(--text-secondary); }

.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.chat-item-preview {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.unread-badge {
  background: var(--accent);
  color: #06231d;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-secondary);
  display: inline-block;
  margin-right: 5px;
}
.status-dot.online { background: var(--accent); }

.empty-list { padding: 24px 20px; color: var(--text-secondary); font-size: 13.5px; text-align: center; }

/* ---------- CHAT PANEL ---------- */
.chat-panel {
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-image: radial-gradient(circle at 1px 1px, #1a2429 1px, transparent 0);
  background-size: 22px 22px;
}

.no-chat {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  color: var(--text-secondary);
}
.no-chat p { max-width: 260px; text-align: center; font-size: 14px; }

.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border);
}
.chat-header-info { display: flex; flex-direction: column; }
.chat-header-info strong { font-size: 15px; }
.chat-status { font-size: 12.5px; color: var(--text-secondary); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 8% 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.day-divider {
  align-self: center;
  background: var(--bg-panel-header);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 8px;
  margin: 12px 0;
}

.bubble {
  max-width: 65%;
  padding: 7px 10px 8px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble.out { align-self: flex-end; background: var(--bg-bubble-out); border-top-right-radius: 2px; }
.bubble.in { align-self: flex-start; background: var(--bg-bubble-in); border-top-left-radius: 2px; }

.bubble-sender { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.bubble-time { font-size: 10.5px; color: var(--text-secondary); float: right; margin: 6px 0 -3px 8px; }

.message-form {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--bg-panel-header);
}
.message-form input {
  flex: 1;
  background: var(--bg-input);
  border: none;
  border-radius: 22px;
  padding: 11px 16px;
  color: var(--text-primary);
  font-size: 14.5px;
  outline: none;
}
.send-btn {
  background: var(--accent);
  color: #06231d;
  border: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.send-btn:hover { filter: brightness(1.08); }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 26px 22px;
  width: 100%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 { margin: 0 0 18px; font-size: 18px; }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.modal input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #2a3942; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: absolute; inset: 0; z-index: 10; }
  .sidebar.hidden-mobile { display: none; }
  .chat-panel { position: absolute; inset: 0; }
  .messages { padding: 14px 4% 12px; }
  .bubble { max-width: 82%; }
}
