/**
 * Action Menu Component Styles
 *
 * Prefix: .am-*
 * Uses CSS custom properties from design-tokens.css
 *
 * Components:
 * - Trigger button
 * - Desktop dropdown menu
 * - Mobile bottom sheet
 * - Menu items (shared)
 * - Artist preview rows
 * - Submenu navigation
 */

/* ==========================================================================
   Wrapper
   ========================================================================== */

.am-wrapper {
    position: relative;
    display: inline-block;
}

/* ==========================================================================
   Trigger Button
   ========================================================================== */

.am-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm, 4px);
    color: var(--text-secondary, #999);
    cursor: pointer;
    transition: all var(--transition-base, 0.2s);
}

.am-trigger:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #fff);
}

.am-trigger:focus-visible {
    outline: 2px solid var(--accent-primary, #1DB954);
    outline-offset: 2px;
}

.am-trigger i,
.am-trigger svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Desktop Dropdown
   ========================================================================== */

.am-dropdown {
    position: fixed;
    /* Position is set dynamically via JavaScript */
    min-width: 220px;
    max-width: 300px;
    background: var(--bg-secondary, #1e1e1e);
    border: 1px solid var(--border-primary, #333);
    border-radius: var(--radius-lg, 8px);
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.5));
    z-index: var(--z-dropdown, 1000);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity var(--transition-fast, 150ms),
                transform var(--transition-fast, 150ms),
                visibility var(--transition-fast, 150ms);
    overflow: hidden;
}

.am-dropdown.am-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Open upward when near bottom of viewport */
/* Note: Position is handled via JS fixed positioning, not CSS bottom */
.am-dropdown.am-open-upward {
    /* Just a marker class for animation direction */
    transform: translateY(8px);
}

.am-dropdown.am-open-upward.am-visible {
    transform: translateY(0);
}

/* Open left when near right edge */
.am-dropdown.am-open-left {
    right: auto;
    left: 0;
}

/* ==========================================================================
   Menu Items (shared between dropdown and bottom sheet)
   ========================================================================== */

.am-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-primary, #fff);
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--transition-fast, 150ms);
}

.am-item:hover:not(.am-disabled) {
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
}

.am-item:focus-visible {
    outline: 2px solid var(--accent-primary, #1DB954);
    outline-offset: -2px;
}

.am-item.am-active {
    color: var(--accent-primary, #1DB954);
}

.am-item.am-disabled {
    color: var(--text-disabled, #4d4d4d);
    cursor: not-allowed;
}

/* Item icon */
.am-item-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: inherit;
}

.am-item.am-active .am-item-icon {
    color: var(--accent-primary, #1DB954);
}

/* Item label */
.am-item-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Checkmark for active items */
.am-item-check {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--accent-primary, #1DB954);
}

/* Chevron for submenu items */
.am-item-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-tertiary, #808080);
    transition: transform var(--transition-fast, 150ms);
}

.am-submenu-section.am-expanded > .am-submenu-toggle .am-item-chevron {
    transform: rotate(90deg);
}

/* ==========================================================================
   Divider
   ========================================================================== */

.am-divider {
    height: 1px;
    margin: 4px 0;
    background: var(--border-primary, #333);
}

/* ==========================================================================
   Submenu (Desktop - Accordion style)
   ========================================================================== */

.am-submenu-section {
    position: relative;
}

.am-submenu-toggle {
    /* Inherits from .am-item */
}

.am-submenu {
    display: none;
    background: var(--bg-tertiary, #2a2a2a);
    border-radius: 0;
    overflow: hidden;
    max-height: 0;
    transition: max-height var(--transition-base, 200ms) ease-out;
}

.am-submenu-section.am-expanded .am-submenu {
    display: block;
    max-height: 500px;
}

.am-submenu .am-item {
    padding-left: 28px;
    font-size: 13px;
}

.am-submenu .am-artist-item {
    padding-left: 16px;
}

/* ==========================================================================
   Artist Preview Row
   ========================================================================== */

.am-artist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    /* Adjusted left padding to align 28px play button with 18px menu icons above */
    /* Icon center = 16px + 9px = 25px; Button center should be same, so 25px - 14px = 11px */
    padding: 10px 16px 10px 11px;
}

/* Play button */
.am-preview-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-primary, #333);
    border-radius: 50%;
    color: var(--text-secondary, #999);
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast, 150ms);
}

.am-preview-btn:hover {
    background: var(--accent-primary, #1DB954);
    border-color: var(--accent-primary, #1DB954);
    color: var(--text-inverse, #121212);
}

.am-preview-btn.am-playing {
    background: var(--accent-primary, #1DB954);
    border-color: var(--accent-primary, #1DB954);
    color: var(--text-inverse, #121212);
}

.am-preview-btn i,
.am-preview-btn svg {
    width: 14px;
    height: 14px;
    /* Filled icons like Seattle Artists - override Lucide's fill="none" */
    fill: currentColor !important;
    stroke: currentColor;
    stroke-width: 1.5;
}

/* Play icon - slight offset for visual centering of triangle */
.am-preview-btn .am-icon-play {
    margin-left: 2px;
}

/* Pause icon - hidden by default */
.am-preview-btn .am-icon-pause {
    display: none;
}

/* Playing state - swap icon visibility */
.am-preview-btn.am-playing .am-icon-play {
    display: none;
}

.am-preview-btn.am-playing .am-icon-pause {
    display: flex;
}

/* Artist name */
.am-artist-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    color: var(--text-primary, #fff);
}

/* Details link (arrow) */
.am-details-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: var(--text-tertiary, #808080);
    text-decoration: none;
    flex-shrink: 0;
    transition: color var(--transition-fast, 150ms);
}

.am-details-link:hover {
    color: var(--text-primary, #fff);
}

.am-details-link i,
.am-details-link svg {
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   Mobile Bottom Sheet
   ========================================================================== */

.am-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop-medium, rgba(0, 0, 0, 0.7));
    z-index: var(--z-modal-backdrop, 1040);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base, 200ms),
                visibility var(--transition-base, 200ms);
}

.am-sheet-backdrop.am-visible {
    opacity: 1;
    visibility: visible;
}

.am-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 80vh;
    background: var(--bg-secondary, #1e1e1e);
    border-radius: var(--radius-xl, 12px) var(--radius-xl, 12px) 0 0;
    z-index: var(--z-modal, 1050);
    transform: translateY(100%);
    transition: transform var(--transition-slow, 300ms) cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.am-sheet.am-visible {
    transform: translateY(0);
}

/* Drag handle */
.am-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 8px;
    cursor: grab;
}

.am-sheet-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    background: var(--bg-hover, #333);
    border-radius: var(--radius-full, 9999px);
}

/* Sheet header */
.am-sheet-header {
    padding: 0 20px 16px;
    text-align: center;
    border-bottom: 1px solid var(--border-primary, #333);
}

.am-sheet-header-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 12px;
    border-bottom: 1px solid var(--border-primary, #333);
}

.am-sheet-back {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--accent-primary, #1DB954);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

.am-sheet-back i,
.am-sheet-back svg {
    width: 18px;
    height: 18px;
}

.am-sheet-nav-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.am-sheet-nav-spacer {
    width: 60px; /* Balance the back button */
}

.am-sheet-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #fff);
    margin: 0 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.am-sheet-subtitle {
    font-size: 13px;
    color: var(--text-secondary, #b3b3b3);
    margin: 0;
}

/* Sheet body */
.am-sheet-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

/* Page-based navigation for submenus */
.am-sheet-page {
    display: none;
}

.am-sheet-page.am-page-active {
    display: block;
}

/* Slide animations */
.am-sheet-page.am-slide-out-left {
    animation: am-slide-out-left var(--transition-base, 200ms) ease-out forwards;
}

.am-sheet-page.am-slide-in-right {
    animation: am-slide-in-right var(--transition-base, 200ms) ease-out forwards;
}

.am-sheet-page.am-slide-out-right {
    animation: am-slide-out-right var(--transition-base, 200ms) ease-out forwards;
}

.am-sheet-page.am-slide-in-left {
    animation: am-slide-in-left var(--transition-base, 200ms) ease-out forwards;
}

@keyframes am-slide-out-left {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-30%); opacity: 0; }
}

@keyframes am-slide-in-right {
    from { transform: translateX(30%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes am-slide-out-right {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(30%); opacity: 0; }
}

@keyframes am-slide-in-left {
    from { transform: translateX(-30%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Sheet footer */
.am-sheet-footer {
    padding: 12px 20px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-primary, #333);
}

.am-sheet-cancel {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--bg-tertiary, #2a2a2a);
    border: none;
    border-radius: var(--radius-md, 6px);
    color: var(--text-primary, #fff);
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    text-align: center;
    cursor: pointer;
    transition: background var(--transition-fast, 150ms);
}

.am-sheet-cancel:hover {
    background: var(--bg-hover, #333);
}

/* Mobile-specific item styles */
.am-sheet .am-item {
    padding: 14px 20px;
    font-size: 16px;
}

.am-sheet .am-item-icon {
    width: 22px;
    height: 22px;
}

.am-sheet .am-artist-item {
    /* Adjusted left padding to align 36px play button with 22px menu icons */
    /* Icon center = 20px + 11px = 31px; Button center at 31px, so 31px - 18px = 13px */
    padding: 12px 20px 12px 13px;
}

.am-sheet .am-preview-btn {
    width: 36px;
    height: 36px;
}

.am-sheet .am-preview-btn i,
.am-sheet .am-preview-btn svg {
    width: 18px;
    height: 18px;
}

.am-sheet .am-details-link {
    width: 36px;
    height: 36px;
}

.am-sheet .am-details-link i,
.am-sheet .am-details-link svg {
    width: 22px;
    height: 22px;
}

/* ==========================================================================
   Responsive: Hide dropdown on mobile, show bottom sheet
   ========================================================================== */

@media (max-width: 768px) {
    .am-dropdown {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .am-sheet-backdrop,
    .am-sheet {
        display: none !important;
    }
}

/* ==========================================================================
   Audio Player (Hidden, controlled by JS)
   ========================================================================== */

.am-audio-player {
    display: none;
}

/* ==========================================================================
   Utility: Body scroll lock when sheet is open
   ========================================================================== */

body.am-sheet-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}
