:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #eee;
  --muted: #888;
  --green: #22c55e;
  --gold: #fbbf24;
  --blue: #60a5fa;
  --border: #2a2a40;
  --radius: 14px;
  --nav-h: 60px;
  --header-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  position: relative;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.screen { display: none; flex-direction: column; height: 100%; width: 100%; }
.screen.active { display: flex; }

/* AUTH */
.auth-container {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 1.5rem; gap: 1rem;
}
.logo { text-align: center; margin-bottom: 1rem; }
.logo h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: 3px; color: var(--accent); }
.logo p { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }
.auth-tabs { display: flex; background: var(--card); border-radius: 10px; padding: 4px; }
.auth-tab { flex: 1; border: none; background: transparent; color: var(--muted); padding: 0.7rem; font-size: 1rem; border-radius: 8px; cursor: pointer; }
.auth-tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.auth-form { display: none; flex-direction: column; gap: 0.75rem; }
.auth-form.active { display: flex; }

input[type="text"], input[type="password"], input[type="email"] {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.9rem 1rem; color: var(--text); font-size: 1rem; width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  border: none; border-radius: 10px; padding: 0.9rem 1.2rem; font-size: 1rem;
  font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.btn:active { opacity: 0.85; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: #b91c1c; color: #fff; }
.btn.small { padding: 0.6rem 1rem; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-link { background: none; border: none; color: var(--blue); font-size: 0.85rem; cursor: pointer; text-decoration: underline; padding: 0.25rem; }

.auth-msg { font-size: 0.85rem; color: #f87171; min-height: 1.2em; text-align: center; }

/* SELFIE */
.selfie-container { flex: 1; display: flex; flex-direction: column; padding: 1rem; gap: 0.75rem; overflow: auto; }
.selfie-container h2 { text-align: center; }
.hint { text-align: center; color: var(--muted); font-size: 0.85rem; }
.register-hint { color: var(--gold); font-size: 0.8rem; }
.camera-wrap { position: relative; width: 100%; aspect-ratio: 3/4; max-height: 55vh; background: #000; border-radius: var(--radius); overflow: hidden; }
#camera, #preview, #snapshot { width: 100%; height: 100%; object-fit: cover; }
.camera-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.hidden { display: none !important; }

/* MAIN */
.app-header {
  height: var(--header-h); display: flex; align-items: center;
  justify-content: space-between; padding: 0 0.75rem; background: var(--card);
  border-bottom: 1px solid var(--border); flex-shrink: 0; z-index: 10;
}
.brand { font-weight: 800; letter-spacing: 1px; color: var(--accent); font-size: 1rem; }
.icon-btn { background: transparent; border: none; color: var(--text); font-size: 1.3rem; padding: 0.4rem; cursor: pointer; line-height: 1; position: relative; }

.notif-badge {
  position: absolute; top: 0; right: 0; background: var(--accent); color: #fff;
  font-size: 0.6rem; min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px; font-weight: 700;
}

.view { display: none; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }
.view.active { display: flex; }
.view-header { padding: 0.6rem 0.75rem; background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.view-header h3 { font-size: 1rem; }

/* CHAT TABS */
.chat-tabs-bar {
  background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.chat-tabs-bar::-webkit-scrollbar { display: none; }
.chat-tabs-scroll { display: flex; gap: 0; min-width: 100%; }
.chat-tab {
  flex-shrink: 0; padding: 0.5rem 1rem; font-size: 0.85rem; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; color: var(--muted); background: none; border-top: none; border-left: none; border-right: none;
}
.chat-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.chat-tab .close-tab { margin-left: 0.4rem; color: var(--muted); font-size: 0.8rem; cursor: pointer; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; -webkit-overflow-scrolling: touch; }
.msg { max-width: 85%; padding: 0.55rem 0.8rem; border-radius: 12px; background: var(--card); align-self: flex-start; word-break: break-word; }
.msg.mine { background: var(--accent2); align-self: flex-end; }
.msg .meta { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.15rem; }
.msg .meta .name { color: var(--accent); font-weight: 600; cursor: pointer; }
.msg .meta .name:active { opacity: 0.7; }

.chat-input-bar { display: flex; align-items: center; gap: 0.4rem; padding: 0.5rem 0.6rem; background: var(--card); border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); }
.chat-input-bar input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 0.6rem 1rem; color: var(--text); font-size: 0.95rem; outline: none; }

.emoji-picker { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0.5rem; background: var(--card); border-top: 1px solid var(--border); max-height: 120px; overflow-y: auto; flex-shrink: 0; }
.emoji-picker span { font-size: 1.4rem; padding: 0.25rem; cursor: pointer; }

/* Empty view */
.empty-view { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.empty-state .sub { font-size: 0.85rem; margin-top: 0.4rem; }

.code-input-wrap { margin: 1rem 0; }
.code-input-wrap input { max-width: 180px; margin: 0 auto; text-align: center; font-size: 1.8rem; letter-spacing: 8px; }

/* Users panel */
.users-panel {
  position: absolute; top: var(--header-h); left: 0; right: 0; bottom: var(--nav-h);
  background: var(--bg); z-index: 20; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.25s ease;
}
.users-panel.open { transform: translateX(0); }
.users-panel-header { display: flex; align-items: center; padding: 0.6rem 0.75rem; background: var(--card); border-bottom: 1px solid var(--border); gap: 0.5rem; }
.users-panel-header h3 { flex: 1; font-size: 1rem; }
.users-list { flex: 1; overflow-y: auto; padding: 0.5rem; }
.user-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0.5rem; border-radius: 10px; cursor: pointer; }
.user-row:active { background: var(--card); }
.user-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--border); flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-info .uname { font-weight: 600; display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; flex-shrink: 0; }
.user-info .last { font-size: 0.75rem; color: var(--muted); }

.like-badge { display: inline-block; background: var(--accent); color: #fff; font-size: 0.65rem; padding: 0.15rem 0.4rem; border-radius: 6px; margin-left: 0.3rem; flex-shrink: 0; }

/* Matches */
.friends-list { flex: 1; overflow-y: auto; padding: 0.75rem; }
.friend-card, .match-card { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; background: var(--card); border-radius: 12px; margin-bottom: 0.5rem; cursor: pointer; position: relative; }
.friend-card img, .match-card img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.friend-card .unread-dot, .match-card .unread-dot { position: absolute; top: 10px; left: 10px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--card); z-index: 1; }
.friend-card .info, .match-card .info { flex: 1; }
.friend-card .info h4, .match-card .info h4 { font-size: 1rem; display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.friend-card .info p, .match-card .info p { font-size: 0.75rem; color: var(--muted); }
.match-flair { font-size: 0.7rem; color: var(--accent); font-weight: 600; }
.friend-badge { font-size: 0.7rem; color: var(--green); font-weight: 600; }

#view-friends { flex: 1; display: none; flex-direction: column; min-height: 0; }
#view-friends.active { display: flex; }

/* Events */
.events-scroll { flex: 1; overflow-y: auto; padding: 0.75rem; -webkit-overflow-scrolling: touch; }
.event-card { background: var(--card); border-radius: 12px; margin-bottom: 0.75rem; overflow: hidden; cursor: pointer; }
.event-card img { width: 100%; aspect-ratio: 9/16; object-fit: cover; background: var(--border); max-height: 200px; }
.event-card .event-info { padding: 0.75rem; }
.event-card .event-info h4 { font-size: 1rem; margin-bottom: 0.25rem; }
.event-card .event-info .event-date { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; }
.event-card .event-info .event-desc { font-size: 0.85rem; color: #ccc; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.event-card .event-info .event-rsvp-badge { display: inline-block; font-size: 0.7rem; color: var(--green); margin-top: 0.3rem; }

.event-detail-header { position: relative; margin: -1rem -1rem 1rem -1rem; }
.event-detail-header img { width: 100%; aspect-ratio: 9/16; object-fit: cover; max-height: 300px; background: var(--border); }
.event-detail-info h2 { font-size: 1.4rem; margin-bottom: 0.3rem; }
.event-detail-info .event-date { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.5rem; }
.event-detail-info .event-desc { color: #ccc; font-size: 0.95rem; line-height: 1.5; margin-bottom: 1rem; }
.event-detail-info .spots-left { color: var(--gold); font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }
.event-detail-info .sold-out { color: var(--accent); font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }
.event-detail-info .my-rsvp { color: var(--green); font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }

/* Private */
.private-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.75rem; background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.private-header span { font-weight: 600; }

/* Modals */
.modal {
  position: absolute; inset: 0; background: rgba(0,0,0,0.7); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-content {
  background: var(--card); border-radius: 20px 20px 0 0; padding: 1.25rem;
  width: 100%; max-height: 85%; overflow-y: auto; position: relative; animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.close-modal { position: absolute; top: 0.75rem; right: 0.75rem; background: transparent; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.modal-content img { width: 140px; height: 140px; border-radius: 50%; object-fit: cover; display: block; margin: 0.5rem auto 1rem; background: var(--border); }
.modal-content h3 { text-align: center; margin-bottom: 0.25rem; }
.modal-content .detail-meta { text-align: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 1rem; }
.detail-actions { display: flex; gap: 0.5rem; align-items: center; }
.detail-actions .btn:not(.icon-btn) { flex: 1; }
.detail-actions .icon-btn { font-size: 1.8rem; padding: 0.4rem; flex-shrink: 0; }

/* FLAIRS */
.flair-owner { font-size: 1.1rem; }
.flair-admin { color: var(--gold); font-weight: 700; font-size: 1rem; }
.flair-rrpp { background: #6366f1; color: #fff; font-size: 0.6rem; padding: 1px 5px; border-radius: 4px; font-weight: 700; letter-spacing: 0.5px; }
.flair-staff { background: #8b5cf6; color: #fff; font-size: 0.6rem; padding: 1px 5px; border-radius: 4px; font-weight: 700; letter-spacing: 0.5px; }
.flair-vip { background: #f59e0b; color: #000; font-size: 0.6rem; padding: 1px 5px; border-radius: 4px; font-weight: 700; letter-spacing: 0.5px; }
.tick-blue { color: #3b82f6; font-weight: 700; font-size: 0.85rem; margin-left: 1px; }

/* Profile form */
.profile-form { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }

/* Como funciona */
.como-funciona-content p { font-size: 0.9rem; line-height: 1.5; color: #ccc; margin-bottom: 0.75rem; }

/* Bottom nav */
.bottom-nav { height: var(--nav-h); display: flex; background: var(--card); border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: env(safe-area-inset-bottom); }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: transparent; border: none; color: var(--muted); font-size: 0.7rem; cursor: pointer; position: relative; }
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 1.35rem; }
.nav-badge { position: absolute; top: 2px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.welcome-banner { padding: 0.6rem 0.75rem; background: var(--accent2); color: var(--text); font-size: 0.85rem; text-align: center; flex-shrink: 0; transition: opacity 0.5s; }
.welcome-banner.fadeout { opacity: 0; }
.events-banner { padding: 0.75rem; background: var(--card); border-radius: 10px; margin-bottom: 0.75rem; text-align: center; font-size: 0.85rem; color: var(--muted); }

/* Notifications list */
.notif-item { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.notif-item.unread { opacity: 1; }
.notif-item.read { opacity: 0.5; }
.notif-item .notif-icon { font-size: 1.2rem; flex-shrink: 0; }
.notif-item .notif-text { font-size: 0.85rem; line-height: 1.3; }
.notif-item .notif-time { font-size: 0.7rem; color: var(--muted); }

/* Message with photo */
.msg { display: flex; gap: 0.4rem; align-items: flex-start; }
.msg-photo, .msg-photo-placeholder { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-top: 0.1rem; }
.msg-photo-placeholder { background: var(--border); }
.msg .msg-body { min-width: 0; }
.msg.mine .msg-photo { display: none; }
.msg.mine .msg-body { width: 100%; }


/* Check-in view */
#chat-checkin { flex: 1; display: none; align-items: center; justify-content: center; padding: 1.5rem; }
#chat-checkin:not(.hidden) { display: flex; }
.checkin-content { text-align: center; max-width: 320px; }
.checkin-content h3 { margin-bottom: 0.5rem; }
.checkin-content h4 { margin: 0.5rem 0; color: var(--accent); }
.checkin-content .hint { margin-bottom: 0.5rem; line-height: 1.4; }
#checkin-selfie-area { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
#btn-start-selfie-checkin { margin-top: 0.5rem; }

/* Check-in user detail layout */
.checkin-img-wrap { position: relative; width: 100%; aspect-ratio: 9/16; max-height: 300px; background: var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 0.75rem; }
.checkin-img-wrap .checkin-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.checkin-time { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,0.8)); color: #fff; font-size: 0.75rem; padding: 1.5rem 0.75rem 0.5rem; text-align: center; }
.checkin-user-info { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; padding: 0 0.5rem; }
.checkin-user-photo { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--border); flex-shrink: 0; }
.checkin-user-info div { min-width: 0; }
.checkin-user-info h3 { text-align: left; margin: 0; font-size: 1rem; }
.checkin-user-info .detail-meta { text-align: left; }
