/* ========================= */
/* Global layout / reset     */
/* ========================= */

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111827;
  color: #111827;
  overflow: hidden; /* prevent whole-page scroll */
}

#app {
  position: relative;
}

.hidden {
  display: none;
}

/* ========================= */
/* AUTH MODE (login screen)  */
/* ========================= */

body.auth-mode {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.auth-mode #app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Show only login card, centered */
body.auth-mode #auth-panel {
  width: 360px;
  max-width: 90vw;
  background: #f9fafb;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 25px rgba(15,23,42,0.5);
  display: block;
}

/* Hide chat completely before login */
body.auth-mode #chat-panel {
  display: none !important;
}

/* ========================= */
/* CHAT MODE (after login)   */
/* ========================= */

body.chat-mode {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Chat as a card, centered */
body.chat-mode #app {
  width: 1000px;
  max-width: 95vw;
  height: 80vh;
  max-height: 90vh;
  background: #f9fafb;
  border-radius: 16px;
  box-shadow: 0 15px 35px rgba(15,23,42,0.6);
  padding: 12px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* Hide login once in chat mode */
body.chat-mode #auth-panel {
  display: none !important;
}

/* Show chat panel as flex column */
body.chat-mode #chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow inner flex to shrink */
}

/* ========================= */
/* Auth panel styling        */
/* ========================= */

#auth-panel h2 {
  text-align: center;
  margin-bottom: 12px;
}

.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 3px;
  color: #4b5563;
}

.field input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  box-sizing: border-box;
}

.buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

button {
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 6px;
  border: none;
  background: #2563eb;
  color: white;
  font-size: 0.9rem;
}

button:hover {
  background: #1d4ed8;
}

.status {
  margin-top: 10px;
  min-height: 20px;
  font-size: 0.85rem;
}

/* forgot password */
#forgot-password {
  margin-top: 8px;
}

#forgot-toggle-btn {
  background: transparent;
  color: #2563eb;
  padding: 0;
}

#forgot-toggle-btn:hover {
  background: transparent;
  text-decoration: underline;
}

/* ========================= */
/* Chat layout (inside card) */
/* ========================= */

#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

#top-left #welcome {
  font-weight: 500;
}

#top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* avatar in header */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
}

/* main layout */
#main {
  flex: 1;
  display: flex;
  min-height: 0; /* important for scroll */
}

/* Sidebar */

#sidebar {
  width: 260px;
  border-right: 1px solid #e5e7eb;
  padding-right: 8px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#add-friend h3 {
  margin: 0 0 4px 0;
  font-size: 0.9rem;
}

#add-friend input {
  width: 100%;
  margin-bottom: 4px;
  padding: 4px 6px;
  font-size: 0.85rem;
  box-sizing: border-box;
}

#add-friend button {
  width: 100%;
  padding: 4px 0;
  font-size: 0.85rem;
}

/* Friend requests section */

#friend-requests h3 {
  margin: 8px 0 4px 0;
  font-size: 0.9rem;
}

#friend-requests-list {
  list-style: none;
  padding: 0;
  margin: 0 0 6px 0;
}

.friend-request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  background: #e5e7eb;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.friend-request-buttons {
  display: flex;
  gap: 4px;
}

.friend-request-buttons button {
  padding: 2px 6px;
  font-size: 0.75rem;
}

/* Chats list */

#sidebar h3 {
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

#chat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}

/* chat list items */

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  margin-bottom: 2px;
  font-size: 0.9rem;
  cursor: pointer;
}

.chat-item:hover {
  background: #e5e7eb;
}

.chat-item.active {
  background: #2563eb;
  color: white;
}

.chat-name {
  flex: 1;
}

/* small avatar in chat list */
.chat-avatar {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
}

.badge {
  background: #ef4444;
  color: white;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 0.75rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.status-dot.online {
  background: #22c55e;
}

.status-dot.offline {
  background: #9ca3af;
}

/* Chat area */

#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: 8px;
  min-width: 0;
  min-height: 0; /* important for scroll */
}

/* chat header with title + clear button */
#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

#conversation-title {
  font-weight: 600;
}

#clear-history-btn {
  padding: 4px 10px;
  font-size: 0.8rem;
  background: #ef4444;
  border-radius: 999px;
}

#clear-history-btn:hover {
  background: #b91c1c;
}

/* messages area */

#messages {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px;
  overflow-y: auto;         /* IMPORTANT: scroll only messages */
  background: #f3f4f6;
}

.message {
  margin-bottom: 4px;
}

.message .meta {
  font-size: 0.8rem;
  color: #4b5563;
}

.message.system {
  font-style: italic;
  color: #6b7280;
}

#typing-indicator {
  min-height: 18px;
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 2px;
}

/* Input bar */

#input-bar {
  margin-top: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* text input */
#input-bar input[type="text"] {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  box-sizing: border-box;
}

/* hide native file input */
#image-input,
#avatar-input {
  display: none;
}

/* pretty image (attach) button */
#send-image-btn {
  padding: 6px 10px;
  border-radius: 999px;
  background: #6b7280;
  font-size: 1.1rem;
  line-height: 1;
}

#send-image-btn:hover {
  background: #4b5563;
}

/* send button */
#send-btn {
  padding: 6px 14px;
}

/* Image messages */

.chat-image {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 6px;
  margin-top: 4px;
}

/* Slight tweaks on smaller screens */
@media (max-width: 800px) {
  body.chat-mode #app {
    width: 95vw;
  }
}

@media (max-height: 600px) {
  body.chat-mode #app {
    height: 85vh;
  }
}
