@use 'variables' as *;

// ─── View toggle (segmented control) ─────────────────────────────────────────
.scores-view-toggle {
    display: flex;
    border-radius: 8px;
    border: 1.5px solid $gray-200;
    overflow: hidden;
    flex-shrink: 0;
}

.svt-btn {
    padding: 5px 14px;
    border: none;
    background: transparent;
    font-size: 0.75rem;
    font-weight: 600;
    color: $gray-500;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;

    &:not(:last-child) {
        border-right: 1.5px solid $gray-200;
    }

    &[aria-pressed="true"],
    &.svt-active {
        background: $red-primary;
        color: $white;
    }

    &:hover:not([aria-pressed="true"]):not(:disabled) {
        background: $gray-100;
        color: $gray-700;
    }

    &:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }
}

// ─── View wrappers ────────────────────────────────────────────────────────────
.scores-bar-view[hidden],
.scores-table-view[hidden] {
    display: none;
}

// ─── Table container ──────────────────────────────────────────────────────────
.scores-table {
    display: flex;
    width: 100%;
    height: 200px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid $gray-200;
    position: relative;
    user-select: none;
    touch-action: none;
    margin-top: 18px;
}

// ─── Column ───────────────────────────────────────────────────────────────────
.stc {
    flex: 0 0 var(--col-width);
    min-width: 56px;
    position: relative;
    background: $gray-100;
    overflow: hidden;
}

// ─── Fill (colored bar rising from bottom) ────────────────────────────────────
.stc-fill {
    position: absolute;
    inset: auto 0 0 0;
    height: var(--score-fill);
    background: var(--col-color);
    pointer-events: none;
    transition: height 0.12s ease-out, background 0.12s ease-out;

    body.scores-dragging-score & {
        transition: none;
        will-change: height;
    }
}

// ─── Score handle ─────────────────────────────────────────────────────────────
.stc-score-handle {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(var(--score-fill) - 9px);
    height: 18px;
    cursor: row-resize;
    touch-action: none;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;

    body.scores-dragging-score & {
        will-change: bottom;
    }

    &::before {
        content: '';
        position: absolute;
        left: 8px;
        right: 8px;
        height: 2px;
        background: rgba(255, 255, 255, 0.7);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
        border-radius: 1px;
    }

    &:hover::before,
    &:focus::before {
        background: $white;
        box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
    }

    &:focus { outline: none; }

    &:focus-visible {
        outline: 2px solid rgba(255, 255, 255, 0.8);
        outline-offset: 1px;
    }
}

// ─── Score value pill ─────────────────────────────────────────────────────────
.stc-score-value {
    position: relative;
    background: $white;
    color: $gray-900;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 99px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    z-index: 1;
    pointer-events: none;
    line-height: 1.5;
}

// ─── Column label overlay ─────────────────────────────────────────────────────
.stc-content {
    position: absolute;
    inset: 0;
    padding: 10px;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: $white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.stc-name {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    align-self: flex-start;
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 7px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.95);
}

.stc-weight-pct {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.1;
    align-self: flex-start;
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 8px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.95);
}

.stc-contribution {
    align-self: flex-start;
    font-size: 0.78rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 7px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.95);
}

// ─── Column divider ───────────────────────────────────────────────────────────
.scores-table-divider {
    flex: 0 0 5px;
    cursor: col-resize;
    touch-action: none;
    background: rgba(255, 255, 255, 0.5);
    position: relative;
    z-index: 3;
    transition: background 0.12s;

    &:hover,
    &:active {
        background: rgba(255, 255, 255, 0.9);
    }

    &::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 2px;
        height: 24px;
        background: rgba(0, 0, 0, 0.15);
        border-radius: 1px;
    }
}

// ─── Global drag cursor overrides ─────────────────────────────────────────────
body.scores-dragging-width {
    cursor: col-resize !important;
    user-select: none !important;

    .stc { will-change: flex-basis; }
}

body.scores-dragging-score {
    cursor: row-resize !important;
    user-select: none !important;
}

// ─── Responsive ───────────────────────────────────────────────────────────────
@media (max-width: $bp-mobile) {
    .scores-table   { height: 170px; }
    .stc-weight-pct { font-size: 1.1rem; }
    .stc-name       { font-size: 0.62rem; }
}
