/**
 * Members screen styles (v5-mini-app-6-1, renamed v6-mini-app-s4)
 * Telegram Mini App — uses CSS variables provided by app.css / Telegram theme.
 *
 * Variables assumed available:
 *   --cl-bg, --cl-card, --cl-text, --cl-text-secondary, --cl-border,
 *   --cl-link, --cl-btn, --cl-btn-text, --cl-error, --cl-success,
 *   --cl-radius, --cl-shadow
 */

/* ── Member list ──────────────────────────────────────────────────────────── */

.contacts-list {
  padding: 12px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Member cards ─────────────────────────────────────────────────────────── */

.member-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--cl-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.member-card:active { opacity: 0.7; }
.member-card:last-child { border-bottom: none; }

/* ── Avatar ───────────────────────────────────────────────────────────────── */

.member-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--cl-link);
  display: flex;
  align-items: center;
  justify-content: center;
}

.member-avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.member-avatar__initials {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  line-height: 1;
}

/* ── Card body ────────────────────────────────────────────────────────────── */

.member-card__body {
  flex: 1;
  min-width: 0;
}

.member-card__name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.member-card__name {
  font-size: 15px;
  font-weight: 500;
  color: var(--cl-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0; /* required for ellipsis inside flex container */
  flex: 1;
}

.member-card__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
}

.member-card__last-active,
.member-card__event-count {
  font-size: 12px;
  color: var(--cl-text-secondary);
}

/* ── Sparkline ────────────────────────────────────────────────────────────── */

.member-card__sparkline {
  flex-shrink: 0;
  width: 60px;
  height: 20px;
}

.sparkline {
  display: block;
  width: 60px;
  height: 20px;
  overflow: visible;
}

/* ── Role badges ──────────────────────────────────────────────────────────── */

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
  line-height: 1.6;
}

.role-badge--admin {
  /* rgba fallback for older Android WebView that doesn't support color-mix() */
  background: rgba(33, 150, 243, 0.15);
  background: color-mix(in srgb, var(--cl-link, #2196f3) 15%, transparent);
  color: var(--cl-link);
}

.role-badge--contributor {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.role-badge--observer {
  background: rgba(107, 114, 128, 0.15);
  color: #6b7280;
}

.role-badge--lg {
  font-size: 13px;
  padding: 4px 12px;
}

/* Admin: role badge acts as a button — add visual affordance */
[role="button"].role-badge {
  cursor: pointer;
}

[role="button"].role-badge::after {
  content: ' ▾';
  font-size: 9px;
  opacity: 0.7;
}

/* ── State messages ───────────────────────────────────────────────────────── */

.contacts-error,
.contacts-empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--cl-text-secondary);
}

.contacts-empty__icon { font-size: 40px; margin-bottom: 12px; }
.contacts-empty__text { font-size: 14px; margin: 0; }

.contacts-error p { font-size: 14px; margin: 0 0 12px; color: var(--cl-error, #ef4444); }

.btn-retry {
  padding: 8px 16px;
  background: var(--cl-btn);
  color: var(--cl-btn-text);
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 14px;
  cursor: pointer;
}

/* ── Profile header ───────────────────────────────────────────────────────── */

.member-profile {
  padding: 0 16px 80px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 0 16px;
  border-bottom: 1px solid var(--cl-border);
  margin-bottom: 16px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--cl-link);
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar__initials {
  font-size: 28px;
  font-weight: 600;
  color: #fff;
}

.profile-name {
  font-size: 20px;
  font-weight: 600;
  color: var(--cl-text);
  margin: 0;
  text-align: center;
}

.btn-telegram-profile {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 8px 14px;
  background: var(--cl-link);
  color: #fff;
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Activity section ─────────────────────────────────────────────────────── */

.profile-activity-loading,
.profile-activity-error {
  padding: 32px 0;
  text-align: center;
  color: var(--cl-text-secondary);
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--cl-border);
  border-top-color: var(--cl-link);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.activity-stats {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--cl-card);
  border-radius: var(--cl-radius, 12px);
  overflow: hidden;
}

.activity-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  border-right: 1px solid var(--cl-border);
}

.activity-stat:last-child { border-right: none; }

.activity-stat__value {
  font-size: 20px;
  font-weight: 700;
  color: var(--cl-text);
}

.activity-stat__label {
  font-size: 11px;
  color: var(--cl-text-secondary);
  text-align: center;
  margin-top: 2px;
}

.profile-section {
  margin-bottom: 16px;
}

.profile-section__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cl-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}

/* ── Event type list ──────────────────────────────────────────────────────── */

.event-type-list { display: flex; flex-direction: column; gap: 4px; }

.event-type-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--cl-card);
  border-radius: var(--cl-radius, 8px);
}

.event-type-row__name {
  font-size: 14px;
  color: var(--cl-text);
}

.event-type-row__count {
  font-size: 14px;
  font-weight: 600;
  color: var(--cl-link);
}

/* ── Recent events list ───────────────────────────────────────────────────── */

.recent-events-list { display: flex; flex-direction: column; gap: 4px; }

.recent-event-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--cl-card);
  border-radius: var(--cl-radius, 8px);
}

.recent-event-row__type {
  font-size: 14px;
  color: var(--cl-text);
}

.recent-event-row__date {
  font-size: 12px;
  color: var(--cl-text-secondary);
}

/* ── Admin actions ────────────────────────────────────────────────────────── */

.profile-admin-actions {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--cl-border);
}

.btn-remove-member {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--cl-error, #ef4444);
  border: 1px solid var(--cl-error, #ef4444);
  border-radius: var(--cl-radius, 8px);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-remove-member:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Role picker / modal ──────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.modal-sheet {
  width: 100%;
  background: var(--cl-card);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--cl-text);
  margin: 0 0 8px;
  text-align: center;
}

.modal-body {
  font-size: 14px;
  color: var(--cl-text-secondary);
  margin: 0 0 8px;
  text-align: center;
  line-height: 1.5;
}

.modal-cancel {
  margin-top: 8px;
  padding: 12px;
  background: transparent;
  color: var(--cl-text-secondary);
  border: 1px solid var(--cl-border);
  border-radius: var(--cl-radius, 8px);
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-cancel-secondary {
  flex: 1;
  padding: 12px;
  background: transparent;
  color: var(--cl-text-secondary);
  border: 1px solid var(--cl-border);
  border-radius: var(--cl-radius, 8px);
  font-size: 15px;
  cursor: pointer;
}

.btn-remove-confirm {
  flex: 1;
  padding: 12px;
  background: var(--cl-error, #ef4444);
  color: #fff;
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-remove-confirm:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Role picker options ──────────────────────────────────────────────────── */

.role-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--cl-radius, 8px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.role-option:active,
.role-option--active { background: var(--cl-bg); }

.role-option__check {
  margin-left: auto;
  color: var(--cl-link);
  font-weight: 700;
  font-size: 16px;
}

/* ── Undo toast ───────────────────────────────────────────────────────────── */

.undo-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--cl-card);
  color: var(--cl-text);
  padding: 10px 16px;
  border-radius: 24px;
  box-shadow: var(--cl-shadow, 0 4px 16px rgba(0,0,0,0.15));
  font-size: 14px;
  white-space: nowrap;
  z-index: 200;
}

.undo-toast__btn {
  background: none;
  border: none;
  color: var(--cl-link);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

/* ── Skeleton loading ─────────────────────────────────────────────────────── */

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.skeleton-line,
.skeleton-avatar,
.skeleton-sparkline {
  background: linear-gradient(90deg,
    var(--cl-border) 25%,
    var(--cl-card)   50%,
    var(--cl-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}

.skeleton-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.skeleton-sparkline {
  flex-shrink: 0;
  width: 60px;
  height: 20px;
  border-radius: 4px;
}

.skeleton-line--name {
  height: 14px;
  width: 120px;
  margin-bottom: 6px;
}

.skeleton-line--sm {
  height: 11px;
  width: 80px;
}
