/* ── Athletes View — scoped to .ap-athletes-view ── */

/* ── Layout ── */

.ap-athletes-view {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 0;
    overflow: hidden;
}

/* ── Mobile back button (desktop: hidden) ── */

.ap-mobile-back {
    display: none;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 0;
    color: var(--text-muted, #6b7280);
    font: inherit;
    font-size: 14px;
    padding: 12px 16px 4px;
    cursor: pointer;
    text-align: left;
}

.ap-mobile-back:hover {
    color: var(--text, #111);
}

@media (max-width: 1023px) {
    .ap-athletes-view {
        grid-template-columns: 1fr;
    }

    /* Default (no focus): show rail only */
    .ap-athletes-view .ap-rail {
        display: flex;
    }
    .ap-athletes-view .ap-detail {
        display: none;
    }

    /* When focused or creating: show detail only */
    .ap-athletes-view.has-focus .ap-rail {
        display: none;
    }
    .ap-athletes-view.has-focus .ap-detail {
        display: flex;
        flex-direction: column;
    }

    .ap-athletes-view.has-focus .ap-mobile-back {
        display: inline-flex;
    }
}

/* ── Rail ── */

.ap-rail {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    overflow: hidden;
    background: var(--shell);
}

.ap-rail-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 20px 16px 10px;
    flex-shrink: 0;
}

.ap-rail-head h2 {
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

.ap-rail-count {
    font-size: 11px;
    color: var(--text-faint);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 7px;
    border-radius: 6px;
}

/* ── Rail search ── */

.ap-rail-search {
    position: relative;
    margin: 0 10px 8px;
    flex-shrink: 0;
}

.ap-rail-search-icon {
    position: absolute;
    left: 9px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.ap-rail-search-input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 6px 10px 6px 30px;
    font-size: 12px;
    color: var(--text);
    font-family: inherit;
    outline: none;
    transition: border-color 120ms ease;
}

.ap-rail-search-input::placeholder { color: var(--text-faint); }
.ap-rail-search-input:focus { border-color: var(--signal); }

/* ── Rail list ── */

.ap-rail-list {
    flex: 1;
    overflow-y: auto;
    padding: 2px 8px 8px;
}

.ap-rail-loading {
    padding: 20px 16px;
    color: var(--text-faint);
    font-size: 13px;
}

/* ── Group separators ── */

.ap-grp {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 4px 4px;
}

.ap-grp::after {
    content: '';
    flex: 1;
    height: 1px;
    border-top: 1px dashed var(--line);
}

.ap-grp-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
}

.ap-grp-count {
    font-size: 10px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    letter-spacing: 0;
}

/* ── Rail Item ── */

.ap-rail-item {
    display: flex;
    flex-direction: column;
    padding: 10px 10px 8px;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: background 120ms ease;
    margin-bottom: 1px;
}

.ap-rail-item:hover { background: rgba(255, 255, 255, 0.04); }

.ap-rail-item.selected { background: rgba(255, 255, 255, 0.06); }

.ap-ri-top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.ap-ri-meta { flex: 1; min-width: 0; }

.ap-ri-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 1px;
}

/* DEMO chip on seeded athletes */
.ap-rail-item.is-demo .ap-ri-name::after {
    content: "DEMO";
    margin-left: 8px;
    font-size: 9px;
    letter-spacing: 0.1em;
    color: var(--text-faint);
    border: 1px solid var(--line);
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 500;
    vertical-align: middle;
}

.ap-ri-sport {
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.04em;
}

.ap-ri-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-faint);
}

.ap-ri-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ap-ri-dot.stable      { background: #4ade80; }
.ap-ri-dot.volatile    { background: #facc15; }
.ap-ri-dot.building    { background: var(--signal); }
.ap-ri-dot.at-risk     { background: #f87171; }
.ap-ri-dot.constrained { background: #facc15; }
.ap-ri-dot.high-risk   { background: #f87171; }

/* Connector for selected rail item */

.ap-rail-item.selected::after {
    content: '';
    position: absolute;
    right: -1px;
    top: 50%;
    transform: translateY(-50%);
    height: 1px;
    background: var(--signal);
    animation: apDashIn 300ms ease forwards;
}

.ap-rail-item.selected::before {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--signal);
    animation: apDotPop 400ms 150ms ease both;
}

@keyframes apDashIn {
    from { width: 0; }
    to   { width: 18px; }
}

@keyframes apDotPop {
    from { transform: translateY(-50%) scale(0); }
    to   { transform: translateY(-50%) scale(1); }
}

/* ── Avatar ── */

.ap-avatar {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.02em;
    user-select: none;
}

.ap-avatar.av-0 { background: color-mix(in srgb, var(--signal) 20%, var(--shell)); color: var(--signal); }
.ap-avatar.av-1 { background: rgba(212, 165, 116, 0.18); color: #d4a574; }
.ap-avatar.av-2 { background: rgba(155, 142, 196, 0.18); color: #9b8ec4; }
.ap-avatar.av-3 { background: rgba(232, 140, 160, 0.18); color: #e88ca0; }

/* ── Workspace-active badge ── */

.ap-workspace-badge {
    font-size: 9px;
    letter-spacing: 0.08em;
    background: color-mix(in srgb, var(--signal) 12%, transparent);
    color: var(--signal);
    border: 1px solid color-mix(in srgb, var(--signal) 25%, transparent);
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* ── Detail pane ── */

.ap-detail {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 24px 28px 0;
    background: var(--bg);
}

.ap-detail-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-faint);
    font-size: 13px;
}

.ap-detail-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.ap-detail-avatar {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    font-size: 18px;
}

.ap-detail-header-body {
    flex: 1;
    min-width: 0;
}

.ap-detail-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.ap-detail-name {
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    line-height: 1.15;
}

.ap-detail-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 8px;
}

.ap-chip {
    font-size: 11px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-soft);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--line);
}

/* ── Detail subrow ── */

.ap-detail-subrow {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-faint);
}

.ap-subrow-sep {
    opacity: 0.4;
}

/* ── Action buttons ── */

.ap-action-btns {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.ap-action-btn {
    font-size: 11px;
    font-family: inherit;
    color: var(--text-faint);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    transition: color 120ms, background 120ms;
    white-space: nowrap;
}

.ap-action-btn:hover {
    color: var(--text-soft);
    background: rgba(255, 255, 255, 0.07);
}

/* ── Tabs ── */

.ap-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0;
    flex-shrink: 0;
}

.ap-tab {
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text-faint);
    cursor: pointer;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-family: inherit;
    transition: color 120ms ease;
}

.ap-tab:hover { color: var(--text-soft); }

.ap-tab.active {
    color: var(--text);
    border-bottom-color: var(--signal);
    font-weight: 600;
}

/* ── Tab body ── */

.ap-tab-body {
    flex: 1;
    overflow-y: auto;
    padding-top: 20px;
    padding-bottom: 32px;
}

/* ── Metrics strip ── */

.ap-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}

.ap-metric {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 16px 12px;
}

.ap-metric-top {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 4px;
}

.ap-metric-value {
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.ap-metric-trend {
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

.ap-metric-trend.up   { color: #4ade80; }
.ap-metric-trend.down { color: #f87171; }

.ap-metric-label {
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.04em;
}

/* ── Sections ── */

.ap-sections {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.ap-section {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 16px;
    padding: 20px 0;
    border-top: 1px solid var(--line);
}

.ap-section:first-child {
    border-top: none;
}

.ap-section-side {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 2px;
}

.ap-section-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-soft);
}

.ap-section-desc {
    font-size: 11px;
    color: var(--text-faint);
    line-height: 1.5;
}

.ap-section-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-content: start;
}

/* ── Profile fields ── */

.ap-field { display: flex; flex-direction: column; gap: 4px; }

.ap-field-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.ap-field-value {
    font-size: 13px;
    color: var(--text);
}

/* ── Stub panels ── */

.ap-stub-message {
    color: var(--text-faint);
    font-size: 13px;
    line-height: 1.6;
}

/* ── Rail head layout ── */

.ap-rail-head-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── New athlete button ── */

.ap-new-btn {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.ap-new-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

/* ── Action button variants ── */

.ap-action-btn--danger {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.3);
}

.ap-action-btn--danger:hover {
    background: rgba(248, 113, 113, 0.08);
    color: #fca5a5;
}

.ap-action-btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Edit mode: field inputs ── */

.ap-field-input {
    font-size: 13px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 8px;
    width: 100%;
    outline: none;
    transition: border-color 0.15s;
}

.ap-field-input:focus {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Save bar (edit + create) ── */

.ap-save-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    margin-top: 8px;
    background: var(--shell);
    position: sticky;
    bottom: 0;
}

.ap-save-btn {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 7px;
    border: none;
    background: var(--accent, #3b82f6);
    color: #fff;
    cursor: pointer;
    transition: opacity 0.15s;
}

.ap-save-btn:hover {
    opacity: 0.85;
}

.ap-cancel-btn {
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.15s;
}

.ap-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* ── Create athlete panel ── */

.ap-create-panel {
    padding: 32px 40px;
    max-width: 560px;
}

.ap-create-title {
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 24px;
}

.ap-create-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 8px;
}

.ap-create-field--wide {
    grid-column: 1 / -1;
}

.ap-create-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 6px;
}

.ap-create-input {
    width: 100%;
    font-size: 13px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
    box-sizing: border-box;
}

.ap-create-input:focus {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.08);
}

.ap-create-panel .ap-save-bar {
    padding: 16px 0 0;
    border-top: none;
    background: transparent;
    position: static;
}

/* ── Delete confirm modal ── */

.ap-confirm-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: inherit;
}

.ap-detail {
    position: relative;
}

.ap-confirm-modal {
    background: var(--bg, #fff);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 24px 28px;
    max-width: 380px;
    width: calc(100% - 40px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}

.ap-confirm-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}

.ap-confirm-body {
    font-size: 13px;
    color: var(--text-2, var(--text-muted));
    line-height: 1.6;
    margin-bottom: 20px;
}

.ap-confirm-btns {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.ap-confirm-destroy {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 7px;
    border: none;
    background: #dc2626;
    color: #fff;
    cursor: pointer;
    transition: opacity 0.15s;
}

.ap-confirm-destroy:hover {
    opacity: 0.85;
}

.ap-confirm-destroy[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
}
