/* [tf-fixes R] Аватарки: ровные круги без растяжения + окно выбора области при загрузке.
   Только CSS-правила поверх существующих; рамки магазина, бейджи и активные состояния серверов не трогаются. */

/* 1. Ряд серверов. Причина «растянутых/сплющенных»: .server-icon = display:grid + place-content:center,
      поэтому height:100% у картинки не срабатывает и высота берётся из пропорций файла (48×16, 48×144…).
      Картинка теперь лежит абсолютно на всю плитку 48×48 и обрезается по центру. Радиус (круг / 16px у активного) — прежний. */
#serverList .server-icon,
aside.servers > .server-icon { position: relative; }
aside.servers > #serverList > .server-icon > img,
aside.servers > .server-icon > img,
#serverList .server-icon > img,
.server-icon > img {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  aspect-ratio: 1 / 1;
  object-fit: cover !important;
  object-position: 50% 50%;
  flex: none !important;
}

/* 2. Все аватарки пользователей/серверов/каналов: квадрат, обрезка по центру, не сжимаются во flex-строках. */
#userBarAvatar, #userMenuAva, #profileAvatarPrev, #tfsPrevAva, #srvIconPrev, #chanIconPrev, #callAva,
.voice-user > img, .srv-live-ava > img, .mav > img, .dm-ava > img, .friend-ava > img,
.ss-mrow > img, .voice-rank-row > img, .tf-ava, .tfp-ava, .tfp-c-ava, .tfp-p-ava, .tfs-st-avimg,
.tfs-ava-wrap > img:first-child, .tfs-st-chat > img, .msg > img:first-child, .fx-avs img, .tfo-av img, img.ch-ico {
  object-fit: cover;
  object-position: 50% 50%;
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
}
#userBarAvatar, #userMenuAva, .voice-user > img, .srv-live-ava > img, .mav > img, .dm-ava > img, .friend-ava > img,
.ss-mrow > img, .voice-rank-row > img, .tf-ava, .tfp-c-ava, .tfp-p-ava { border-radius: 50%; }
#ssAva { background-size: cover !important; background-position: 50% 50% !important; background-repeat: no-repeat !important; }

/* 3. Страховка для любых других мест: загруженные картинки и аватарки по умолчанию никогда не растягиваются.
      :where() = нулевая специфичность → любые существующие правила (contain в просмотрщике и т.п.) важнее. */
:where(img[src^="/uploads/"], img[src^="/avatar/"], img[src*="/uploads/"]) { object-fit: cover; }

/* 4. Окно выбора области */
.tfav-ov { position: fixed; inset: 0; z-index: 2147481000; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(7, 8, 12, .66); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); opacity: 0; transition: opacity .18s ease; }
.tfav-ov.on { opacity: 1; }
.tfav-card { width: min(420px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-sizing: border-box; padding: 20px 20px 18px;
  background: linear-gradient(180deg, #23252e 0%, #1b1c23 100%); border: 1px solid rgba(255, 255, 255, .07); border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55), 0 0 0 1px rgba(124, 108, 255, .08), inset 0 1px 0 rgba(255, 255, 255, .04);
  color: #e6e7ee; font-family: "gg sans", "Segoe UI", Inter, system-ui, sans-serif; transform: translateY(8px) scale(.98); transition: transform .18s ease; }
.tfav-ov.on .tfav-card { transform: none; }
.tfav-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tfav-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .01em; color: #fff; }
.tfav-sub { margin: 4px 0 0; font-size: 12.5px; color: #9a9db0; line-height: 1.4; }
.tfav-x { flex: none; width: 30px; height: 30px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, .05); color: #b5b8c8; font-size: 18px; line-height: 30px; cursor: pointer; padding: 0; }
.tfav-x:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.tfav-stage { position: relative; width: 100%; max-width: 320px; aspect-ratio: 1 / 1; margin: 0 auto; border-radius: 14px; overflow: hidden;
  background: #101116 repeating-conic-gradient(#15161c 0 25%, #101116 0 50%) 0 0 / 20px 20px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; }
.tfav-stage:focus-visible { box-shadow: inset 0 0 0 2px rgba(124, 108, 255, .7); }
.tfav-card:focus { outline: none; }
.tfav-stage.drag { cursor: grabbing; }
.tfav-img { position: absolute; left: 0; top: 0; max-width: none !important; max-height: none !important; transform-origin: 0 0; will-change: transform; pointer-events: none; -webkit-user-drag: none; object-fit: fill !important; }
.tfav-mask { position: absolute; inset: 7%; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 999px rgba(9, 10, 14, .62); outline: 2px solid rgba(255, 255, 255, .9); outline-offset: -1px; }
.tfav-mask::after { content: ""; position: absolute; inset: -1px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(124, 108, 255, .28); }
.tfav-zoom { display: flex; align-items: center; gap: 10px; max-width: 320px; margin: 16px auto 0; }
.tfav-zb { flex: none; width: 30px; height: 30px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .06); color: #cfd2e0; font-size: 18px; line-height: 30px; cursor: pointer; padding: 0; }
.tfav-zb:hover { background: rgba(124, 108, 255, .22); color: #fff; }
.tfav-range { flex: 1; min-width: 0; height: 22px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; --p: 0%; }
.tfav-range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #7c6cff 0 var(--p), #3a3c49 var(--p) 100%); }
.tfav-range::-moz-range-track { height: 6px; border-radius: 3px; background: #3a3c49; }
.tfav-range::-moz-range-progress { height: 6px; border-radius: 3px; background: #7c6cff; }
.tfav-range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 4px rgba(124, 108, 255, .35), 0 2px 6px rgba(0, 0, 0, .4); }
.tfav-range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 4px rgba(124, 108, 255, .35), 0 2px 6px rgba(0, 0, 0, .4); }
.tfav-prev { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 16px 0 2px; }
.tfav-prev canvas { display: block; border-radius: 50%; background: #2b2d38; box-shadow: 0 0 0 2px rgba(255, 255, 255, .06); }
.tfav-prev small { font-size: 11.5px; color: #8b8ea3; margin-left: 2px; }
.tfav-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.tfav-btn { min-width: 108px; height: 38px; padding: 0 16px; border: 0; border-radius: 10px; font: 600 14px/38px inherit; font-family: inherit; cursor: pointer; transition: filter .15s ease, background .15s ease, transform .1s ease; }
.tfav-btn:active { transform: translateY(1px); }
.tfav-cancel { background: rgba(255, 255, 255, .06); color: #d7d9e4; }
.tfav-cancel:hover { background: rgba(255, 255, 255, .11); }
.tfav-save { background: linear-gradient(135deg, #7c6cff, #5b8cff); color: #fff; box-shadow: 0 6px 18px rgba(124, 108, 255, .35); }
.tfav-save:hover { filter: brightness(1.08); }
.tfav-save[disabled] { opacity: .6; cursor: progress; }
.tfav-hint { margin: 10px 0 0; text-align: center; font-size: 11.5px; color: #767a8e; }
html[data-theme="glass"] .tfav-card { background: rgba(28, 30, 40, .82); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
@media (max-width: 480px) { .tfav-card { padding: 16px 14px 14px; border-radius: 16px; } .tfav-btn { flex: 1; min-width: 0; } .tfav-hint { display: none; } }
@media (prefers-reduced-motion: reduce) { .tfav-ov, .tfav-card { transition: none; } }
