/**
 * SelectionList Component Styles
 * 
 * LinkedIn-style FLAT LIST layout for selection modals.
 * Features:
 * - Full-width rows with subtle 1px dividers (no card borders)
 * - .sl-row: row container
 * - .sl-left: avatar area (circular, left)
 * - .sl-main: title/subtitle (center, flex-grow)
 * - .sl-right: trailing actions (right-aligned)
 * - Subtle hover/selected backgrounds
 * - Accessible keyboard navigation
 * 
 * Class naming: .sl-* to avoid conflicts with legacy .friend-item etc.
 */

/* ═══════════════════════════════════════════════════════════════════════════
   DEBUG STYLES (only when SELECTION_LIST_DEBUG = true in JS)
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-row.sl-debug {
    border-top: 3px solid #22c55e !important;
    position: relative;
}

.sl-row.sl-debug::before {
    content: 'SL';
    position: absolute;
    top: 2px;
    right: 4px;
    background: #22c55e;
    color: white;
    font-size: 9px;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 3px;
    z-index: 10;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   ROW STYLES - Flat list rows with subtle dividers
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-md, 12px);
    padding: 10px 12px 12px;
    background: transparent;
    cursor: pointer;
    transition: background-color 0.15s ease;
    position: relative;
    
    /* FLAT LIST: No card borders, no border-radius, no margins */
    border: none;
    border-radius: 0;
    margin: 0;
    width: 100%;
    box-sizing: border-box;
    
    /* Divider on top of EVERY row (including first) */
    border-top: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

/* Hover state - subtle background tint */
.sl-row:hover:not(.sl-disabled) {
    background: var(--color-bg-hover, rgba(0, 0, 0, 0.04));
}

/* Apple list system: modal lists use consistent insets/density */
.c-modal-scroll-body .sl-row {
    gap: var(--yrh-apple-row-gap, 12px);
    padding: var(--yrh-apple-row-padding-y, 11px) var(--yrh-apple-list-padding-x, 20px);
    border-top-color: var(--yrh-apple-separator-color, rgba(0, 0, 0, 0.14));
}

@media (hover: hover) and (pointer: fine) {
    .c-modal-scroll-body .sl-row:hover:not(.sl-disabled) {
        background: var(--yrh-apple-row-hover-bg, rgba(0, 0, 0, 0.04));
    }
}

.c-modal-scroll-body .sl-row:active:not(.sl-disabled) {
    background: var(--yrh-apple-row-active-bg, rgba(0, 0, 0, 0.10));
}

.c-modal-scroll-body .sl-left {
    width: var(--yrh-apple-avatar-size, 40px);
    height: var(--yrh-apple-avatar-size, 40px);
}

/* Selected state - soft highlight with left accent, full row coverage */
.sl-row.sl-selected {
    background: var(--color-brand-primary-10, rgba(102, 126, 234, 0.08));
    box-shadow: inset 3px 0 0 0 var(--color-primary, #667eea);
}

.sl-row.sl-selected:hover {
    background: var(--color-brand-primary-15, rgba(102, 126, 234, 0.12));
}

/* Focus state for keyboard navigation */
.sl-row:focus {
    outline: none;
}

.sl-row:focus-visible {
    outline: 2px solid var(--color-primary, #667eea);
    outline-offset: -2px;
    z-index: 1;
}

/* Disabled state */
.sl-row.sl-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Special items (All Timelines, No Timeline) */
.sl-row.sl-special {
    /* Slightly muted to distinguish from regular items */
    position: relative;
}

.sl-row.sl-special .sl-left {
    background: var(--color-text-tertiary, #999);
    font-size: 1em;
}

/* ═══════════════════════════════════════════════════════════════════════════
   AVATAR / LEFT SECTION
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-left {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gradient-primary, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1.1em;
    overflow: hidden;
}

.sl-left.has-image {
    background: var(--color-bg-secondary, #f5f5f5);
}

.sl-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN / INFO SECTION (Title & Subtitle)
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sl-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text-primary, #1a1a1a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.sl-subtitle {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--color-text-muted, #666);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RIGHT / TRAILING SECTION (Actions/Icons)
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Prevent trailing actions from triggering row click */
.sl-right button,
.sl-right a,
.sl-right .btn-small {
    position: relative;
    z-index: 2;
}

/* ═══════════════════════════════════════════════════════════════════════════
   OFFICIAL FRIEND BADGE (admin account styling)
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-row.official-friend {
    background: linear-gradient(135deg, rgba(240, 247, 255, 0.5) 0%, rgba(245, 240, 255, 0.5) 100%);
}

.sl-row.official-friend .sl-left {
    border: 2px solid var(--color-primary, #667eea);
}

.sl-row .official-badge {
    display: inline-block;
    background: var(--color-primary, #667eea);
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: 8px;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE ADJUSTMENTS
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .sl-row {
        padding: 8px 10px;
        gap: 10px;
    }

    .sl-left {
        width: 36px;
        height: 36px;
        font-size: 1em;
    }

    .sl-title {
        font-size: 0.875rem;
    }

    .sl-subtitle {
        font-size: 0.75rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TIMELINE PICKER - Reset any inherited card styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* Remove section borders to avoid double-divider noise with row rules */
.timeline-picker-collection-section {
    border-bottom: none;
}

/* Header styling: spacing + typography only (no borders) */
.timeline-picker-collection-section .group-section-header {
    background: transparent;
    border: none;
    padding: 14px 12px 6px;
    margin-top: 0;
}

.timeline-picker-collection-section .group-section-header:hover {
    background: transparent;
}

/* Remove container padding/gap that creates visual spacing between rows */
.timeline-picker-list,
.timeline-picker-collection-list {
    padding: 0 12px 12px;
    gap: 0;
}

.timeline-picker-list .sl-row,
.timeline-picker-collection-list .sl-row {
    /* Ensure flat styling: no cards, no margins, no gaps */
    border: none;
    border-radius: 0;
    margin: 0;
    box-shadow: none;
    background: transparent;
    
    /* Divider on top of every row */
    border-top: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

/* Bottom divider for last row in each list */
.timeline-picker-list .sl-row:last-child,
.timeline-picker-collection-list .sl-row:last-child {
    border-bottom: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

.timeline-picker-list .sl-row:hover:not(.sl-disabled),
.timeline-picker-collection-list .sl-row:hover:not(.sl-disabled) {
    background: var(--color-bg-hover, rgba(0, 0, 0, 0.04));
}

.timeline-picker-list .sl-row.sl-selected,
.timeline-picker-collection-list .sl-row.sl-selected {
    background: var(--color-brand-primary-10, rgba(102, 126, 234, 0.08));
    box-shadow: inset 3px 0 0 0 var(--color-primary, #667eea);
}

/* ═══════════════════════════════════════════════════════════════════════════
   FRIENDS MODAL - Reset any inherited card styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* The legacy friends list uses flex-gap for card rows; remove it for sl-row lists. */
#friendsModal .friend-list {
    gap: 0;
}

#friendsModal .friend-list .sl-row {
    /* Ensure flat styling: no cards, no margins, no gaps */
    border: none;
    border-radius: 0;
    margin: 0;
    box-shadow: none;
    background: transparent;
    cursor: default;
    
    /* Divider on top of every row */
    border-top: 1px solid var(--yrh-apple-separator-color, rgba(0, 0, 0, 0.14));
}

/* Bottom divider for last row */
#friendsModal .friend-list .sl-row:last-child {
    border-bottom: 1px solid var(--yrh-apple-separator-color, rgba(0, 0, 0, 0.14));
}

#friendsModal .friend-list .sl-row:hover:not(.sl-disabled) {
    background: transparent;
}

#friendsModal .friend-list .sl-row:active:not(.sl-disabled) {
    background: transparent;
}

#friendsModal .friend-list .sl-row.sl-selected {
    background: var(--color-brand-primary-10, rgba(102, 126, 234, 0.08));
    box-shadow: inset 3px 0 0 0 var(--color-primary, #667eea);
}

/* Official friend special styling (admin account) */
#friendsModal .friend-list .sl-row.official-friend {
    background: linear-gradient(135deg, rgba(240, 247, 255, 0.5) 0%, rgba(245, 240, 255, 0.5) 100%);
}

#friendsModal .friend-list .sl-row.official-friend {
    border-top: 1px solid var(--color-primary-light, rgba(102, 126, 234, 0.3));
}

/* ═══════════════════════════════════════════════════════════════════════════
   LEGACY COMPATIBILITY - friend-item-actions styling
   These classes are used in trailing HTML for action buttons
   ═══════════════════════════════════════════════════════════════════════════ */

.sl-row .friend-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sl-row .friend-item-actions .btn-small {
    padding: 6px 8px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--color-text-secondary, #666);
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 500;
}

.sl-row .friend-item-actions .btn-small:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text-primary, #222);
}

.sl-row .friend-item-actions .btn-small:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.12);
}

.sl-row .friend-item-actions .btn-small.message {
    padding: 6px 10px;
    letter-spacing: 0.01em;
}

.sl-row .friend-item-actions .profile-options-btn {
    padding: 6px;
}

.sl-row .friend-item-actions .btn-small svg {
    width: 16px;
    height: 16px;
}

/* Profile options menu positioning */
.sl-row .profile-options-container {
    position: relative;
}

.sl-row .profile-options-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    min-width: 140px;
    background: var(--color-bg-primary, white);
    border: 1px solid var(--color-border-light, #e5e5e5);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    display: none;
}

.sl-row .profile-options-menu.active,
.sl-row .profile-options-menu.show {
    display: block;
}

.sl-row .profile-options-menu button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-text-primary, #333);
}

.sl-row .profile-options-menu button:hover {
    background: var(--color-bg-hover, rgba(0, 0, 0, 0.04));
}

/* ═══════════════════════════════════════════════════════════════════════════
   FRIEND ROW POPOVER (Apple-style)
   ═══════════════════════════════════════════════════════════════════════════ */

.profile-options-menu.friend-row-menu {
    display: block; /* keep in DOM; opacity/transform handle visibility */
    background: var(--color-bg-primary, #fff);
    border-radius: 14px;
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.12),
        0 2px 6px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 6px 0;
    opacity: 0;
    transform: scale(0.96) translateY(4px);
    transition:
        opacity 160ms cubic-bezier(0.2, 0.8, 0.2, 1),
        transform 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
    pointer-events: none;
    transform-origin: var(--menu-arrow-x, 24px) 0%;
}

.profile-options-menu.friend-row-menu.show {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.profile-options-menu.friend-row-menu.is-closing {
    opacity: 0;
    transform: scale(0.98) translateY(2px);
    transition:
        opacity 100ms cubic-bezier(0.2, 0.8, 0.2, 1),
        transform 100ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.profile-options-menu.friend-row-menu[data-placement="top"] {
    transform-origin: var(--menu-arrow-x, 24px) 100%;
}

.profile-options-menu.friend-row-menu::before {
    background: var(--color-bg-primary, #fff);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.profile-options-menu.friend-row-menu .friend-menu-item {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-primary, #222);
    padding: 10px 14px;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.profile-options-menu.friend-row-menu .friend-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.profile-options-menu.friend-row-menu .friend-menu-item.is-danger {
    color: #d92d20;
}

.profile-options-menu.friend-row-menu .friend-menu-item.is-danger:hover {
    background: rgba(217, 45, 32, 0.12);
}

@media (prefers-reduced-motion: reduce) {
    .profile-options-menu.friend-row-menu {
        transition: opacity 120ms ease;
        transform: none;
    }

    .profile-options-menu.friend-row-menu.show {
        transform: none;
    }

    .profile-options-menu.friend-row-menu.is-closing {
        transform: none;
        transition: opacity 80ms ease;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   CANVAS CONTEXT SWITCHER (Profile Picker)
   Flat list styling for profile/friend selection
   ═══════════════════════════════════════════════════════════════════════════ */

.canvas-context-switcher-list .sl-row {
    /* Ensure flat styling: no cards, no margins, no gaps */
    border: none;
    border-radius: 0;
    margin: 0;
    box-shadow: none;
    background: transparent;
    
    /* Divider above each row (avoid double-thick lines between rows) */
    border-top: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

/* Profile picker labels (Apple-like) */
.canvas-context-switcher-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted, #777);
    padding: 10px 12px 6px;
    border: none;
}

/* Space after current profile row before other profiles label */
.canvas-context-switcher-section-you {
    margin-bottom: 10px;
    border-bottom: none;
    padding-bottom: 0;
}

/* Current profile row (“You”): top + bottom border (profile box) */
.canvas-context-switcher-section-you .sl-row {
    border-top: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
    border-bottom: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

/* Last profile row: add a bottom border to end the list cleanly */
.canvas-context-switcher-list .sl-row:last-of-type {
    border-bottom: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

/* Space between current profile and other profiles group */
.canvas-context-switcher-section + .canvas-context-switcher-section {
    margin-top: 10px;
}

.canvas-context-switcher-list .sl-row:hover:not(.sl-disabled) {
    background: var(--color-bg-hover, rgba(0, 0, 0, 0.04));
}

.canvas-context-switcher-list .sl-row.sl-selected {
    background: var(--color-brand-primary-10, rgba(102, 126, 234, 0.08));
    box-shadow: inset 3px 0 0 0 var(--color-primary, #667eea);
}

/* ═══════════════════════════════════════════════════════════════════════════
   EVENT MANAGER TIMELINE PICKER
   Flat list styling for event library timeline filter
   ═══════════════════════════════════════════════════════════════════════════ */

#em-timeline-picker-list .sl-row {
    /* Ensure flat styling: no cards, no margins, no gaps */
    border: none;
    border-radius: 0;
    margin: 0;
    box-shadow: none;
    background: transparent;
    
    /* Divider on top of every row */
    border-top: 1px solid var(--color-border-lighter, rgba(0, 0, 0, 0.08));
}

#em-timeline-picker-list .sl-row:hover:not(.sl-disabled) {
    background: var(--color-bg-hover, rgba(0, 0, 0, 0.04));
}

#em-timeline-picker-list .sl-row.sl-selected {
    background: var(--color-brand-primary-10, rgba(102, 126, 234, 0.08));
    box-shadow: inset 3px 0 0 0 var(--color-primary, #667eea);
}
