/**
 * Team Pilot Cards — компактные горизонтальные карточки состава команды.
 *
 * Карточка рассчитана на максимально насыщенное состояние: длинные имя и Steam,
 * флаг, ранг, ELO, дивизион, дата вступления, три статистики, винрейт,
 * кнопки связи, профиль и управление ролью. Все подписи — в одну строку.
 */

/* === Сетка: две широкие карточки в основной колонке, одна на узких экранах === */
.team-pilots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 16px;
    align-items: stretch;
    margin-bottom: 16px;
}

.team-pilot-card-wrap {
    display: flex;
    min-width: 0;
}

/* === Карточка === */
.team-pilot-card {
    --tpc-text-strong: #ffffff;
    --tpc-text-primary: rgba(255, 255, 255, 0.95);
    --tpc-text-muted: rgba(255, 255, 255, 0.76);
    --tpc-tile-bg: rgba(0, 0, 0, 0.24);
    --tpc-tile-border: rgba(255, 255, 255, 0.12);
    --tpc-footer-bg: rgba(0, 0, 0, 0.32);

    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    border-radius: 16px;
    background:
        linear-gradient(180deg, rgba(8, 10, 16, 0.08) 0%, rgba(8, 10, 16, 0.38) 100%),
        linear-gradient(
            165deg,
            var(--card-primary, #4169e1) 0%,
            var(--card-secondary, #7b68ee) 55%,
            color-mix(in srgb, var(--card-secondary, #7b68ee) 65%, #000) 100%
        );
    box-shadow:
        0 1px 2px rgba(16, 24, 40, 0.08),
        0 14px 28px -18px var(--card-glow, rgba(65, 105, 225, 0.3));
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    isolation: isolate;
}

.team-pilot-card::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 12px,
        rgba(255, 255, 255, 0.02) 12px,
        rgba(255, 255, 255, 0.02) 20px
    );
    pointer-events: none;
}

.team-pilot-card:hover {
    transform: translateY(-2px);
    box-shadow:
        0 2px 4px rgba(16, 24, 40, 0.1),
        0 20px 34px -18px var(--card-glow, rgba(65, 105, 225, 0.36));
}

.team-pilot-card.tpc-is-self {
    outline: 2px solid rgba(255, 255, 255, 0.58);
    outline-offset: 2px;
}

/* === Основная часть === */
.tpc-face {
    position: relative;
    z-index: 1;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    padding: 12px 14px 10px;
}

/* Аватар + данные */
.tpc-top {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.tpc-avatar-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.tpc-avatar-ring {
    --tpc-progress: 0;
    position: relative;
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    padding: 2px;
    border-radius: 50%;
    background: conic-gradient(
        rgba(255, 255, 255, 0.92) calc(var(--tpc-progress) * 1%),
        rgba(255, 255, 255, 0.18) 0
    );
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
}

.tpc-avatar-inner {
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.tpc-avatar {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tpc-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 1.4rem;
    color: rgba(255, 255, 255, 0.55);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
}

.tpc-level-badge {
    position: absolute;
    right: -2px;
    bottom: -2px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 999px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 800;
    line-height: 1;
}

/* Строка имени и роли */
.tpc-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.tpc-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.tpc-name {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--tpc-text-strong);
    font-size: 1.02rem;
    font-weight: 800;
    line-height: 1.2;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    white-space: nowrap;
}

.tpc-role-badge {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
    color: #111111;
    font-size: 0.6rem;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.tpc-role-badge i {
    font-size: 0.85em;
}

.tpc-role-badge.role-owner {
    background: linear-gradient(135deg, #ffd700 0%, #ffa500 100%);
}

.tpc-role-badge.role-captain {
    background: linear-gradient(135deg, #e8ecff 0%, #c7d2fe 100%);
    color: #1e2a5a;
}

.tpc-role-badge.role-driver {
    background: linear-gradient(135deg, #d4f8d4 0%, #a8e6cf 100%);
    color: #0d3d1f;
}

.tpc-role-badge.role-reserve {
    background: linear-gradient(135deg, #ffe0b2 0%, #ffab91 100%);
    color: #5d2e0a;
}

/* ELO, ранг, дивизион, флаг */
.tpc-subline {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    color: var(--tpc-text-muted);
    font-size: 0.7rem;
    line-height: 1.2;
    white-space: nowrap;
}

.tpc-flag {
    flex: 0 0 auto;
    width: 18px;
    height: 13px;
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    object-fit: cover;
}

.tpc-elo {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: baseline;
    gap: 3px;
    color: var(--tpc-text-strong);
}

.tpc-elo strong {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}

.tpc-elo span {
    color: var(--tpc-text-muted);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.tpc-rank {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 8rem;
    overflow: hidden;
    padding: 2px 6px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.28);
    color: var(--tpc-text-primary);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.tpc-division {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--tpc-text-muted);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.tpc-division::before {
    content: '·';
    margin-right: 4px;
    opacity: 0.7;
}

/* Steam и дата вступления */
.tpc-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    color: var(--tpc-text-muted);
    font-size: 0.66rem;
    line-height: 1.2;
    white-space: nowrap;
}

.tpc-steam {
    display: inline-flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
}

.tpc-steam i {
    flex: 0 0 auto;
    color: var(--tpc-text-muted);
    font-size: 0.8rem;
}

.tpc-ellipsis {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tpc-join {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    color: var(--tpc-text-muted);
    white-space: nowrap;
}

.tpc-join i {
    flex: 0 0 auto;
    font-size: 0.78rem;
}

/* Статистика */
.tpc-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    min-width: 0;
}

.tpc-stat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    padding: 5px 6px;
    border: 1px solid var(--tpc-tile-border);
    border-radius: 8px;
    background: var(--tpc-tile-bg);
    backdrop-filter: blur(4px);
}

.tpc-stat-val {
    color: var(--tpc-text-strong);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tpc-stat-lbl {
    color: var(--tpc-text-muted);
    font-size: 0.58rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Винрейт + действия */
.tpc-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    margin-top: auto;
}

.tpc-winrate {
    flex: 0 0 auto;
    color: var(--tpc-text-muted);
    font-size: 0.64rem;
    font-weight: 600;
    white-space: nowrap;
}

.tpc-winrate strong {
    color: var(--tpc-text-primary);
    font-weight: 800;
}

.tpc-meta-actions {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.team-member-msg-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tpc-msg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    font-size: 0.8rem;
    text-decoration: none;
    transition: background-color 0.15s ease, transform 0.15s ease;
    cursor: pointer;
}

.tpc-msg-btn:hover,
.tpc-msg-btn:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    color: #ffffff;
    transform: translateY(-1px);
}

.tpc-msg-btn--quiet {
    border-style: dashed;
}

.tpc-profile-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 9px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    font-size: 0.66rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.tpc-profile-link:visited,
.tpc-profile-link:hover,
.tpc-profile-link:focus-visible {
    color: #ffffff;
}

.tpc-profile-link:hover {
    background: rgba(255, 255, 255, 0.24);
    transform: translateY(-1px);
}

.tpc-profile-link i {
    color: inherit;
    font-size: 0.8rem;
}

/* === Управление (роль / удаление / выход) === */
.tpc-controls {
    position: relative;
    z-index: 2;
    padding: 8px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    background: var(--tpc-footer-bg);
    backdrop-filter: blur(6px);
}

.tpc-control-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.tpc-role-select {
    flex: 1 1 auto;
    min-width: 0;
    height: 30px;
    min-height: 30px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.92);
    color: #212529;
    font-size: 0.72rem;
}

[data-theme="dark"] .tpc-role-select {
    background: rgba(30, 30, 30, 0.92);
    color: #e8e8e8;
    border-color: rgba(255, 255, 255, 0.15);
}

.tpc-btn-remove {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border-radius: 7px;
}

.tpc-self-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    padding: 5px 8px;
    border: 1px dashed rgba(255, 255, 255, 0.28);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--tpc-text-primary);
    font-size: 0.7rem;
    font-weight: 600;
}

.tpc-self-badge i {
    color: rgba(255, 255, 255, 0.9);
}

.tpc-btn-leave {
    width: 100%;
    height: 30px;
    min-height: 30px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 0.7rem;
    font-weight: 600;
}

.tpc-controls .text-muted {
    color: rgba(255, 255, 255, 0.75);
}

[data-theme="light"] .tpc-controls .btn-outline-danger {
    background: rgba(255, 255, 255, 0.9);
}

/*
 * Светлая тема: .card i.bi в light.css красит иконки в серый.
 * Карточки пилотов — на цветном градиенте, иконки должны быть светлыми.
 */
[data-theme="light"] .team-pilot-card .tpc-face i.bi,
[data-theme="light"] .team-pilot-card .tpc-face .bi,
[data-theme="light"] .team-pilot-card .tpc-profile-link i.bi,
[data-theme="light"] .team-pilot-card .tpc-self-badge i.fas {
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="light"] .team-pilot-card .tpc-role-badge i.fas {
    color: inherit;
}

[data-theme="light"] .team-pilot-card .tpc-steam i.bi::before,
[data-theme="light"] .team-pilot-card .tpc-join i.bi::before,
[data-theme="light"] .team-pilot-card .tpc-profile-link i.bi::before {
    color: rgba(255, 255, 255, 0.92);
}

/* === Адаптив === */
@media (max-width: 575.98px) {
    .team-pilots-grid {
        gap: 12px;
    }

    .tpc-face {
        padding: 12px 12px 10px;
    }

    .tpc-top {
        grid-template-columns: 56px minmax(0, 1fr);
        gap: 10px;
    }

    .tpc-avatar-ring {
        width: 56px;
        height: 56px;
    }

    .tpc-avatar-placeholder {
        font-size: 1.2rem;
    }

    .tpc-level-badge {
        min-width: 20px;
        height: 20px;
        font-size: 0.6rem;
    }

    .tpc-name {
        font-size: 0.98rem;
    }

    .tpc-role-badge {
        padding: 2px 6px;
        font-size: 0.56rem;
    }

    .tpc-elo strong {
        font-size: 0.95rem;
    }

    .tpc-msg-btn {
        width: 26px;
        height: 26px;
    }

    .tpc-profile-link {
        height: 26px;
        padding: 0 7px;
        font-size: 0.62rem;
    }

    .tpc-controls {
        padding: 8px 12px;
    }
}

@media (max-width: 399.98px) {
    .tpc-subline {
        gap: 4px;
    }

    .tpc-division {
        display: none;
    }

    .tpc-flag {
        width: 16px;
        height: 12px;
    }

    .tpc-elo strong {
        font-size: 0.9rem;
    }

    .tpc-elo span {
        font-size: 0.52rem;
    }

    .tpc-rank {
        max-width: 6rem;
        padding: 2px 5px;
        font-size: 0.52rem;
    }

    .tpc-name {
        font-size: 0.9rem;
    }

    .tpc-role-badge {
        justify-content: center;
        width: 22px;
        height: 22px;
        padding: 0;
    }

    .tpc-role-label {
        display: none;
    }

    .tpc-winrate {
        font-size: 0.6rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .team-pilot-card,
    .tpc-msg-btn,
    .tpc-profile-link {
        transition: none;
    }

    .team-pilot-card:hover,
    .tpc-msg-btn:hover,
    .tpc-profile-link:hover {
        transform: none;
    }
}
