:root {
  --primary: #4f46e5; --primary-hover: #4338ca;
  --bg: #f8fafc; --desktop-bg: #e2e8f0; 
  --surface: #ffffff; --text: #0f172a; --text-muted: #64748b;
  --border: #e2e8f0; --success: #10b981; --danger: #ef4444;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

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

html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; overscroll-behavior-y: none; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--desktop-bg); color: var(--text); -webkit-font-smoothing: antialiased; display: flex; justify-content: center; align-items: flex-start; }
.app-frame { 
  width: 100%; max-width: 500px; height: 100dvh; 
  overflow-y: auto; 
  -webkit-overflow-scrolling: touch; /* THIS FIXES THE LAG! */
  background: var(--bg); position: relative; box-shadow: var(--shadow-lg); margin: 0 auto; 
}

.topbar { background: rgba(248, 250, 252, 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 900; }
.title { font-weight: 800; font-size: 22px; letter-spacing: -0.5px; background: linear-gradient(135deg, var(--primary), #818cf8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logoutBtn { background: #f1f5f9; color: var(--text-muted); border: none; padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 600; transition: all 0.2s; width: auto; }
.logoutBtn:hover { background: #fee2e2; color: var(--danger); }

/* NEW: Top Profile Button */
.profileBtn { background: #e0e7ff; color: var(--text); border: none; padding: 0; width: 36px; height: 36px; border-radius: 50%; font-size: 18px; display: flex; justify-content: center; align-items: center; transition: all 0.2s; cursor: pointer;}
.profileBtn:hover { background: #c7d2fe; transform: scale(1.05); }

.container { padding: 16px; padding-bottom: 100px; } 

.card { background: var(--surface); padding: 24px; border-radius: 24px; margin-bottom: 16px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); transition: transform 0.2s, box-shadow 0.2s; }
.card:hover { box-shadow: var(--shadow-md); }
h2, h3, h4 { margin-top: 0; font-weight: 700; letter-spacing: -0.5px; }

input, select, textarea { width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); margin-bottom: 12px; font-size: 15px; font-family: inherit; background: #f9fafb; resize: none; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1); background: var(--surface); }

button { width: 100%; padding: 14px; border-radius: 14px; border: none; background: var(--primary); color: white; font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer; transition: all 0.2s ease; display: flex; justify-content: center; align-items: center; gap: 8px; }
button:hover { background: var(--primary-hover); transform: translateY(-1px); }
button:active { transform: translateY(1px); }
.hidden { display: none !important; }

/* ==========================================
   BOTTOM NAVIGATION
   ========================================== */
.bottom-nav { position: fixed; bottom: 0; width: 100%; max-width: 500px; left: 50%; transform: translateX(-50%); background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--border); display: flex; justify-content: space-around; padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 950; }

.nav-item { 
  flex: 1; text-align: center; border: none; 
  color: #9ca3af; font-size: 12px; font-weight: 600; 
  display: flex; flex-direction: column; align-items: center; gap: 4px; 
  padding: 4px 0; width: auto; cursor: pointer;
  
  /* 🔥 THE FIX: Kills the dark mobile block, ensures background is clean */
  background: transparent; 
  -webkit-tap-highlight-color: transparent; 
  transition: color 0.2s ease; 
}

.nav-item i { font-size: 24px; transition: all 0.2s; }
.nav-item.active { color: var(--primary); background: transparent; box-shadow: none; }
.nav-item.active i { transform: translateY(-2px); }

/* 🔥 THE PREMIUM TAP EFFECT: Shrinks slightly only when your finger is on it */
.nav-item:active { opacity: 0.6; transform: scale(0.95); transition: all 0.1s ease; }

/* ==========================================
   DYNAMIC FEED FILTERS
   ========================================== */
.feed-filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 8px; -ms-overflow-style: none; scrollbar-width: none; flex-wrap: wrap; }
.feed-filters::-webkit-scrollbar { display: none; }
.filter-pill { background: var(--surface); color: var(--text-muted); padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; border: 1px solid var(--border); transition: all 0.2s; box-shadow: var(--shadow-sm); }
.filter-pill.active { background: var(--text); color: var(--surface); border-color: var(--text); }

.event-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.event-meta { font-size: 14px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.delete-btn { background: #fee2e2; color: var(--danger); margin-top: 16px; }
.delete-btn:hover { background: #fca5a5; }
.join { background: var(--success); margin-top: 16px; }
.leave-btn { background: #f1f5f9; color: var(--text-muted); margin-top: 16px; border: 1px solid var(--border); }
.leave-btn:hover { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }
/* Event Attendees Box (No stretching!) */
.attendees { 
  font-size: 13px; 
  color: var(--primary); 
  margin-top: 12px; 
  background: #e0e7ff; 
  padding: 8px 14px; 
  border-radius: 12px; 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  font-weight: 600;
  white-space: nowrap; /* Forces everything to stay on one line */
  overflow-x: auto; /* Adds a clean horizontal swipe scroller */
  -ms-overflow-style: none;  /* Hides ugly scrollbar on Windows */
  scrollbar-width: none;  /* Hides ugly scrollbar on Firefox */
}

/* Hides ugly scrollbar on Chrome/Safari */
.attendees::-webkit-scrollbar { display: none; }

.tag-selector { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 4px; -ms-overflow-style: none; scrollbar-width: none; }
.tag-selector::-webkit-scrollbar { display: none; }
.tag { background: #f1f5f9; color: var(--text-muted); padding: 8px 16px; border-radius: 20px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; border: 1px solid transparent; transition: all 0.2s; }
.tag.active { background: #e0e7ff; color: var(--primary); border-color: #c7d2fe; }

.event-tag-badge { display: inline-block; background: #f1f5f9; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
/* Event Description Fixes */
.event-desc-box { 
  max-height: 0; 
  overflow: hidden; 
  opacity: 0; 
  transition: all 0.3s ease; 
  background: #f8fafc; 
  border-radius: 12px; 
  padding: 0 12px; 
  margin-top: 0; 
  font-size: 14px; 
  color: #475569; 
  border-left: 3px solid var(--primary); 
}

.event.expanded .event-desc-box { 
  max-height: 250px; 
  opacity: 1; 
  padding: 12px; 
  margin-top: 12px; 
  overflow-y: auto; /* Adds a scrollbar if the text is huge */
  white-space: pre-wrap; /* Respects the enter key/paragraphs */
  word-wrap: break-word; /* Stops long links from breaking the box */
}
.read-more-btn { background: none; border: none; color: var(--primary); font-size: 13px; font-weight: 600; padding: 0; margin-top: 8px; justify-content: flex-start; width: auto; }
.read-more-btn:hover { background: none; text-decoration: underline; transform: none; }

.chat-item { padding: 16px; background: var(--surface); margin-bottom: 12px; border-radius: 16px; cursor: pointer; border: 1px solid var(--border); display: flex; align-items: center; gap: 14px; }
.chat-avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #a855f7); color: white; display: flex; justify-content: center; align-items: center; font-size: 18px; font-weight: 700; text-transform: uppercase; }
.chat-name { font-weight: 600; font-size: 16px; color: var(--text); }

#chatScreen { position: fixed; top: 0; bottom: 0; width: 100%; max-width: 500px; left: 50%; transform: translateX(-50%); height: 100dvh; background: var(--bg); display: flex; flex-direction: column; z-index: 1000; }
.chat-header { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(12px); padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.back-btn { background: #f1f5f9; color: var(--text); width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 20px; display: flex; justify-content: center; align-items: center; }
#messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 20px 16px; display: flex; flex-direction: column; }

/* ==========================================
   PREMIUM CHAT UI: DATES, TAILS, & INDICATORS
   ========================================== */
/* Normal inline dates - clean and natural */
.date-wrapper { text-align: center; margin: 24px 0 16px 0; }
.date-separator { font-size: 11px; font-weight: 700; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px; }

/* The Premium Floating Glass Badge (Hidden by default) */
.floating-date {
  position: absolute; top: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(248, 250, 252, 0.5);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  padding: 6px 16px; border-radius: 20px;
  font-size: 11px; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04); border: 1px solid rgba(255, 255, 255, 0.6);
  z-index: 50; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.floating-date.visible { opacity: 1; }

.msg-wrapper { display: flex; flex-direction: column; width: 100%; cursor: pointer; }
.msg-time { font-size: 11px; color: #94a3b8; max-height: 0; opacity: 0; overflow: hidden; transition: all 0.2s ease-out; padding: 0 4px; }
.msg-wrapper.show-time .msg-time { max-height: 20px; opacity: 1; margin-bottom: 8px; margin-top: 2px; }

.msg-bubble { padding: 10px 14px; font-size: 15px; font-weight: 500; max-width: 75%; word-wrap: break-word; line-height: 1.4; transition: all 0.2s; }

/* Smart Tails: Sent Messages (Smooth Pill Design) */
.msg-sent { background: var(--primary); color: white; align-self: flex-end; }
.msg-sent.single { border-radius: 20px 20px 20px 20px; margin-bottom: 12px; }
.msg-sent.first  { border-radius: 20px 20px 6px 20px; margin-bottom: 2px; }
.msg-sent.middle { border-radius: 20px 6px 6px 20px; margin-bottom: 2px; }
.msg-sent.last   { border-radius: 20px 6px 20px 20px; margin-bottom: 12px; }

/* Smart Tails: Received Messages (Smooth Pill Design) */
.msg-received { background: var(--surface); color: var(--text); border: 1px solid var(--border); align-self: flex-start; }
.msg-received.single { border-radius: 20px 20px 20px 20px; margin-bottom: 12px; }
.msg-received.first  { border-radius: 20px 20px 20px 6px; margin-bottom: 2px; }
.msg-received.middle { border-radius: 6px 20px 20px 6px; margin-bottom: 2px; }
.msg-received.last   { border-radius: 6px 20px 20px 20px; margin-bottom: 12px; }

/* Read Receipts & Typing Indicators */
.msg-status { font-size: 11px; color: var(--text-muted); align-self: flex-end; margin-top: -8px; margin-bottom: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }

.typing-indicator { display: flex; gap: 4px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px 20px 20px 4px; align-self: flex-start; margin-bottom: 12px; width: fit-content; box-shadow: var(--shadow-sm); }
.typing-dot { width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%; animation: typing 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0.5); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* Premium Pulsing Unread Dot */
/* Premium, Tiny Pulsing Unread Dot (Chat List) */
.unread-pulse-dot {
  width: 8px; 
  height: 8px; 
  min-width: 8px; 
  background: var(--danger); 
  border-radius: 50%; 
  margin-left: auto; 
  flex-shrink: 0; 
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  /* Reduced the shadow spread from 6px down to 4px for a softer glow */
  70% { transform: scale(1); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

@keyframes pulse-red {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.chat-footer { background: var(--surface); padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.chat-footer input { margin-bottom: 0; flex: 1; border-radius: 24px; padding: 14px 20px; }
.chat-footer button { width: 50px; height: 50px; border-radius: 50%; padding: 0; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100dvh; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; padding: 16px; z-index: 2000; }
.modal-content { background: var(--surface); padding: 24px; border-radius: 24px; width: 100%; max-width: 400px; max-height: 85dvh; overflow-y: auto; text-align: center; animation: slideUp 0.3s ease-out; }
.modal-content button { margin-top: 12px; }

/* NEW: AVATAR MODAL STYLES */
.avatar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.avatar-option { font-size: 36px; padding: 12px; background: #f8fafc; border-radius: 16px; cursor: pointer; border: 3px solid transparent; transition: all 0.2s; }
.avatar-option:hover { transform: scale(1.1); }
.avatar-option.selected { border-color: var(--primary); background: #e0e7ff; }

.time-stack { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; width: 100%; }
input[type="datetime-local"] { width: 100%; max-width: 100%; padding: 14px 16px; font-size: 15px; margin-top: 4px; margin-bottom: 0; -webkit-appearance: none; appearance: none; box-sizing: border-box; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state i { font-size: 48px; color: #cbd5e1; margin-bottom: 12px; }

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

#profileScreen { 
  position: absolute; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  background: var(--bg); 
  display: flex; 
  flex-direction: column; 
  z-index: 2000; 
}
#myProfileEvents .event { margin-bottom: 12px; }

#loading-screen {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  z-index: 9999;
}

.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  width: 40px; height: 40px;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Tiny, Elegant Nav Badge for Bottom Menu */
.nav-badge { 
  position: absolute; 
  top: 2px; 
  right: calc(50% - 14px); 
  width: 8px; 
  height: 8px; 
  background: var(--danger); 
  border-radius: 50%; 
  /* Uses a 1.5px border to create a clean cutout effect over the icon */
  border: 1.5px solid var(--bg); 
  animation: pulse-red 2s infinite; 
  z-index: 10;
}

/* ==========================================
   SMART REPLY SYSTEM
   ========================================== */
/* The quoted message sitting inside the new bubble */
.msg-replied-to { 
  font-size: 12px; 
  background: rgba(0, 0, 0, 0.06); 
  padding: 6px 10px; 
  border-radius: 10px; 
  margin-bottom: 6px; 
  color: var(--text-muted); 
  display: -webkit-box; 
  -webkit-line-clamp: 1; 
  -webkit-box-orient: vertical; 
  overflow: hidden; 
  border-left: 3px solid rgba(0, 0, 0, 0.2);
}

/* If the reply is inside a blue 'Sent' bubble, make it look white/glassy */
.msg-sent .msg-replied-to { 
  background: rgba(255, 255, 255, 0.2); 
  color: rgba(255, 255, 255, 0.9); 
  border-left: 3px solid white;
}

/* The Reply action button next to the timestamp */
.reply-action-btn {
  background: #e0e7ff; color: var(--primary);
  border: none; padding: 4px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 700; cursor: pointer;
  margin-left: 8px; display: inline-flex; align-items: center; gap: 4px;
}

/* Obliterate the mobile tap highlight bug globally */
* { -webkit-tap-highlight-color: transparent; }
.msg-wrapper, .msg-bubble { outline: none !important; }

/* ==========================================
   SWIPE-TO-REPLY UI (FIXED FOR DESKTOP & MOBILE)
   ========================================== */
/* touch-action: pan-y kills the browser's horizontal screen-slide bug */
.msg-wrapper { position: relative; touch-action: pan-y; } 

.swipe-reply-icon {
  position: absolute; top: 50%; transform: translateY(-50%) scale(0.5);
  opacity: 0; width: 30px; height: 30px;
  background: #e0e7ff; color: var(--primary); border-radius: 50%;
  display: flex; justify-content: center; align-items: center;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 0;
}

/* Received messages pull right, icon sits on the left */
.swipe-reply-icon.left { left: -40px; right: auto; }
/* Sent messages pull left, icon sits on the right */
.swipe-reply-icon.right { right: -40px; left: auto; }

.msg-wrapper.ready-to-reply .swipe-reply-icon {
  opacity: 1; transform: translateY(-50%) scale(1);
}

/* ==========================================
   HIGH-CONTRAST PULSE SYSTEM
   ========================================== */

/* Received (White Bubble): Pulse with a deep, bold Purple */
.msg-bubble.flash-received {
  animation: pulseReceived 1.5s ease-out forwards;
}

@keyframes pulseReceived {
  0% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(79, 70, 229, 0.4); }
  100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

/* Sent (Purple Bubble): Pulse with a Luminous Cyan-Blue */
.msg-bubble.flash-sent {
  animation: pulseSent 1.5s ease-out forwards;
  z-index: 10; /* Force it to the front */
  overflow: visible !important; /* Ensure the shadow can escape the bubble */
}

@keyframes pulseSent {
  0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.7); } /* Vibrant Cyan */
  50% { box-shadow: 0 0 0 10px rgba(34, 211, 238, 0.5); } /* Stronger spread */
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}

/* Ensure the container is a stack */
#replyPreviewContainer {
    width: 100%;
    margin-bottom: 8px; /* Spacing between reply bar and input */
    flex-shrink: 0;
}

/* The input wrapper */
.input-wrapper {
    display: flex;
    gap: 10px;
    width: 100%;
    align-items: center;
}

.reply-preview-bar {
    background: rgba(79, 70, 229, 0.1); 
    padding: 8px 12px; 
    border-radius: 12px; 
    border-left: 4px solid var(--primary); 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    width: 100%;
}
