/* ============================================================================
 * Грид · Граждане и отделы — Дизайн-система Уз Дружбы и Связей
 * Бейджи дружбы, индикаторы крепости, судейская изоляция по Статье XX.5
 * Стандарты: WCAG 2.2 AAA (Контрастность >= 7:1), Закон Модульности (< 800 строк)
 * ============================================================================ */

/* ---------- 1. Токены и Градиенты дружбы: канонический свод в tokens.css ---------- */

/* ---------- 2. Стопка аватаров друзей на карточке (Avatar Stack) ---------- */
.friend-avatars-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  overflow: hidden;
}

.friend-avatar-stack {
  display: inline-flex;
  align-items: center;
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.friend-avatar-item {
  width: 24px;
  height: 24px;
  border-radius: var(--r-circle);
  border: 2px solid var(--card);
  margin-right: calc(-1 * var(--sp-1-5));
  position: relative;
  overflow: hidden;
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 var(--sp-0-5) var(--sp-1) var(--black-alpha-40);
  transition: transform var(--dur-normal) var(--ease-spring), z-index var(--dur-normal) ease, border-color var(--dur-normal) ease;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
}

.friend-avatar-item:hover {
  transform: translateY(-2px) scale(1.18);
  z-index: 10;
  border-color: var(--violet);
  box-shadow: 0 0 10px var(--violet-alpha-50);
}

.friend-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.friend-avatar-fallback {
  font-size: var(--fs-sm);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.friend-avatar-more {
  width: 22px;
  height: 22px;
  border-radius: var(--r-circle);
  background: var(--violet-alpha-20);
  border: 2px solid var(--violet-alpha-40);
  color: var(--violet-light);
  font-family: var(--mono);
  font-size: var(--fs-2xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: var(--sp-0-5);
  flex-shrink: 0;
  user-select: none;
}

/* ---------- 3. Строгий бейдж 'Чужак: дружбы не заводит' (Статья XX.5) ---------- */
.foreign-critic-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1-5);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--foreign-bg);
  border: 1px dashed var(--foreign-border);
  color: var(--foreign-tx);
  font-size: var(--fs-xs);
  font-family: var(--mono);
  white-space: nowrap;
  box-sizing: border-box;
  user-select: none;
  transition: all var(--dur-normal) ease;
}

.foreign-critic-badge:hover {
  border-color: var(--foreign-warn-border);
  color: var(--foreign-warn-tx);
  background: var(--rose-alpha-70);
}

.foreign-critic-icon {
  font-size: var(--fs-sm);
  line-height: 1;
  flex-shrink: 0;
}

.foreign-critic-text {
  font-size: var(--fs-xs);
  letter-spacing: 0.2px;
}

.critic-isolation-box {
  display: flex;
  align-items: center;
  gap: var(--sp-2-5);
  padding: var(--sp-2-5) var(--sp-3-5);
  background: var(--slate-900-alpha-70);
  border: 1px dashed var(--slate-400-alpha-30);
  border-radius: var(--r-10);
  margin-top: var(--sp-1);
}

.critic-isolation-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--slate-400-alpha-15);
  border: 1px solid var(--slate-400-alpha-20);
  display: grid;
  place-items: center;
  font-size: var(--fs-xl);
  flex-shrink: 0;
}

.critic-isolation-info {
  display: flex;
  flex-direction: column;
  gap: var(--sp-0-5);
  min-width: 0;
}

.critic-isolation-title {
  font-size: var(--fs-sub);
  font-weight: 700;
  color: var(--tx);
}

.critic-isolation-desc {
  font-size: var(--fs-sm);
  color: var(--tx3);
  line-height: 1.4;
}

/* ---------- 4. Индикаторы крепости уз и побед (Bond Meters) ---------- */
.bond-meter-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 80px;
}

.bond-meter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--fs-2xs);
  font-family: var(--mono);
}

.bond-meter-label {
  color: var(--tx3);
}

.bond-meter-val {
  font-weight: 700;
  color: var(--tx);
}

.bond-meter-track {
  height: 4px;
  border-radius: var(--r-2xs);
  background: var(--slate-900-alpha-80);
  overflow: hidden;
  position: relative;
}

.bond-meter-fill {
  height: 100%;
  border-radius: var(--r-2xs);
  transition: width var(--dur-slow) ease;
}

.bond-meter-fill.lvl-weak { background: var(--slate-400); }
.bond-meter-fill.lvl-med { background: var(--blue); }
.bond-meter-fill.lvl-strong { background: var(--violet); }
.bond-meter-fill.lvl-eternal { background: var(--gold); box-shadow: 0 0 8px var(--gold-alpha-20); }

.friend-victories-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-2xs);
  font-family: var(--mono);
  font-weight: 700;
  color: var(--rank-celestial);
  background: var(--amber-alpha-12);
  border: 1px solid var(--amber-alpha-30);
  padding: var(--sp-0-5) var(--sp-1-5);
  border-radius: var(--r-xs);
  white-space: nowrap;
}

.friend-reason-tag {
  font-size: var(--fs-xs);
  color: var(--tx2);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

/* ---------- 5. Детальные карточки дружбы в Модальном Окне ---------- */
.friendship-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.friendship-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-2-5);
  margin-top: var(--sp-1);
}

.friend-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-2-5) var(--sp-3);
  background: var(--slate-900-alpha-60);
  border: 1px solid var(--line);
  border-radius: var(--r-10);
  transition: all var(--dur-normal) var(--ease-spring);
  cursor: pointer;
  position: relative;
}

.friend-card:hover {
  background: var(--violet-alpha-08);
  border-color: var(--violet-alpha-40);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px var(--black-alpha-40);
}

.friend-card-top {
  display: flex;
  align-items: center;
  gap: var(--sp-2-5);
}

.friend-card-face {
  width: 40px;
  height: 40px;
  border-radius: var(--r-circle);
  overflow: hidden;
  background: var(--bg-deep-canvas);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform var(--dur-normal) ease, border-color var(--dur-normal) ease, box-shadow var(--dur-normal) ease;
}

.friend-card-face:hover {
  transform: scale(1.1);
  border-color: var(--violet);
  box-shadow: 0 0 10px var(--violet-alpha-50);
}

.friend-card-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--r-circle);
}

.friend-card-info {
  display: flex;
  flex-direction: column;
  gap: var(--sp-0-5);
  min-width: 0;
  flex: 1;
}

.friend-card-name {
  font-size: var(--fs-body);
  font-weight: 700;
  color: var(--tx);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-card-id {
  font-size: var(--fs-xs);
  font-family: var(--mono);
  color: var(--tx3);
}

.friend-card-reason {
  font-size: var(--fs-sm);
  color: var(--tx2);
  line-height: 1.4;
  background: var(--black-alpha-20);
  padding: var(--sp-1-5) var(--sp-2);
  border-radius: var(--r-sm);
  border-left: 2px solid var(--violet);
}

.friend-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-top: auto;
  padding-top: var(--sp-1);
}

.friendship-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4);
  background: var(--slate-900-alpha-40);
  border: 1px dashed var(--line);
  border-radius: var(--r-10);
  text-align: center;
  gap: var(--sp-1-5);
}

.friendship-empty-icon {
  font-size: var(--fs-3xl);
  opacity: 0.7;
}

.friendship-empty-title {
  font-size: var(--fs-body);
  font-weight: 700;
  color: var(--tx);
}

.friendship-empty-desc {
  font-size: var(--fs-sm);
  color: var(--tx3);
  max-width: 320px;
}

/* ---------- 6. Светлая тема (Light Mode WCAG 2.2 AAA) ---------- */
html.light-theme .foreign-critic-badge {
  background: var(--bg2);
  border-color: var(--tx2);
  color: var(--tx3);
}

html.light-theme .foreign-critic-badge:hover {
  background: var(--status-failed-bg);
  border-color: var(--status-failed-border);
  color: var(--red-light);
}

html.light-theme .critic-isolation-box {
  background: var(--card2);
  border-color: var(--line);
}

html.light-theme .critic-isolation-icon {
  background: var(--line);
  border-color: var(--tx2);
}

html.light-theme .critic-isolation-title {
  color: var(--tx);
}

html.light-theme .critic-isolation-desc {
  color: var(--tx3);
}

html.light-theme .friend-avatar-item {
  border-color: var(--white);
  background: var(--bg2);
}

html.light-theme .friend-card {
  background: var(--white);
  border-color: var(--line);
  box-shadow: 0 1px 3px var(--black-alpha-04);
}

html.light-theme .friend-card:hover {
  background: var(--bg2);
  border-color: var(--violet-light);
  box-shadow: 0 4px 14px var(--black-alpha-08);
}

html.light-theme .friend-card-face {
  background: var(--bg2);
  border-color: var(--line);
}

html.light-theme .friend-card-name {
  color: var(--tx);
}

html.light-theme .friend-card-id {
  color: var(--text-muted);
}

html.light-theme .friend-card-reason {
  background: var(--bg2);
  color: var(--tx2);
  border-left-color: var(--violet);
}

html.light-theme .bond-meter-track {
  background: var(--line);
}

html.light-theme .bond-meter-val {
  color: var(--tx);
}

html.light-theme .friend-victories-badge {
  background: var(--rank-celestial-bg);
  border-color: var(--rank-celestial-border);
  color: var(--amber-light);
}

html.light-theme .friendship-empty {
  background: var(--card2);
  border-color: var(--line);
}

html.light-theme .friendship-empty-title {
  color: var(--tx);
}

html.light-theme .friendship-empty-desc {
  color: var(--text-muted);
}

/* ---------- 7. Мобильная адаптивность (390px - 768px) ---------- */
@media (max-width: 768px) {
  .friendship-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-2);
  }
  .friend-reason-tag {
    max-width: 160px;
  }
}

@media (max-width: 480px) {
  .friend-card {
    padding: var(--sp-2) var(--sp-2-5);
  }
  .friend-card-face {
    width: 34px;
    height: 34px;
  }
  .friend-card-name {
    font-size: var(--fs-sub);
  }
  .critic-isolation-box {
    padding: var(--sp-2) var(--sp-2-5);
    gap: var(--sp-2);
  }
  .critic-isolation-icon {
    width: 30px;
    height: 30px;
    font-size: var(--fs-h2);
  }
  .critic-isolation-title {
    font-size: var(--fs-sm);
  }
  .critic-isolation-desc {
    font-size: var(--fs-xs);
  }
}