/* ============================================================
   WORLDS CHAT — Dark Sleek UI  |  Purple/Violet Theme
   Font: Syne (headers) + DM Sans (body)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-base:        #0e0e12;
  --bg-surface:     #16161d;
  --bg-elevated:    #1e1e28;
  --bg-hover:       #25252f;
  --bg-input:       #1a1a24;

  --accent:         #7c5cbf;
  --accent-light:   #9d7fd8;
  --accent-dim:     #3a2d65;
  --accent-glow:    rgba(124, 92, 191, 0.18);

  --text-primary:   #e8e6f0;
  --text-secondary: #9490a8;
  --text-muted:     #5c5870;

  --border:         rgba(255,255,255,0.06);
  --border-strong:  rgba(255,255,255,0.12);

  --bubble-self:        #4e3a8a;
  --bubble-self-light:  #5c449e;
  --bubble-other:       #1e1e28;
  --bubble-other-border:#2a2a38;

  --danger:         #c0415a;
  --danger-dim:     rgba(192, 65, 90, 0.15);

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  18px;
  --radius-xl:  24px;

  --sidebar-w: 240px;
  --header-h:  64px;
  --input-h:   56px;

  --shadow-md:  0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.55);
  --glow-accent: 0 0 0 3px rgba(124, 92, 191, 0.35);
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar        { width: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--accent-dim); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════ */

.chat-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ════════════════════════════════════════
   SIDEBAR
   ════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 10px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 10;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s ease;
}

/* Sidebar top logo strip */
.sidebar::before {
  content: "🌐 Worlds Chat";
  display: block;
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-light);
  text-transform: uppercase;
  padding: 0 6px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

/* Username input */
.sidebar input#username {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  padding: 9px 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar input#username::placeholder {
  color: var(--text-muted);
}

.sidebar input#username:focus {
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

.sidebar input#username:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Sidebar buttons */
.sidebar > button {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.sidebar > button::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  opacity: 0.6;
}

.sidebar > button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* "Public Chat" button — accent highlight */
.sidebar > button:nth-of-type(3) {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-light);
  font-weight: 600;
}

.sidebar > button:nth-of-type(3):hover {
  background: var(--accent);
  color: #fff;
}

/* AI button */
#pc {
  background: linear-gradient(135deg, #1d1535, #2d1f5e) !important;
  border-color: var(--accent-dim) !important;
  color: var(--accent-light) !important;
}

#pc:hover {
  background: linear-gradient(135deg, #2d1f5e, #3d2b7e) !important;
  color: #fff !important;
}

/* ── Admin Panel ── */
.admin-panel {
  display: none;
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  padding: 10px 8px;
  display: none;
  flex-direction: column;
  gap: 5px;
  margin-top: 4px;
}

.admin-panel button {
  width: 100%;
  background: rgba(192,65,90,0.12);
  border: 1px solid rgba(192,65,90,0.3);
  border-radius: var(--radius-sm);
  color: #e8748a;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.admin-panel button:hover {
  background: rgba(192,65,90,0.25);
  color: #f5a0af;
}

/* ── User List ── */
.user-list {
  flex: 1;
  overflow-y: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.user-list::before {
  content: "ONLINE USERS";
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 4px 6px 8px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.user-item::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}

.user-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ════════════════════════════════════════
   CHAT AREA
   ════════════════════════════════════════ */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100% !important;
  background: var(--bg-base);
  overflow: hidden;
  position: relative;
}

/* Subtle grid pattern background */
.chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(124,92,191,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124,92,191,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}

#logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#logo:active {
  transform: scale(0.85); /* Shrinks slightly when tapped */
}

/* Optional: Subtle glow on mobile to show it's interactive */
@media (max-width: 680px) {
  #logo {
    border: 2px solid var(--accent-light);
    box-shadow: 0 0 10px var(--accent-glow);
  }
}

#chat-title {
  font-family: 'Syne', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

/* Remove the <pre> spacer visually */
.header pre {
  display: none;
}

/* Online indicator on header */
.header::after {
  content: '● LIVE';
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #4ade80;
  margin-left: auto;
}

/* ── Chat Box ── */
#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 1;
}

/* ── Message Bubbles ── */
#chat-box > div {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  animation: msgIn 0.25s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Every bubble — base */
#chat-box > div > strong {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
  color: var(--accent-light);
  display: block;
  padding-left: 4px;
}

/* Bubble body — treat the entire div as a bubble */
#chat-box > div {
  background: var(--bubble-other);
  border: 1px solid var(--bubble-other-border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  align-self: flex-start;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-primary);
  position: relative;
  word-break: break-word;
}

/* Self messages — pushed right with purple bubble */
#chat-box > div:has(button) {
  align-self: flex-end;
  background: var(--bubble-self);
  border-color: var(--bubble-self-light);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
}

#chat-box > div:has(button) > strong {
  color: #d4b8ff;
  text-align: right;
}

/* ── Edit / Delete buttons ── */
#edidel {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  cursor: pointer;
  margin-left: 6px;
  transition: background 0.15s, color 0.15s;
  vertical-align: middle;
}

#edidel:first-of-type:hover {
  background: rgba(124,92,191,0.25);
  color: var(--accent-light);
  border-color: var(--accent);
}

#edidel:last-of-type:hover {
  background: var(--danger-dim);
  color: #e8748a;
  border-color: var(--danger);
}

/* ── Message Input Bar ── */
.chat-area > input#message {
  flex-shrink: 0;
  margin: 0 20px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  padding: 14px 100px 14px 18px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
  z-index: 2;
}

.chat-area > input#message::placeholder {
  color: var(--text-muted);
}

.chat-area > input#message:focus {
  border-color: var(--accent);
  box-shadow: var(--glow-accent);
}

/* ── Send Button ── */
#send {
  position: absolute;
  bottom: 24px;
  right: 28px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 10px 18px;
  cursor: pointer;
  z-index: 3;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

#send:hover {
  background: var(--accent-light);
  box-shadow: 0 4px 20px var(--accent-glow);
}

#send:active {
  transform: scale(0.95);
}

/* ════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════ */

@media (max-width: 680px) {
  :root { --sidebar-w: 190px; }

  #chat-box > div { max-width: 85%; }

  .header { padding: 0 14px; }
  #chat-box { padding: 14px 14px; }

  .chat-area > input#message {
    margin: 0 12px 12px;
    padding-right: 88px;
  }

  #send {
    right: 16px;
    bottom: 18px;
    padding: 9px 14px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .sidebar { display: none; }
  .chat-container { flex-direction: column; }
}






/* THE FINAL MOBILE FIX */
@media (max-width: 680px) {
    html, body {
        height: 100dvh !important;
        position: fixed !important;
        overflow: hidden !important;
    }

    .chat-container {
        height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important; /* Stacks header/box/input */
    }

    .chat-area {
        height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #chat-box {
        flex: 1 !important; /* This forces the messages to shrink for keyboard */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .chat-area > input#message {
        position: sticky !important; /* Anchors it to the bottom of the visible area */
        bottom: 10px !important;
        flex-shrink: 0 !important;
        margin: 10px !important;
        z-index: 100 !important;
    }

    #send {
        bottom: 20px !important;
        right: 20px !important;
        z-index: 101 !important;
    }
}






@media (max-width: 680px) {
  .sidebar {
    display: flex !important; /* Ensure it's not set to display: none */
    position: fixed;
    top: 0;
    left: -260px; /* Hide it exactly the width of the sidebar */
    width: 260px;
    height: 100dvh;
    z-index: 9999 !important; /* Force it to stay on top of everything */
    transition: transform 0.3s ease-in-out;
    background: #16161d; /* Solid color so it's visible */
  }

  /* We use transform for smoother performance on mobile */
  .sidebar.active {
    transform: translateX(260px);
  }
}