:root {
  --rr-navy-dark: #0b1e36;
  --rr-navy: #122b4d;
  --rr-navy-light: #1b3d6c;
  --rr-blue: #1d4ed8;
  --rr-blue-light: #3b82f6;
  --rr-gold: #f59e0b;
  --rr-gold-light: #fbbf24;
  --rr-gold-dark: #d97706;
  --rr-red: #dc2626;

  --bg-page: #f1f5f9;
  --bg-chat: #f8fafc;
  --bg-bubble-other: #ffffff;
  --bg-bubble-me: #122b4d;
  --text-me: #ffffff;
  --text-dark: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-page);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Auth / Login Container */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at top center, #1b3d6c 0%, #0b1e36 100%);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.auth-emblem {
  width: 72px;
  height: 72px;
  margin: 0 auto 1rem;
}

.auth-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--rr-navy-dark);
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.form-group {
  margin-bottom: 1.25rem;
  text-align: left;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--rr-navy);
  margin-bottom: 0.4rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  transition: all 0.2s ease;
  background: #f8fafc;
}

.form-input:focus {
  outline: none;
  border-color: var(--rr-blue);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-submit {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--rr-navy), var(--rr-navy-light));
  color: #ffffff;
  font-weight: 700;
  font-size: 1rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-submit:hover {
  background: linear-gradient(135deg, var(--rr-navy-light), var(--rr-blue));
  transform: translateY(-1px);
  box-shadow: 0 6px 15px rgba(18, 43, 77, 0.25);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.alert-error {
  background: #fee2e2;
  border: 1px solid #f87171;
  color: #991b1b;
}

.alert-success {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}

/* Chat Layout */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Header */
.chat-header {
  background: var(--rr-navy-dark);
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid var(--rr-gold);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chat-header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-header-emblem {
  width: 36px;
  height: 36px;
}

.chat-header-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.chat-header-badge {
  font-size: 0.75rem;
  color: var(--rr-gold-light);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.online-dot {
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px #22c55e;
}

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.user-badge:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-header {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #ffffff;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-header.danger:hover {
  background: var(--rr-red);
  border-color: var(--rr-red);
}

/* Chat Body (Sidebar + Messages) */
.chat-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Sidebar Roster */
.chat-sidebar {
  width: 280px;
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-section-title {
  padding: 1rem 1.25rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.roster-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 0.75rem;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
  margin-bottom: 0.25rem;
}

.roster-item:hover {
  background: #f1f5f9;
}

.roster-avatar {
  font-size: 1.35rem;
  line-height: 1;
}

.roster-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.roster-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--rr-navy-dark);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.roster-patrol {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.sidebar-code-box {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-chat);
  font-size: 0.8rem;
  color: var(--rr-navy);
}

.sidebar-code-box strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--rr-gold-dark);
}

/* Chat Main Pane */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  overflow: hidden;
}

.messages-viewport {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.message-card {
  display: flex;
  gap: 0.8rem;
  max-width: 82%;
  animation: message-pop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes message-pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-card.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border-color);
}

.message-content {
  display: flex;
  flex-direction: column;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 0.78rem;
}

.message-card.mine .msg-header {
  justify-content: flex-end;
}

.msg-author {
  font-weight: 700;
  color: var(--rr-navy-dark);
}

.msg-patrol {
  font-size: 0.7rem;
  color: var(--rr-blue);
  background: rgba(37, 99, 235, 0.08);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

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

.msg-bubble {
  background: var(--bg-bubble-other);
  border: 1px solid var(--border-color);
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  font-size: 0.92rem;
  line-height: 1.5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  word-break: break-word;
}

.message-card.mine .msg-bubble {
  background: linear-gradient(135deg, var(--rr-navy) 0%, var(--rr-navy-light) 100%);
  color: #ffffff;
  border-color: rgba(245, 158, 11, 0.3);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: 4px;
  box-shadow: 0 3px 10px rgba(18, 43, 77, 0.2);
}

/* Chat Input Bar */
.chat-footer {
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
}

.quick-emojis {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.emoji-btn {
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1.1rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.emoji-btn:hover {
  background: #e2e8f0;
  transform: scale(1.15);
}

.chat-input-row {
  display: flex;
  gap: 0.75rem;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1.1rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input:focus {
  border-color: var(--rr-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-send {
  background: linear-gradient(135deg, var(--rr-gold-light), var(--rr-gold));
  color: var(--rr-navy-dark);
  border: none;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-send:hover {
  background: linear-gradient(135deg, #fcd34d, var(--rr-gold-light));
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
}

/* Profile Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 30, 54, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.3);
  transform: translateY(15px);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-box {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--rr-navy);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Avatar picker */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.avatar-option {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  padding: 0.5rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.avatar-option:hover {
  background: #f1f5f9;
}

.avatar-option.selected {
  border-color: var(--rr-blue);
  background: rgba(37, 99, 235, 0.12);
  transform: scale(1.08);
}

/* Mobile Drawer Elements */
.btn-roster-mobile {
  display: none;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  margin-right: 0.35rem;
}

.sidebar-header-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  background: var(--rr-navy-dark);
}

.sidebar-header-mobile .sidebar-section-title {
  padding: 0;
  color: var(--rr-gold-light);
}

.btn-close-sidebar {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: #ffffff;
  cursor: pointer;
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(11, 30, 54, 0.6);
  backdrop-filter: blur(2px);
  z-index: 70;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
  .btn-roster-mobile {
    display: inline-flex;
  }

  .sidebar-header-mobile {
    display: flex;
  }

  .chat-header {
    padding: 0.55rem 0.85rem;
    padding-top: max(0.55rem, env(safe-area-inset-top));
  }

  .chat-header-emblem {
    width: 30px;
    height: 30px;
  }

  .chat-header-title {
    font-size: 0.95rem;
    line-height: 1.2;
  }

  .chat-header-badge {
    font-size: 0.68rem;
  }

  .chat-header-user {
    gap: 0.4rem;
  }

  .user-badge {
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
  }

  .user-name-text {
    max-width: 70px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .btn-header {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
  }

  .chat-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 85vw;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.35);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  .messages-viewport {
    padding: 0.85rem;
    gap: 0.85rem;
  }

  .message-card {
    max-width: 92%;
  }

  .msg-avatar {
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
  }

  .msg-bubble {
    padding: 0.65rem 0.9rem;
    font-size: 0.88rem;
  }

  .chat-footer {
    padding: 0.55rem 0.75rem;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  }

  .quick-emojis {
    gap: 0.3rem;
  }

  .emoji-btn {
    padding: 0.15rem 0.4rem;
    font-size: 1rem;
  }

  .chat-input-row {
    gap: 0.45rem;
  }

  .chat-input {
    padding: 0.65rem 0.95rem;
    font-size: 16px; /* Prevents auto-zoom on iOS Safari */
  }

  .btn-send {
    padding: 0.65rem 1rem;
    font-size: 0.88rem;
  }

  .avatar-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .auth-card {
    padding: 2rem 1.25rem;
  }

  .modal-box {
    padding: 1.5rem 1.25rem;
    max-height: 90vh;
    overflow-y: auto;
  }
}
