/* Clean, consolidated stylesheet after repair */
/* ---------- CSS VARIABLES ---------- */
:root {
  --primary-color: #b01510;
  --primary-color-hover: #8e100d;
  --background: #ffffff;
  --secondary-color: #f5f5f7;
  --panel-color: #ffffff;
  --border-color: #e5e5e5;
  --border-subtle: #f1f1f3;
  --text-color: #222;
  --text-light: #666;
  --text-lighter: #999;
  --danger: #d93025;
  --success: #1b8755;
  --incoming-bubble: #f0f1f4;
  --outgoing-bubble: #b01510;
  --outgoing-bubble-text: #fff;
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, .08), 0 2px 6px -2px rgba(0, 0, 0, .06);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --transition: .25s cubic-bezier(.4, 0, .2, 1);
}

/* ---------- GLOBAL RESETS ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
}

html,
body {
  height: 100%;
}

body {
  background: var(--background);
  color: var(--text-color);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font-family: inherit;
  outline: none;
  border: none;
  background: none;
}

/* ---------- AUTH SCREENS ---------- */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(180deg, #fafbfc, #f1f2f5);
}

.auth-box {
  background: #fff;
  padding: 32px 30px 36px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  animation: fadeIn .4s ease;
}

.auth-box h2 {
  text-align: center;
  margin-bottom: 18px;
  font-weight: 600;
  color: var(--primary-color);
  letter-spacing: .5px;
}

.tabs {
  display: flex;
  margin-bottom: 26px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: var(--secondary-color);
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--text-light);
  background: transparent;
  position: relative;
  transition: var(--transition);
}

.tab-btn.active {
  background: #fff;
  color: var(--primary-color);
  box-shadow: 0 2px 4px -2px rgba(0, 0, 0, .15);
}

.auth-form {
  animation: fadeIn .3s ease;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-light);
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: .9rem;
  background: #fff;
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(176, 21, 16, .15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-size: .9rem;
}

.btn-primary {
  background: var(--primary-color);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-color-hover);
}

.btn-logout {
  color: var(--danger);
  background: transparent;
}

.btn-logout:hover {
  background: #fdecec;
}

/* ---------- CHAT LAYOUT ---------- */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--panel-color);
  box-shadow: var(--shadow);
  position: relative;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eeeeee;
  background: var(--panel-color);
  position: sticky;
  top: 0;
  z-index: 20;
}

.left-header {
  display: flex;
  align-items: center;
  min-width: 0;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.1rem;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.nav-btn:hover {
  background: var(--secondary-color);
  color: var(--text-color);
}

.group-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e63934, #780d0b);
  margin-right: 12px;
  flex-shrink: 0;
}

.group-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.group-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.group-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-color);
}

.sub-status {
  font-size: .65rem;
  color: var(--text-lighter);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  letter-spacing: .2px;
  font-weight: 500;
}

.dot-sep {
  opacity: .4;
}

.anon-status {
  background: var(--incoming-bubble);
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .5px;
}

.anon-status.on {
  background: var(--primary-color);
  color: #fff;
}

.right-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.incognito-btn {
  background: var(--primary-color);
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  border-radius: 50%;
  width: 42px;
  height: 42px;
}

.incognito-btn:hover {
  background: var(--primary-color-hover);
}

.incognito-btn svg circle {
  fill: #ffffff;
}

.incognito-btn svg path {
  fill: var(--primary-color);
}

.incognito-btn.active {
  background: transparent;
}

.incognito-btn.active:hover {
  background: var(--secondary-color);
}

.incognito-btn.active svg circle {
  fill: var(--primary-color);
}

.incognito-btn.active svg path {
  fill: #ffffff;
}

.current-user-avatar-wrapper {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-light);
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--secondary-color);
  color: var(--primary-color);
}

.btn-icon.logout {
  color: var(--danger);
}

.btn-icon.logout:hover {
  background: #fdecec;
  color: var(--danger);
}

/* Anonymous banner */
/* (Old top banner removed per new design) */
.inline-anon-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: .68rem;
  font-weight: 400;
  letter-spacing: .2px;
  color: #999;
  margin: 12px 0 8px;
  padding: 6px 12px;
  background: transparent;
  border-radius: 12px;
  align-self: center;
  text-align: center;
}

.inline-anon-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.inline-anon-icon svg {
  width: 12px;
  height: 12px;
}

.inline-anon-text {
  white-space: nowrap;
}

/* ---------- MESSAGES ---------- */
.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: #f8f9fa;
}

.messages:focus {
  outline: none;
}

/* Date separator */
.date-separator {
  text-align: center;
  margin: 16px 0;
  font-size: .7rem;
  color: var(--text-lighter);
  font-weight: 500;
}

.message {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  margin: 0 0 8px;
  max-width: 75%;
  position: relative;
  gap: 8px;
  animation: fadeIn .25s ease;
}

.message:last-child {
  margin-bottom: 6px;
}

.message-incoming {
  align-self: flex-start;
}

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

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.message-content {
  max-width: calc(100% - 38px);
}

.message-sender {
  font-size: .68rem;
  font-weight: 600;
  margin: 0 0 2px;
  color: var(--text-light);
  letter-spacing: .2px;
}

.message-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: .85rem;
  line-height: 1.3;
  word-wrap: break-word;
  position: relative;
  font-weight: 400;
  max-width: 280px;
}

.message-incoming .message-bubble {
  background: #ffffff;
  color: var(--text-color);
  border-top-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.message-outgoing .message-bubble {
  background: var(--outgoing-bubble);
  color: var(--outgoing-bubble-text);
  border-top-right-radius: 4px;
}

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time {
  font-size: .58rem;
  color: var(--text-lighter);
  margin-top: 4px;
  text-align: right;
  font-weight: 500;
  letter-spacing: .2px;
}

.message-outgoing .message-time {
  color: rgba(255, 255, 255, .8);
}

/* ---------- INPUT AREA ---------- */
.message-input {
  padding: 12px 16px 16px;
  background: var(--panel-color);
  border-top: 1px solid #eeeeee;
}

.input-container {
  display: flex;
  align-items: center;
  background: #f5f5f5;
  border-radius: 20px;
  padding: 8px 12px;
  gap: 8px;
  border: 1px solid #e8e8e8;
  transition: var(--transition);
}

.input-container:focus-within {
  background: #f0f0f0;
  border-color: #ddd;
}

input#message-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 8px;
  font-size: .9rem;
  color: var(--text-color);
  font-weight: 400;
}

input#message-input::placeholder {
  color: #aaa;
  font-weight: 400;
}

.send-btn {
  background: var(--primary-color);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  font-size: .9rem;
  cursor: pointer;
  transition: var(--transition);
}

.send-btn:hover {
  background: var(--primary-color-hover);
}

.send-btn:active {
  transform: scale(.95);
}

.send-btn:hover {
  background: var(--primary-color-hover);
  transform: translateY(-1px);
}

.send-btn:active {
  transform: translateY(0);
}

.anonymous-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 14px;
  background: transparent;
  transition: var(--transition);
}

.anonymous-toggle.active {
  background: var(--primary-color);
}

.anonymous-toggle.active .anon-mode-icon {
  color: #fff;
}

.anon-mode-icon {
  font-size: 1.05rem;
  color: var(--text-lighter);
  transition: var(--transition);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #cfd0d3;
  transition: .35s;
  border-radius: 34px;
}

.slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  transition: .35s;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}

.switch input:checked+.slider {
  background: var(--primary-color);
}

.switch input:checked+.slider:before {
  transform: translateX(20px);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width:820px) {
  .chat-container {
    max-width: 100%;
    border-radius: 0;
  }

  .group-title {
    font-size: .95rem;
  }

  .group-avatar {
    width: 42px;
    height: 42px;
    margin-right: 10px;
  }

  .sub-status {
    font-size: .55rem;
  }

  .current-username {
    display: none;
  }

  .message {
    max-width: 88%;
  }

  .anon-banner {
    top: 60px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
  }
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #999;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #666;
}

/* ---------- ANIMATIONS ---------- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- ACCESSIBILITY ---------- */
button:focus-visible,
.send-btn:focus-visible,
.nav-btn:focus-visible,
.btn-icon:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

@media (prefers-reduced-motion:reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}