/* ===== Comp Builder ===== */

.comps-container {
    padding-top: 24px;
}

.comp-layout {
    display: grid;
    grid-template-columns: minmax(380px, 460px) 1fr;
    gap: 24px;
    align-items: start;
    margin-top: 24px;
}

@media (max-width: 1024px) {
    .comp-layout {
        grid-template-columns: 1fr;
    }
}

.comp-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* --- Map button in toolbar --- */
.cb-map-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.cb-map-thumb {
    width: 28px;
    height: 20px;
    border-radius: 4px;
    background: var(--bg-tertiary) center/cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

/* --- Comp column --- */
.cb-comp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.cb-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cb-preset {
    padding: 5px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cb-preset:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.cb-preset.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.cb-preset-custom {
    padding: 5px 10px;
    border: 1px dashed var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    display: none;
}

.cb-preset-custom.active {
    display: inline-block;
    color: var(--text-secondary);
    border-color: var(--border-light);
}

/* --- Slot rows --- */
.cb-slots {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cb-slot {
    position: relative;
    display: flex;
    align-items: stretch;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: visible;
    transition: border-color 0.15s;
}

.cb-slot:hover {
    border-color: var(--border-light);
}

.cb-slot.is-focused {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.cb-slot-role {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 74px;
    flex-shrink: 0;
    padding: 8px 4px;
    background: var(--bg-secondary);
    border: none;
    border-right: 1px solid var(--border);
    border-radius: var(--radius) 0 0 var(--radius);
    color: var(--text-secondary);
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.cb-slot-role:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.cb-slot-role img,
.cb-slot-role svg {
    width: 16px;
    height: 16px;
    object-fit: contain;
    filter: invert(1);
    opacity: 0.9;
}

.cb-slot-role svg {
    filter: none;
    fill: currentColor;
}

.cb-slot-role .cb-caret {
    width: 9px;
    height: 9px;
    opacity: 0.6;
}

.cb-role-menu {
    position: absolute;
    left: 6px;
    top: calc(100% - 4px);
    z-index: 40;
    min-width: 150px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg, 0 12px 32px rgba(0,0,0,0.5));
    padding: 4px;
}

.cb-role-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.cb-role-opt:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.cb-role-opt.active {
    color: var(--accent);
}

.cb-role-opt img,
.cb-role-opt svg {
    width: 13px;
    height: 13px;
    object-fit: contain;
    filter: invert(1);
    opacity: 0.9;
}

.cb-role-opt svg {
    filter: none;
    fill: currentColor;
}

.cb-slot-body {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    cursor: pointer;
}

.cb-slot-portrait {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.cb-slot-portrait.empty {
    background: var(--bg-secondary);
    border-style: dashed;
}

.cb-slot-info {
    flex: 1;
    min-width: 0;
}

.cb-slot-agent {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
}

.cb-slot-agent.muted {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.82rem;
}

.cb-tag {
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}

.cb-tag-pin {
    color: var(--accent);
    border-color: var(--accent);
    background: transparent;
}

.cb-slot-stats {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 3px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.cb-slot-stats.muted {
    font-size: 0.72rem;
}

.cb-score {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--green, #3ecf8e);
    font-variant-numeric: tabular-nums;
}

.cb-slot-stats em {
    font-style: normal;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.cb-sub {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cb-sub.pos { color: var(--green, #3ecf8e); }
.cb-sub.neg { color: var(--accent, #ff4655); }

.cb-slot-btns {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 6px 8px 6px 0;
    flex-shrink: 0;
}

.cb-icon-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.cb-icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.cb-icon-btn svg {
    width: 12px;
    height: 12px;
}

/* --- Actions / toast (shared look with old builder) --- */
.comp-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.comp-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    font-family: inherit;
}

.comp-btn:hover:not([disabled]) {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.comp-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}

.comp-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.comp-btn-primary:hover:not([disabled]) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.comp-btn-ghost {
    background: transparent;
}

.comp-toast {
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--green-bg);
    border: 1px solid rgba(62, 207, 142, 0.4);
    color: var(--green);
    border-radius: var(--radius);
    font-size: 0.78rem;
    font-weight: 600;
}

/* --- Summary --- */
.comp-summary {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}

.comp-summary-empty {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.comp-summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    font-size: 0.85rem;
}

.comp-summary-avg {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.comp-summary-avg .comp-summary-count {
    color: var(--green, #3ecf8e);
}

.comp-summary-role {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: capitalize;
}

.comp-summary-role img {
    width: 14px;
    height: 14px;
    filter: invert(1);
    opacity: 0.85;
}

.comp-summary-count {
    color: var(--text-primary);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.comp-summary-warn {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    color: var(--yellow);
    font-size: 0.75rem;
    font-weight: 600;
}

/* --- Candidates panel --- */
.comp-picker {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.comp-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.comp-picker-filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.comp-role-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    text-transform: capitalize;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.comp-role-chip:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.comp-role-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.comp-role-icon {
    width: 12px;
    height: 12px;
    object-fit: contain;
    filter: invert(1);
}

.comp-role-chip.active .comp-role-icon {
    filter: none;
}

.cb-cand-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cb-empty {
    background: var(--bg-secondary);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.cb-cand {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.cb-cand:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.cb-cand.is-in {
    opacity: 0.45;
    cursor: default;
}

.cb-cand.is-in:hover {
    border-color: var(--border);
    background: var(--bg-secondary);
}

.cb-cand.is-current {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
    cursor: default;
}

.cb-cand-rank {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.cb-cand-img {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.cb-cand-id {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 90px;
    flex-shrink: 0;
}

.cb-cand-id b {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.cb-cand-id em {
    font-style: normal;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.cb-cand-stats {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.cb-cand-action {
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.cb-cand:hover:not(.is-in):not(.is-current) .cb-cand-action {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.cb-cand.is-current .cb-cand-action {
    color: var(--accent);
    border-color: var(--accent);
}

/* Role accent colors on candidate role tags */
.cb-cand-id em.role-duelist { color: #ff8a9a; }
.cb-cand-id em.role-initiator { color: #8fd0a5; }
.cb-cand-id em.role-controller { color: #9fb6ff; }
.cb-cand-id em.role-sentinel { color: #ffd98a; }

/* --- Saved comps --- */
.comp-saved-section {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.comp-saved-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.comp-saved-head h2 {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.comp-saved-head-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cb-sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
}

.cb-sync-pill a {
    color: var(--accent);
    text-decoration: none;
}

.cb-sync-pill a:hover {
    text-decoration: underline;
}

.cb-sync-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
}

.cb-sync-dot.ok {
    background: var(--green, #3ecf8e);
}

.comp-saved-meta {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.comp-saved-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.comp-saved-empty {
    grid-column: 1 / -1;
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.comp-saved-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s, transform 0.05s;
}

.comp-saved-card:hover {
    border-color: var(--border-light);
}

.comp-saved-card-map {
    position: relative;
    height: 90px;
    background: var(--bg-tertiary) center/cover;
}

.comp-saved-card-map::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(14,16,21,0.2) 0%, rgba(14,16,21,0.85) 100%);
}

.comp-saved-card-map-name {
    position: absolute;
    left: 12px;
    bottom: 8px;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    z-index: 1;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

.comp-saved-card-wr {
    position: absolute;
    right: 10px;
    bottom: 8px;
    z-index: 1;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: var(--green, #3ecf8e);
    font-size: 0.68rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.comp-saved-card-body {
    padding: 12px;
}

.comp-saved-card-agents {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.comp-saved-card-agents .agent-img {
    aspect-ratio: 1;
    border-radius: 4px;
    background: var(--bg-secondary) center/cover;
    border: 1px solid var(--border);
}

.comp-saved-card-filters {
    margin: -4px 0 10px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.comp-saved-card-actions {
    display: flex;
    gap: 6px;
}

.comp-saved-action {
    flex: 1;
    padding: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.comp-saved-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.comp-saved-action.is-danger:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* --- Modals --- */
.comp-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.comp-modal[hidden] {
    display: none;
}

.comp-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}

.comp-modal-panel {
    position: relative;
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.comp-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.comp-modal-head h3 {
    font-size: 1rem;
    font-weight: 700;
}

.comp-modal-close {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
}

.comp-modal-close:hover {
    color: var(--text-primary);
}

.comp-modal-panel .comp-map-grid {
    padding: 16px;
}

/* --- Map grid (in modal) --- */
.comp-map-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.comp-map-card {
    position: relative;
    aspect-ratio: 16/10;
    background: var(--bg-secondary) center/cover;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.05s, border-color 0.15s;
    padding: 0;
}

.comp-map-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.comp-map-card.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent) inset;
}

.comp-map-card-any {
    background: repeating-linear-gradient(45deg, var(--bg-secondary), var(--bg-secondary) 12px, var(--bg-card) 12px, var(--bg-card) 24px);
}

.comp-map-card-name {
    position: absolute;
    inset: auto 0 0 0;
    padding: 10px 12px;
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    background: linear-gradient(180deg, transparent, rgba(0,0,0,0.85));
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
    text-align: left;
}

/* --- Mobile tweaks --- */
@media (max-width: 640px) {
    /* The top navbar barely fits 3 links on phones (pre-existing); drop the
       self-link — the sidebar still navigates here and marks it active. */
    .nav-links > a[href="/comps"] {
        display: none;
    }

    .cb-slot-role {
        width: 58px;
    }
    .cb-slot-role span {
        display: none;
    }
    .cb-cand-id {
        min-width: 70px;
    }
    .cb-cand-stats .cb-sub:nth-child(n+4) {
        display: none;
    }
}
