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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e5e7eb;
}

/* Auth page */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1d4ed8, #020617);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 1.8rem 1.8rem 2rem;
  border-radius: 1.25rem;
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.auth-card h1 {
  margin-top: 0;
  margin-bottom: 1rem;
  text-align: center;
}

.auth-card label {
  display: block;
  font-size: 0.9rem;
  margin-top: 0.7rem;
  margin-bottom: 0.25rem;
}

.auth-card input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 0.7rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: #020617;
  color: #e5e7eb;
}

.auth-card input:focus {
  outline: none;
  border-color: #38bdf8;
}

.auth-card .btn {
  width: 100%;
  margin-top: 1rem;
}

.auth-link {
  text-align: center;
  margin-top: 0.8rem;
  font-size: 0.9rem;
}

/* Alerts */
.alert {
  padding: 0.5rem 0.7rem;
  border-radius: 0.7rem;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.8);
}

.alert-success {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(74, 222, 128, 0.9);
}

/* Buttons */
.btn {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
  background: #1f2937;
  color: #e5e7eb;
}

.btn.primary {
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  color: #020617;
}

.btn.small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

/* App layout */
.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  flex-shrink: 0;
  padding: 0.6rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #020617;
  border-bottom: 1px solid rgba(148, 163, 184, 0.4);
}

.app-title {
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.9rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}

/* Chat layout */
.chat-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 0;
}

/* Sidebar */
.sidebar {
  border-right: 1px solid rgba(148, 163, 184, 0.25);
  background: #020617;
  display: flex;
  flex-direction: column;
  padding: 0.6rem;
  gap: 0.6rem;
}

.sidebar-section h2 {
  font-size: 0.9rem;
  margin: 0 0 0.4rem;
}

.sidebar-section input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.35rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: #020617;
  color: #e5e7eb;
}

.search-result {
  font-size: 0.85rem;
  max-height: 150px;
  overflow-y: auto;
}

.search-item {
  padding: 0.35rem 0.4rem;
  border-radius: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-item:nth-child(odd) {
  background: rgba(15, 23, 42, 0.7);
}

.search-item button {
  font-size: 0.75rem;
}

.friends-list {
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  font-size: 0.9rem;
}

.friend-item {
  padding: 0.4rem 0.5rem;
  border-radius: 0.6rem;
  cursor: pointer;
}

.friend-item:hover,
.friend-item.active {
  background: rgba(56, 189, 248, 0.18);
}

/* Chat area */
.chat-section {
  display: flex;
  flex-direction: column;
  background: #020617;
}

.chat-header-empty {
  padding: 1rem;
  text-align: center;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.9rem;
  color: #9ca3af;
}

.chat-header {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-window {
  flex: 1;
  padding: 0.8rem;
  overflow-y: auto;
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), #020617);
}

/* Bubbles */
.message-row {
  margin-bottom: 0.4rem;
  display: flex;
}

.message-row.me {
  justify-content: flex-end;
}

.message-row.them {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 70%;
  padding: 0.45rem 0.65rem;
  border-radius: 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
}

.message-row.me .message-bubble {
  background: #22c55e;
  color: #020617;
  border-bottom-right-radius: 0.2rem;
}

.message-row.them .message-bubble {
  background: #111827;
  border-bottom-left-radius: 0.2rem;
}

.message-time {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 0.1rem;
}

/* Message form */
.message-form {
  flex-shrink: 0;
  padding: 0.6rem 0.7rem;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  display: flex;
  gap: 0.5rem;
}

.message-form input[type="text"] {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: #020617;
  color: #e5e7eb;
}

.message-form input:focus {
  outline: none;
  border-color: #38bdf8;
}

/* Responsive */
@media (max-width: 768px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    height: 40vh;
  }

  .chat-section {
    height: 60vh;
  }
}
