/**
 * JerryTrades v4 — Team Needs Grid CSS
 * Modal overlay with league-wide positional needs matrix
 */

/* ── Overlay & Modal ─────────────────────────────────────────────────── */

#teamNeedsGrid {
    position: fixed;
    inset: 0;
    z-index: 1200;
    pointer-events: auto;
}

#teamNeedsGrid .tng-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
}

#teamNeedsGrid .tng-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(94vw, 820px);
    max-height: 85vh;
    background: #111827;
    border: 1px solid #1f2937;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

/* ── Header ──────────────────────────────────────────────────────────── */

.tng-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem 0.7rem;
    border-bottom: 1px solid #1f2937;
    flex-shrink: 0;
}

.tng-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #f9fafb;
    letter-spacing: -0.01em;
}

.tng-header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.tng-search {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 6px;
    color: #f9fafb;
    font-size: 0.8rem;
    padding: 0.3rem 0.65rem;
    width: 160px;
    outline: none;
}
.tng-search:focus { border-color: #7c3aed; }
.tng-search::placeholder { color: #6b7280; }

.tng-close {
    background: #374151;
    border: none;
    border-radius: 6px;
    color: #9ca3af;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.tng-close:hover { background: #4b5563; color: #f9fafb; }

/* ── Legend ──────────────────────────────────────────────────────────── */

.tng-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.1rem;
    border-bottom: 1px solid #1f2937;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.tng-chip {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
    letter-spacing: 0.03em;
}

/* Tier colours — also used on cells */
.tng-chip.tng-over, .tng-over .tng-tier-dot  { background: rgba(52, 211, 153, 0.18); color: #34d399; border: 1px solid rgba(52, 211, 153, 0.3); }
.tng-chip.tng-set,  .tng-set  .tng-tier-dot  { background: rgba(99, 102, 241, 0.18); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }
.tng-chip.tng-thin, .tng-thin .tng-tier-dot  { background: rgba(251, 191, 36, 0.18); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.3); }
.tng-chip.tng-weak, .tng-weak .tng-tier-dot  { background: rgba(248, 113, 113, 0.18); color: #f87171; border: 1px solid rgba(248, 113, 113, 0.3); }

.tng-legend-note {
    font-size: 0.68rem;
    color: #6b7280;
    margin-left: auto;
}

/* ── Table Wrapper ───────────────────────────────────────────────────── */

.tng-table-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 0;
}

/* Custom scrollbar */
.tng-table-wrap::-webkit-scrollbar { width: 5px; height: 5px; }
.tng-table-wrap::-webkit-scrollbar-track { background: transparent; }
.tng-table-wrap::-webkit-scrollbar-thumb { background: #374151; border-radius: 99px; }

/* ── Table ───────────────────────────────────────────────────────────── */

.tng-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    table-layout: fixed;
}

/* Header */
.tng-th {
    background: #0f172a;
    color: #6b7280;
    font-size: 0.73rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.55rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid #1f2937;
    white-space: nowrap;
    user-select: none;
    cursor: pointer;
    position: sticky;
    top: 0;
    z-index: 2;
    transition: color 0.15s;
}
.tng-th:hover { color: #d1d5db; }
.tng-th.tng-sorted { color: #7c3aed; }
.tng-th-team {
    text-align: left;
    padding-left: 1rem;
    width: 200px;
    min-width: 160px;
    cursor: default;
}
.tng-sort-icon { margin-left: 3px; font-size: 0.65rem; opacity: 0.5; }

/* Rows */
.tng-row {
    transition: background 0.12s;
}
.tng-row:hover { background: rgba(255,255,255,0.03); }
.tng-row:not(:last-child) td { border-bottom: 1px solid #1a2332; }

/* My-team row */
.tng-my-team { background: rgba(124, 58, 237, 0.07); }
.tng-my-team:hover { background: rgba(124, 58, 237, 0.12); }

/* Dim rows when cell is clicked for opportunity highlight */
.tng-row-dim td { opacity: 0.3; transition: opacity 0.2s; }

/* Team name column */
.tng-team-name {
    padding: 0.55rem 0.6rem 0.55rem 1rem;
    color: #d1d5db;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.tng-me-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    background: #7c3aed;
    color: #fff;
    border-radius: 4px;
    padding: 0 4px;
    margin-right: 5px;
    letter-spacing: 0.05em;
    vertical-align: middle;
}

/* Data cells */
.tng-cell {
    padding: 0.45rem 0.35rem;
    text-align: center;
    cursor: pointer;
    transition: opacity 0.2s, filter 0.2s;
    position: relative;
}

.tng-pct {
    font-size: 0.78rem;
    font-weight: 600;
    display: block;
}

.tng-tier-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-top: 2px;
}

/* Cell tier background tints */
.tng-cell.tng-over { background: rgba(52, 211, 153, 0.07); }
.tng-cell.tng-set  { background: transparent; }
.tng-cell.tng-thin { background: rgba(251, 191, 36, 0.06); }
.tng-cell.tng-weak { background: rgba(248, 113, 113, 0.08); }

/* Cell text colours per tier */
.tng-cell.tng-over .tng-pct { color: #34d399; }
.tng-cell.tng-set  .tng-pct { color: #818cf8; }
.tng-cell.tng-thin .tng-pct { color: #fbbf24; }
.tng-cell.tng-weak .tng-pct { color: #f87171; }

/* Tier dot colours */
.tng-cell.tng-over .tng-tier-dot { background: #34d399; }
.tng-cell.tng-set  .tng-tier-dot { background: #818cf8; }
.tng-cell.tng-thin .tng-tier-dot { background: #fbbf24; }
.tng-cell.tng-weak .tng-tier-dot { background: #f87171; }

/* Highlighted cell (from opportunity click) */
.tng-cell.tng-highlight {
    outline: 2px solid #7c3aed;
    outline-offset: -2px;
    border-radius: 3px;
    z-index: 1;
}
.tng-cell.tng-highlight-origin {
    outline-color: #a78bfa;
    background: rgba(124, 58, 237, 0.18) !important;
}

/* ── Footer ──────────────────────────────────────────────────────────── */

.tng-footer {
    padding: 0.5rem 1.1rem;
    font-size: 0.7rem;
    color: #6b7280;
    border-top: 1px solid #1f2937;
    flex-shrink: 0;
}

/* ── Mobile ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    #teamNeedsGrid .tng-modal {
        top: auto;
        left: 0;
        bottom: 0;
        transform: none;
        width: 100%;
        max-height: 90vh;
        border-radius: 12px 12px 0 0;
    }
    .tng-th-team { width: 130px; min-width: 110px; }
    .tng-legend-note { display: none; }
    .tng-search { width: 110px; }
}

/* ── Loading State ───────────────────────────────────────────────────── */

.tng-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
    flex: 1;
}

.tng-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #1f2937;
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: tngSpin 0.7s linear infinite;
}

@keyframes tngSpin {
    to { transform: rotate(360deg); }
}

.tng-loading-text {
    font-size: 0.85rem;
    color: #6b7280;
}

/* ── Needs Grid button in trading toolbar ────────────────────────────── */

.trade-action-btn.needs-grid-btn {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.35);
    color: #a5b4fc;
}
.trade-action-btn.needs-grid-btn:hover {
    background: rgba(99, 102, 241, 0.28);
    border-color: #7c3aed;
    color: #c4b5fd;
}