:root {
  --bg: #1A1410;
  --bg-2: #221a14;
  --bg-3: #2a201a;
  --amber: #E8A547;
  --amber-soft: rgba(232, 165, 71, 0.12);
  --text: #F5EBE0;
  --text-muted: rgba(245, 235, 224, 0.6);
  --text-dim: rgba(245, 235, 224, 0.4);
  --border: rgba(245, 235, 224, 0.08);
  --border-strong: rgba(245, 235, 224, 0.18);
  --green: #5DCAA5;
  --coral: #F0997B;
  --purple: #AFA9EC;
  --pink: #ED93B1;

  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Manrope', system-ui, sans-serif;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: var(--amber); text-decoration: none; }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: 80px;
}

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
}
.loader-text {
  font-family: var(--mono);
  color: var(--amber);
  font-size: 24px;
  font-weight: 500;
}
.loader-bar {
  width: 120px;
  height: 2px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
}
.loader-fill {
  width: 40%;
  height: 100%;
  background: var(--amber);
  animation: load 1s ease-in-out infinite;
}
@keyframes load {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 16px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 80%, transparent);
  z-index: 10;
  backdrop-filter: blur(12px);
}
.logo {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--amber);
}
.logo-sub {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--sans);
  font-weight: 400;
  margin-top: 2px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  flex-shrink: 0;
}

/* Section header */
.section-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  padding: 8px 20px 12px;
}
.section-label::before {
  content: '// ';
  color: var(--amber);
  opacity: 0.5;
}

/* Meetup list */
.meetup-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 20px;
}

.meetup-card {
  background: var(--bg-2);
  border: 0.5px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  transition: transform 0.15s ease, border-color 0.2s ease;
  cursor: pointer;
}
.meetup-card:active { transform: scale(0.98); }
.meetup-card.live {
  background: var(--amber-soft);
  border-color: rgba(232, 165, 71, 0.4);
}

.meetup-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--amber);
}
.meetup-card:not(.live) .meetup-meta { color: var(--text-muted); }

.badge-live {
  background: rgba(93, 202, 165, 0.15);
  color: var(--green);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-live::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.meetup-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.3;
}
.meetup-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 14px;
}

.meetup-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.attendees {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
}
/* Стек аватарок — кожен наступний наїжджає на попередній */
.attendees .attendee-stack-item {
  margin-left: -8px;
}
.attendees .attendee-stack-item:first-child {
  margin-left: 0;
}
/* Число "7/10" і інші елементи поряд зі стеком */
.attendees .attendee-count,
.attendees .msg-count {
  margin-left: 8px;
}
/* Застарілий стиль — не використовується. Лишаю для зворотньої сумісності з картою попапів. */
.attendee-pill {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 10px;
  flex-shrink: 0;
}

.attendee-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn {
  background: transparent;
  color: var(--amber);
  border: 0.5px solid var(--amber);
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--amber);
  color: var(--bg);
}
.btn-joined {
  background: rgba(93, 202, 165, 0.15);
  color: var(--green);
  border-color: rgba(93, 202, 165, 0.4);
}

/* Create button */
.create-card {
  border: 0.5px dashed rgba(232, 165, 71, 0.4);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 13px;
  margin: 4px 20px 0;
  background: transparent;
  width: calc(100% - 40px);
  transition: all 0.2s ease;
}
.create-card:active {
  background: var(--amber-soft);
  transform: scale(0.99);
}

/* Bottom nav */
.nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: rgba(26, 20, 16, 0.92);
  backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 6px 16px;
  transition: color 0.15s ease;
}
.nav-item.active { color: var(--amber); }
.nav-icon {
  width: 22px;
  height: 22px;
}

/* Profile */
.profile-hero {
  text-align: center;
  padding: 24px 20px 28px;
}
.profile-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 28px;
  margin: 0 auto 14px;
}
.profile-name {
  font-size: 18px;
  font-weight: 600;
}
.profile-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 20px 20px;
}
.stat-card {
  background: var(--bg-2);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
}
.stat-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--amber);
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 20px 20px;
}
.tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-muted);
}
.tag.amber { background: rgba(232, 165, 71, 0.15); color: var(--amber); }
.tag.green { background: rgba(93, 202, 165, 0.15); color: var(--green); }
.tag.coral { background: rgba(240, 153, 123, 0.15); color: var(--coral); }
.tag.purple { background: rgba(175, 169, 236, 0.15); color: var(--purple); }

.achievements {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 20px 20px;
}
.achievement {
  background: var(--bg-2);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
}
.achievement.locked { opacity: 0.35; }
.achievement-icon {
  font-size: 22px;
  margin-bottom: 6px;
}
.achievement-label {
  font-size: 11px;
  font-weight: 500;
}

/* Modal / sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: 480px;
  background: var(--bg-2);
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(28px + env(safe-area-inset-bottom));
  z-index: 95;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 85vh;
  overflow-y: auto;
}
.sheet.open { transform: translateX(-50%) translateY(0); }
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 8px auto 16px;
}
.sheet-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}
.sheet-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.field {
  margin-bottom: 14px;
}
.field-label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  background: var(--bg);
  border: 0.5px solid var(--border-strong);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--amber);
}
.field textarea { resize: vertical; min-height: 70px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-block {
  width: 100%;
  padding: 14px;
  font-size: 14px;
  border-radius: 12px;
  margin-top: 10px;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 36px;
  margin-bottom: 10px;
  opacity: 0.5;
}

/* Detail view */
.detail-back {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 8px;
  margin: 0 12px;
  border-radius: 8px;
}
.detail-back:active { background: var(--bg-2); }

.detail-hero {
  padding: 20px;
}
.detail-when {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--amber);
  margin-bottom: 8px;
}
.detail-title {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 10px;
}
.detail-where {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.detail-desc {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  padding: 16px 20px;
  border-top: 0.5px solid var(--border);
  border-bottom: 0.5px solid var(--border);
  margin: 8px 0;
}

.detail-attendees {
  padding: 16px 20px;
}
.attendee-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-radius: 10px;
  margin: 0 -8px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.attendee-row.clickable {
  cursor: pointer;
}
.attendee-row.clickable:active {
  background: var(--bg-2);
  transform: scale(0.99);
}
@media (hover: hover) {
  .attendee-row.clickable:hover {
    background: var(--bg-2);
  }
}
.attendee-info { flex: 1; min-width: 0; }
.attendee-name { font-size: 14px; font-weight: 500; }
.attendee-stack {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attendee-chevron {
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  padding-right: 4px;
  flex-shrink: 0;
}

.detail-actions {
  position: sticky;
  bottom: 76px;
  padding: 14px 20px;
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-3);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  border: 0.5px solid var(--border-strong);
  font-size: 13px;
  font-family: var(--mono);
  z-index: 200;
  opacity: 0;
  transition: all 0.25s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Auth screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px 24px;
  text-align: center;
}
.auth-logo {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 500;
  color: var(--amber);
  margin-bottom: 8px;
}
.auth-tag {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 48px;
  max-width: 280px;
}
.auth-emoji {
  font-size: 64px;
  margin-bottom: 24px;
}
.auth-btn {
  background: var(--amber);
  color: var(--bg);
  padding: 14px 28px;
  border-radius: 12px;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 14px;
  width: 100%;
  max-width: 300px;
}

.hidden { display: none !important; }

/* ==== Редагування профілю ==== */

.grade-selector {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.grade-btn {
  flex: 1;
  min-width: 0;
  padding: 10px 6px;
  background: var(--bg);
  border: 0.5px solid var(--border-strong);
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  transition: all 0.15s ease;
}
.grade-btn.active {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber);
}
.grade-btn:active {
  transform: scale(0.97);
}

.tag-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--bg);
  border: 0.5px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px;
  min-height: 46px;
}
.tag-editor:focus-within {
  border-color: var(--amber);
}
.tag-input {
  flex: 1;
  min-width: 80px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--text);
  padding: 4px 6px;
}
.tag-input::placeholder {
  color: var(--text-dim);
}

.tag.removable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease;
}
.tag.removable:active {
  opacity: 0.6;
}
.tag-x {
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}

.tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.tag-suggest {
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: transparent;
  border: 0.5px dashed var(--border-strong);
  color: var(--text-muted);
  transition: all 0.15s ease;
}
.tag-suggest:active {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber);
  transform: scale(0.97);
}

/* ==== Кнопка edit у шапці деталей ==== */
.header-action {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--amber);
  padding: 6px 12px;
  border-radius: 8px;
  margin-right: 12px;
}
.header-action:active {
  background: var(--amber-soft);
}

.author-badge {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--amber);
  background: var(--amber-soft);
  padding: 3px 10px;
  border-radius: 999px;
}

/* ==== Кнопка delete (червонувата) ==== */
.btn-danger {
  background: transparent;
  border: 0.5px solid rgba(237, 147, 177, 0.4);
  color: var(--pink);
  margin-top: 8px;
}
.btn-danger:active {
  background: rgba(237, 147, 177, 0.08);
}

/* ==== Pull-to-refresh ==== */

#pull-indicator {
  position: fixed;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  background: var(--bg-2);
  border: 0.5px solid var(--border-strong);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
  pointer-events: none;
}
#pull-indicator.ready {
  border-color: var(--amber);
}
#pull-indicator.refreshing .pull-spinner {
  animation: pull-spin 0.8s linear infinite;
}
.pull-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--amber);
  border-radius: 50%;
}
#pull-indicator.ready .pull-spinner {
  border-top-color: var(--amber);
  border-color: var(--amber-soft);
}
@keyframes pull-spin {
  to { transform: rotate(360deg); }
}

/* ==== Карта ==== */

.map-screen {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh; /* для мобільних з адресною стрічкою */
  display: flex;
  flex-direction: column;
}

#map-container {
  flex: 1;
  width: 100%;
  background: var(--bg-2);
  /* Перекриваємо нижню навігацію — тоді мапа доходить до самого низу екрана */
  margin-top: 64px;
  margin-bottom: 80px;
}

.map-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-2);
  border: 0.5px solid var(--border-strong);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  z-index: 1000;
  pointer-events: none;
  max-width: 320px;
}

.map-counter {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 20, 16, 0.92);
  backdrop-filter: blur(10px);
  border: 0.5px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  z-index: 999;
}

/* Маркер — бурштинова крапка з ореолом */
.pivo-marker {
  background: transparent;
  border: none;
}
.pivo-marker-dot {
  width: 18px;
  height: 18px;
  background: var(--amber);
  border: 3px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(232, 165, 71, 0.4), 0 2px 6px rgba(0, 0, 0, 0.6);
  margin: 3px;
  animation: marker-pulse 2.5s ease-in-out infinite;
}
@keyframes marker-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(232, 165, 71, 0.4), 0 2px 6px rgba(0, 0, 0, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(232, 165, 71, 0.15), 0 2px 6px rgba(0, 0, 0, 0.6); }
}

/* Перекидаємо стиль попапа під наш темний дизайн */
.leaflet-popup-content-wrapper {
  background: var(--bg-2) !important;
  color: var(--text) !important;
  border: 0.5px solid var(--border-strong);
  border-radius: 12px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6) !important;
}
.leaflet-popup-content {
  margin: 14px !important;
  font-family: var(--sans);
}
.leaflet-popup-tip {
  background: var(--bg-2) !important;
  border: 0.5px solid var(--border-strong);
}
.leaflet-container a {
  color: var(--amber);
}

.pivo-popup-when {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--amber);
  margin-bottom: 4px;
}
.pivo-popup-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--text);
}
.pivo-popup-place {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.pivo-popup-btn {
  background: var(--amber);
  color: var(--bg);
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
}

/* Темізуємо контролі Leaflet */
.leaflet-control-zoom a {
  background: var(--bg-2) !important;
  color: var(--text) !important;
  border-color: var(--border-strong) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-3) !important;
}
.leaflet-control-attribution {
  background: rgba(26, 20, 16, 0.7) !important;
  color: var(--text-dim) !important;
  font-size: 9px !important;
  backdrop-filter: blur(4px);
}
.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

/* ==== Міні-карта в деталях ==== */
.detail-map-wrap {
  position: relative;
  margin: 0 20px 16px;
}
#detail-map-container {
  width: 100%;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  border: 0.5px solid var(--border);
}
.detail-map-open {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(26, 20, 16, 0.85);
  backdrop-filter: blur(8px);
  color: var(--amber) !important;
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none !important;
  border: 0.5px solid var(--border-strong);
  z-index: 401;
}

/* ==== Чат у деталях зустрічі ==== */

.msg-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-3);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}

.chat-list {
  padding: 8px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 85%;
}
.chat-msg.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  margin-bottom: 2px;
}

.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-author {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-left: 12px;
  cursor: pointer;
}
.chat-author:active { opacity: 0.6; }

.chat-bubble {
  background: var(--bg-2);
  border: 0.5px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 8px 12px 6px;
}
.chat-msg.mine .chat-bubble {
  background: var(--amber-soft);
  border-color: rgba(232, 165, 71, 0.3);
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}

.chat-text {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.chat-delete {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  border-radius: 4px;
}
.chat-delete:active {
  background: rgba(237, 147, 177, 0.15);
  color: var(--pink);
}

.chat-form {
  position: sticky;
  bottom: 76px;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
  z-index: 5;
}

.chat-input {
  flex: 1;
  background: var(--bg-2);
  border: 0.5px solid var(--border-strong);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  color: var(--text);
}
.chat-input:focus { border-color: var(--amber); }

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--bg);
  border: none;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-send:active { transform: scale(0.94); }

/* ==== Аватарки (img або ініціали) ==== */

.avatar-img {
  border-radius: 50%;
  object-fit: cover;
  display: block;
  background: var(--bg-3);
}

.avatar-initials {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 500;
  flex-shrink: 0;
}

.avatar-btn {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-btn:active { transform: scale(0.95); }

/* Стек учасників у feed-картці — modifier "stack" на самому аватарі */
.attendees .stack {
  margin-left: -8px;
  border: 2px solid var(--bg-2);
  box-sizing: border-box;
  vertical-align: middle;
}
.attendees .stack:first-child {
  margin-left: 0;
}
.meetup-card.live .attendees .stack { border-color: #2a1f15; }

/* +N бейдж у тому самому ряду */
.stack-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--bg-2);
  box-sizing: border-box;
  background: var(--bg-3);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  margin-left: -8px;
  vertical-align: middle;
  flex-shrink: 0;
}
.meetup-card.live .stack-more { border-color: #2a1f15; }

/* Профіль — обгортка з кнопкою зміни */
.profile-avatar-wrap {
  position: relative;
  display: inline-block;
  margin: 0 auto 14px;
}
.profile-avatar-wrap .avatar-img,
.profile-avatar-wrap .avatar-initials {
  display: block;
}
.avatar-change-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--bg);
  border: 3px solid var(--bg);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.avatar-change-btn:active { transform: scale(0.92); }

/* Прибираємо стару profile-avatar (тепер render через wrap) */

/* Чат — слот для аватара */
.chat-avatar-slot {
  flex-shrink: 0;
  margin-bottom: 2px;
}
.chat-avatar-slot .avatar-img,
.chat-avatar-slot .avatar-initials {
  border-radius: 50%;
}

/* ==== Альбом ==== */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 16px 24px;
}

.photo-tile {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg-2);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}
.photo-tile:active img { transform: scale(0.97); }

.photo-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(26, 20, 16, 0.85);
  color: var(--text);
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-delete:active {
  background: rgba(237, 147, 177, 0.9);
}

.photo-upload-btn {
  aspect-ratio: 1;
  background: transparent;
  border: 0.5px dashed rgba(232, 165, 71, 0.5);
  color: var(--amber);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.photo-upload-btn:active {
  background: var(--amber-soft);
  transform: scale(0.97);
}

/* ==== Lightbox ==== */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadein 0.2s ease;
}
@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lightbox img {
  max-width: 100%;
  max-height: 100vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
}

.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(26, 20, 16, 0.6);
  color: var(--text);
  border: 0.5px solid var(--border-strong);
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.lightbox-author {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 20, 16, 0.7);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

/* ==== Версія додатку у профілі ==== */
.version-tag {
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 8px 20px 24px;
  letter-spacing: 0.5px;
}

/* ==== Telegram логін ==== */

.auth-tg-container {
  display: flex;
  justify-content: center;
  margin: 20px 0 12px;
  min-height: 50px;
  align-items: center;
}

.auth-link-old {
  margin-top: 4px;
  text-align: center;
}

.auth-text-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
  text-decoration: underline;
  text-decoration-color: rgba(232, 165, 71, 0.4);
  cursor: pointer;
  padding: 8px;
}
.auth-text-btn:active { color: var(--amber); }

.auth-foot {
  position: absolute;
  bottom: 32px;
  left: 24px;
  right: 24px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

/* ==== Кнопка Telegram у профілі ==== */

.btn-tg {
  background: linear-gradient(135deg, #2AABEE, #229ED9);
  color: white;
  border: none;
  font-weight: 600;
}
.btn-tg:active { transform: scale(0.98); }

.tg-status {
  background: rgba(45, 165, 89, 0.12);
  border: 0.5px solid rgba(45, 165, 89, 0.3);
  color: #5dca8a;
  border-radius: 12px;
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
}

/* ==== PWA Install Banner ==== */

.install-banner {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  left: 12px;
  right: 12px;
  z-index: 900;
  background: var(--bg-2);
  border: 0.5px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s ease-out;
}

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

.install-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.install-banner-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.install-banner-text {
  flex: 1;
  min-width: 0;
}

.install-banner-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.install-banner-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.ios-share-icon {
  display: inline-block;
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  color: var(--amber);
}

.install-banner-action {
  background: var(--amber);
  color: var(--bg);
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.install-banner-action:active { transform: scale(0.96); }

.install-banner-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ==== Публічний перегляд зустрічі (без логіну) ==== */

.public-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.public-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: env(safe-area-inset-top) 20px 16px;
  padding-top: calc(env(safe-area-inset-top) + 16px);
}

.public-login-btn {
  background: transparent;
  border: 0.5px solid var(--border-strong);
  color: var(--amber);
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}
.public-login-btn:active { background: var(--amber-soft); }

.public-meetup {
  flex: 1;
  padding: 8px 0 24px;
}
.public-meetup .detail-when,
.public-meetup .detail-title,
.public-meetup .detail-where,
.public-meetup .detail-desc {
  padding-left: 20px;
  padding-right: 20px;
}
.public-meetup .attendees-section {
  padding: 0 20px;
}

.public-cta {
  background: var(--bg-2);
  border-top: 0.5px solid var(--border);
  padding: 24px 20px calc(env(safe-area-inset-bottom) + 24px);
  text-align: center;
}
.public-cta-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.public-foot {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 12px;
}

/* ==== Auth screen — індикатори завантаження і помилок ==== */
.auth-loading {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  padding: 16px;
}

.auth-error {
  background: rgba(237, 147, 177, 0.08);
  border: 0.5px solid rgba(237, 147, 177, 0.3);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text);
  text-align: center;
  max-width: 320px;
}

.auth-divider {
  width: 100%;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 0.5px;
  background: var(--border);
}

.btn-secondary {
  background: transparent;
  border: 0.5px solid var(--border-strong);
  color: var(--text);
  max-width: 320px;
}
.btn-secondary:active {
  background: var(--bg-2);
}

/* ==== Минулі зустрічі — приглушений вид ==== */
.past-list {
  opacity: 0.7;
}

.meetup-card.past {
  background: var(--bg-2);
  border-color: var(--border);
}

.meetup-card.past .meetup-title {
  color: var(--text-muted);
}

.meetup-card.past .meetup-desc {
  color: var(--text-dim);
}

.badge-past {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-3);
  color: var(--text-muted);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.5px;
  margin-left: 8px;
  vertical-align: middle;
  text-transform: lowercase;
}

/* На минулій картці — клікабельна, але без primary-кнопки справа */
.meetup-card.past .meetup-footer {
  justify-content: flex-start;
}

/* ==== Lightbox — оновлений з навігацією ==== */
.lightbox-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-counter {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 20, 16, 0.6);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 0.5px solid var(--border-strong);
  backdrop-filter: blur(8px);
  z-index: 1001;
}

.lightbox-nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(26, 20, 16, 0.6);
  color: var(--amber);
  border: 0.5px solid var(--border-strong);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  z-index: 1001;
  transition: transform 0.15s ease;
}
.lightbox-nav:active {
  transform: translateX(-50%) scale(0.92);
}
.lightbox-prev {
  top: calc(env(safe-area-inset-top) + 56px);
}
.lightbox-next {
  bottom: calc(env(safe-area-inset-bottom) + 56px);
}

/* На вузьких мобільних — підказка про свайп */
@media (hover: none) and (pointer: coarse) {
  .lightbox-nav {
    opacity: 0.5;
  }
}
