/* Layout chính: Chia 2 cột */
.builder-layout {
    display: flex;
    flex-direction: row; /* Nằm cùng 1 hàng */
    gap: 25px;
    align-items: flex-start;
    margin-top: 20px;
    width: 100%;
}

/* Section Sân bóng (Bên trái - Chiếm phần lớn diện tích) */
.formation-section {
    flex: 2; /* Tự động giãn rộng */
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    text-align: center;
}

/* Section Kho cầu thủ (Bên phải - Cố định độ rộng) */
.inventory-section {
    flex: 1;
    min-width: 350px;
    max-height: 850px; /* Khớp với chiều cao sân */
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

/* Header bên trong phần sơ đồ */
.pitch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #fff;
    border-bottom: 2px solid #f1f5f9;
    border-radius: 12px 12px 0 0;
    margin: -20px -20px 20px -20px;
    flex-wrap: wrap;
    gap: 15px;
}

.pitch-info-group {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.pitch-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #1e293b;
}

.pitch-title h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    text-transform: uppercase;
}

.pitch-title i {
    color: #3b82f6;
}

/* Style cho các chỉ số Team OVR và Cost */
.team-stats-summary {
    display: flex;
    gap: 20px;
    background: #f8fafc;
    padding: 8px 15px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-item .label {
    font-size: 0.65rem;
    color: #64748b;
    font-weight: 700;
    text-transform: uppercase;
}

.stat-item .value {
    font-size: 1rem;
    font-weight: 800;
    color: #1e293b;
}

#team-ovr-value { color: #22c55e; }
#team-cost-value { color: #eab308; }

/* Tối ưu bộ chọn sơ đồ trên header */
.formation-selector {
    display: flex;
    gap: 8px;
}

.btn-formation {
    padding: 6px 15px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-formation.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.btn-formation:hover:not(.active) {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #3b82f6;
}

/* Thiết kế sân bóng */
.pitch-wrapper {
    display: flex;
    justify-content: center;
    background: #f1f5f9;
    padding: 20px;
    border-radius: 10px;
}

.pitch-container {
    background: #1a3a2a; /* Xanh cỏ đậm */
    border: 4px solid #ffffff44;
    border-radius: 8px;
    position: relative;
    width: 100%;
    height: 750px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    overflow: hidden;
    
    /* Vạch kẻ sân bóng chuyên nghiệp */
    background-image: 
        /* Vạch giữa sân */
        linear-gradient(to bottom, transparent 49.8%, rgba(255,255,255,0.3) 49.8%, rgba(255,255,255,0.3) 50.2%, transparent 50.2%),
        /* Vòng tròn giữa */
        radial-gradient(circle at 50% 50%, transparent 12%, rgba(255,255,255,0.3) 12%, rgba(255,255,255,0.3) 12.5%, transparent 12.5%);
    background-repeat: no-repeat;
}

/* Khu vực vòng cấm (Gôn) 2 đầu */
.pitch-container::before, .pitch-container::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 55%;
    height: 90px;
    border: 2px solid rgba(255,255,255,0.3);
    z-index: 1;
}
.pitch-container::before { top: 0; border-top: none; border-radius: 0 0 5px 5px; }
.pitch-container::after { bottom: 0; border-bottom: none; border-radius: 5px 5px 0 0; }

/* Slot vị trí cầu thủ */
.pitch-slot {
    position: absolute;
    width: 65px;
    height: 65px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(2px);
}

.pitch-slot span {
    color: #fff;
    font-size: 0.7rem;
    font-weight: bold;
    pointer-events: none;
}

.pitch-slot:hover {
    border-color: #22c55e;
    transform: translate(-50%, -50%) scale(1.1);
    background: rgba(34, 197, 94, 0.2);
}

* Hiệu ứng các ô trên sân khi ở chế độ chọn vị trí */
.pitch-slot.highlight-mode {
    border: 2px solid #22c55e;
    background: rgba(34, 197, 94, 0.2);
    box-shadow: 0 0 15px #22c55e;
    animation: pulse-green 1.5s infinite;
    z-index: 20;
}

/* Thông báo hướng dẫn */
#status-instruction {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: #fff;
    padding: 12px 25px;
    border-radius: 50px;
    font-weight: 600;
    transition: transform 0.3s ease;
    z-index: 1000;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

#status-instruction.show {
    transform: translateX(-50%) translateY(0);
}

/* Container chứa danh sách cầu thủ */
#player-list-inventory {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    padding: 10px;
}

/* Kho cầu thủ (Inventory Grid) */
.inventory-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f1f5f9;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 cột trong sidebar */
    gap: 12px;
    overflow-y: auto;
    padding-right: 8px;
}

/* Thanh cuộn cho kho cầu thủ */
.inventory-grid::-webkit-scrollbar { width: 5px; }
.inventory-grid::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

.inventory-card {
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 2px solid transparent;
    position: relative; /* Để căn nút x */
    border: 1px dashed #cbd5e1; /* Tạo viền kẻ kẻ (dashed) */
    border-radius: 12px;
    padding: 12px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.inventory-card.selected {
    border-color: #22c55e;
    background: #f0fdf4;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.2);
}

.inventory-card:hover {
    border-style: solid;
    border-color: #3b82f6;
    background: #f8fafc;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.1);
}

.inventory-card .rating {
    background: #1e293b;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.inventory-card .name {
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
/* Nút xóa (Icon X) */
.btn-delete-player {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 22px;
    height: 22px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
    transition: transform 0.2s;
}

.btn-delete-player:hover {
    transform: scale(1.2);
    background: #dc2626;
}

/* Khi cầu thủ được chọn để đặt vào sân */
.inventory-card.selected {
    border: 2px solid #22c55e;
    background: #f0fdf4;
    border-style: solid;
}

/* Hiệu ứng player */
.player-on-pitch {
    text-align: center;
    animation: glow 1.5s infinite alternate;
}

.player-on-pitch .rating {
    background: #22c55e;
    color: #fff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: bold;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #fff;
}

.player-on-pitch .name {
    color: #fff;
    font-size: 0.65rem;
    font-weight: bold;
    margin-top: 3px;
    text-shadow: 1px 1px 3px #000;
}

@keyframes glow {
    from { filter: drop-shadow(0 0 2px rgba(34, 197, 94, 0.4)); }
    to { filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.8)); }
}
/* Mobile */
@media screen and (max-width: 1024px) {
    .builder-layout {
        flex-direction: column; /* Chuyển thành hàng dọc */
    }

    .formation-section, .inventory-section {
        flex: unset;
        width: 100%;
        min-width: unset;
    }

    .inventory-section {
        max-height: 500px; /* Thu gọn kho cầu thủ */
        margin-top: 20px;
    }

    .inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); /* Nhiều cột hơn trên mobile ngang */
    }

    .pitch-container {
        height: 600px; /* Thu nhỏ sân một chút */
    }

    .pitch-slot {
        width: 55px;
        height: 55px;
    }

    .pitch-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    .pitch-info-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

@media screen and (max-width: 480px) {
    .inventory-grid {
        grid-template-columns: repeat(3, 1fr); /* 3 cột card nhỏ trên điện thoại đứng */
    }
    
    .inventory-card .name {
        font-size: 0.7rem;
    }
}

@media (max-width: 768px) {
    .pitch-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
}
