/* Friends modal: search on top, friends list below, search results replace list area (MVP) */

.friends-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 120000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

.friends-modal.show {
  display: flex !important;
}

.friends-modal-content {
  position: relative;
  background: var(--surface-color, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 520px;
  max-height: min(88vh, calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 2rem));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.friends-modal-header {
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.friends-modal-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.friends-modal-header h3 i {
  color: var(--accent-color, #3b82f6);
}

.friends-modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  line-height: 1;
}

.friends-modal-close:hover {
  background: var(--hover-bg, rgba(0, 0, 0, 0.06));
  color: var(--text-primary, #374151);
}

.friends-modal-toolbar {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem 0;
}

.friends-modal-search-wrap {
  position: relative;
}

.friends-modal-search {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--input-bg, #fff);
  color: var(--text-primary, #111827);
}

.friends-modal-search:focus {
  outline: none;
  border-color: var(--accent-color, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.friends-modal-search-hint {
  font-size: 0.8rem;
  color: var(--text-secondary, #6b7280);
  margin-top: 0.35rem;
  min-height: 1.2em;
}

.friends-modal-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1.25rem 1rem;
}

.friends-modal-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.friends-modal-list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.friends-modal-results-panel {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
}

.friends-modal-results-panel.is-visible {
  display: flex;
}

.friends-modal-results-panel .friends-modal-list-wrap {
  border-top: 1px solid var(--border-color, #e5e7eb);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
}

.friends-modal-friends-panel.is-hidden {
  display: none;
}

.friends-modal-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.friends-modal-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--card-bg, #f9fafb);
}

.friends-modal-row:hover {
  border-color: var(--accent-color, #3b82f6);
}

.friends-modal-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border-color, #e5e7eb);
}

.friends-modal-meta {
  flex: 1;
  min-width: 0;
}

.friends-modal-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary, #111827);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friends-modal-handle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Profile headline (display_name) under @username — friends modal */
.friends-modal-profile-headline {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friends-modal-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
}

/* Icon-only actions — compact for narrow / PWA screens */
.friends-modal-actions--icons {
  gap: 0.3rem;
}

.friends-modal-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  min-width: 2.35rem;
  min-height: 2.35rem;
  padding: 0;
  margin: 0;
  border-radius: 10px;
  border: 1px solid var(--friends-icon-border, #cbd5e1);
  background: var(--friends-icon-bg, rgba(255, 255, 255, 0.85));
  color: var(--friends-icon-color, #0ea5e9);
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.friends-modal-icon-btn i {
  font-size: 1.05rem;
}

.friends-modal-icon-btn:hover:not(:disabled) {
  background: var(--friends-icon-bg-hover, rgba(14, 165, 233, 0.12));
  border-color: var(--friends-icon-color, #0ea5e9);
  color: var(--friends-icon-color-hover, #0284c7);
}

.friends-modal-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.friends-modal-icon-btn--follow {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  border-color: transparent;
  color: #fff;
}

.friends-modal-icon-btn--follow:hover:not(:disabled) {
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
  color: #fff;
}

.friends-modal-icon-btn--unfollow {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.08);
}

.friends-modal-icon-btn--unfollow:hover:not(:disabled) {
  color: #b91c1c;
  border-color: rgba(185, 28, 28, 0.55);
  background: rgba(220, 38, 38, 0.14);
}

.friends-modal-icon-btn--message {
  color: var(--friends-icon-accent, #06b6d4);
}

.friends-modal-icon-btn--message:hover:not(:disabled) {
  color: #0891b2;
}

.friends-modal-icon-btn--profile {
  color: var(--friends-icon-muted, #64748b);
}

.friends-modal-icon-btn--profile:hover:not(:disabled) {
  color: var(--friends-icon-accent, #06b6d4);
}

/* Mutual friends: status only — not styled like a button (no frame / hit-area confusion) */
.friends-modal-mutual-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  color: #06b6d4;
  cursor: default;
  line-height: 1;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.friends-modal-mutual-badge i {
  font-size: 1.15rem;
  opacity: 0.92;
}

/* Extra-narrow: mutual badge + several icons still need room beside name */
@media (max-width: 380px) {
  .friends-modal-actions--icons {
    gap: 0.22rem;
  }

  .friends-modal-icon-btn {
    width: 2.1rem;
    height: 2.1rem;
    min-width: 2.1rem;
    min-height: 2.1rem;
    border-radius: 8px;
  }

  .friends-modal-icon-btn i {
    font-size: 0.95rem;
  }

  .friends-modal-mutual-badge i {
    font-size: 1.05rem;
  }

  .friends-modal-row {
    gap: 0.5rem;
    padding: 0.55rem 0.5rem;
  }

  .friends-modal-avatar {
    width: 40px;
    height: 40px;
  }
}

.friends-modal-empty {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--text-secondary, #6b7280);
  font-size: 0.9rem;
}

.friends-modal-loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary, #6b7280);
}

[data-theme="dark"] .friends-modal-content {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .friends-modal-header {
  border-color: #334155;
}

[data-theme="dark"] .friends-modal-header h3 {
  color: #f1f5f9;
}

[data-theme="dark"] .friends-modal-search {
  background: #0f172a;
  border-color: #475569;
  color: #f1f5f9;
}

[data-theme="dark"] .friends-modal-row {
  background: #0f172a;
  border-color: #334155;
}

[data-theme="dark"] .friends-modal-name {
  color: #f1f5f9;
}

[data-theme="dark"] .friends-modal-profile-headline {
  color: #94a3b8;
}

[data-theme="dark"] .friends-modal-icon-btn {
  background: rgba(30, 41, 59, 0.95);
  border-color: #475569;
  color: #38bdf8;
}

[data-theme="dark"] .friends-modal-icon-btn:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.12);
  border-color: #38bdf8;
  color: #7dd3fc;
}

[data-theme="dark"] .friends-modal-icon-btn--follow {
  background: linear-gradient(135deg, #0ea5e9 0%, #0369a1 100%);
  color: #f0f9ff;
}

[data-theme="dark"] .friends-modal-icon-btn--follow:hover:not(:disabled) {
  background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
  color: #fff;
}

[data-theme="dark"] .friends-modal-icon-btn--unfollow {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
}

[data-theme="dark"] .friends-modal-icon-btn--unfollow:hover:not(:disabled) {
  color: #fca5a5;
  border-color: rgba(252, 165, 165, 0.55);
  background: rgba(248, 113, 113, 0.18);
}

[data-theme="dark"] .friends-modal-icon-btn--message {
  color: #22d3ee;
}

[data-theme="dark"] .friends-modal-icon-btn--message:hover:not(:disabled) {
  color: #67e8f9;
}

[data-theme="dark"] .friends-modal-icon-btn--profile {
  color: #94a3b8;
}

[data-theme="dark"] .friends-modal-icon-btn--profile:hover:not(:disabled) {
  color: #22d3ee;
}

[data-theme="dark"] .friends-modal-mutual-badge {
  background: transparent;
  color: #22d3ee;
}

[data-theme="dark"] .friends-modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .friends-modal-results-panel .friends-modal-list-wrap {
  border-color: #334155;
}
