/* ================================================
   Navigation Mode Button Customizer — Edit Mode Styles
   ================================================ */

/* ---- Jiggle Animation ---- */
@keyframes navBtnJiggle {
    0%, 100% { transform: rotate(-1.5deg); }
    50% { transform: rotate(1.5deg); }
}

.nav-customizer-jiggle {
    animation: navBtnJiggle 0.25s ease-in-out infinite alternate;
    will-change: transform;
}

/* ---- Remove Badge (✕) ---- */
.nav-btn-remove-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    line-height: 1;
    border: 2px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s;
}

.nav-btn-remove-badge:active {
    transform: scale(0.85);
}

/* ---- Drag Handle ---- */
.nav-btn-drag-handle {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 2px;
    cursor: grab;
    z-index: 5;
    user-select: none;
    -webkit-user-select: none;
    line-height: 1;
    padding: 2px 4px;
}

.nav-btn-drag-handle:active {
    cursor: grabbing;
}

/* ---- SortableJS Ghost & Chosen ---- */
.sortable-ghost {
    opacity: 0.3;
    border: 2px dashed rgba(255, 255, 255, 0.4) !important;
    border-radius: 50%;
    background: transparent !important;
}

.sortable-chosen {
    transform: scale(1.08) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
    z-index: 100 !important;
    animation: none !important;
}

.sortable-drag {
    opacity: 0.95 !important;
}

/* ---- Add Button (+ trigger) ---- */
.nav-btn-add-trigger {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.6);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.nav-btn-add-trigger:hover,
.nav-btn-add-trigger:active {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.nav-btn-add-icon {
    font-weight: 300;
    line-height: 1;
}

/* ---- Action buttons visual state during edit mode ---- */
/* Actions are blocked by JS (editMode check in _wireAction).
   pointer-events must stay auto so drag handles + ✕ badges work. */
.nav-customizer-edit .nav-mode-action-btn:not(.nav-mode-edit-btn):not(.nav-customizer-jiggle) {
    opacity: 0.4;
}

/* ---- Reset to Default Button (shown in edit mode) ---- */
.nav-customizer-reset-btn {
    position: absolute;
    right: 16px;
    bottom: 100px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    background: rgba(44, 44, 46, 0.9);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    color: #FF9F0A;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--ios-font, 'Outfit', -apple-system, sans-serif);
    cursor: pointer;
    z-index: 1015;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

.nav-customizer-reset-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.nav-customizer-reset-btn:active {
    transform: scale(0.95);
    background: rgba(44, 44, 46, 1);
}

/* ---- Edit Trigger Button Active State ---- */
.nav-mode-edit-btn {
    opacity: 0.6;
    transition: opacity 0.2s, background 0.2s;
}

.nav-mode-edit-btn:hover,
.nav-mode-edit-btn.nav-mode-edit-active {
    opacity: 1;
    background: rgba(52, 199, 89, 0.3) !important;
}

/* ================================================
   Button Library (Bottom Sheet / Side Panel)
   ================================================ */

.nav-btn-library-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: auto;
}

.nav-btn-library-backdrop.visible {
    opacity: 1;
}

.nav-btn-library {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    background: rgba(28, 28, 30, 0.97);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-radius: 20px 20px 0 0;
    z-index: 2001;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    pointer-events: auto;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
}

.nav-btn-library.visible {
    transform: translateY(0);
}

/* Desktop: floating side panel instead of bottom sheet */
@media (min-width: 1024px) {
    .nav-btn-library {
        bottom: auto;
        left: auto;
        right: 80px;
        top: 50%;
        transform: translateY(-50%) translateX(20px);
        max-height: 80vh;
        width: 320px;
        border-radius: 16px;
        opacity: 0;
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
    }

    .nav-btn-library.visible {
        transform: translateY(-50%) translateX(0);
        opacity: 1;
    }
}

.nav-btn-library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.nav-btn-library-title {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin: 0;
    font-family: 'Outfit', sans-serif;
}

.nav-btn-library-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.nav-btn-library-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-btn-library-subtitle {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 12px 0;
}

.nav-btn-library-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-btn-library-category {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.4);
    padding: 8px 0 4px;
    font-family: 'Outfit', sans-serif;
}

.nav-btn-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
}

.nav-btn-library-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    position: relative;
}

.nav-btn-library-item:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.nav-btn-library-item:active {
    transform: scale(0.95);
}

.nav-btn-library-item.placed {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.nav-btn-library-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.nav-btn-library-icon svg {
    width: 20px;
    height: 20px;
}

.nav-btn-library-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    line-height: 1.2;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-btn-library-placed {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    color: rgba(52, 199, 89, 0.8);
    font-weight: 700;
}

/* ================================================
   Undo Toast
   ================================================ */

.nav-btn-undo-toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(50, 50, 54, 0.95);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    font-size: 14px;
    z-index: 2100;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    white-space: nowrap;
}

.nav-btn-undo-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.nav-btn-undo-action {
    border: none;
    background: none;
    color: #34C759;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.nav-btn-undo-action:hover {
    background: rgba(52, 199, 89, 0.15);
}

/* ================================================
   Context Menu
   ================================================ */

.nav-btn-context-menu {
    position: fixed;
    background: rgba(44, 44, 46, 0.97);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-radius: 12px;
    min-width: 180px;
    z-index: 2200;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.15s, transform 0.15s;
    pointer-events: auto;
}

.nav-btn-context-menu.visible {
    opacity: 1;
    transform: scale(1);
}

.nav-btn-context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-btn-context-item:last-child {
    border-bottom: none;
}

.nav-btn-context-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.nav-btn-context-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.nav-btn-context-danger {
    color: #FF3B30;
}

.nav-btn-context-disabled {
    color: rgba(255, 255, 255, 0.35);
    cursor: default;
    pointer-events: none;
    font-style: italic;
}

/* ================================================
   Night Mode Overrides
   ================================================ */

.nav-mode-overlay.night-mode .nav-btn-library {
    background: rgba(10, 10, 12, 0.98);
}

.nav-mode-overlay.night-mode .nav-btn-undo-toast {
    background: rgba(20, 20, 22, 0.96);
}

.nav-mode-overlay.night-mode .nav-btn-context-menu {
    background: rgba(15, 15, 17, 0.98);
}

.nav-mode-overlay.night-mode .nav-btn-remove-badge {
    border-color: rgba(0, 0, 0, 0.6);
}

.nav-mode-overlay.night-mode .nav-btn-add-trigger {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.03);
}

/* Dark theme */
[data-theme="dark"] .nav-btn-library {
    background: rgba(10, 10, 12, 0.98);
}

[data-theme="dark"] .nav-btn-undo-toast {
    background: rgba(20, 20, 22, 0.96);
}

/* ================================================
   Landscape Overrides
   ================================================ */

.nav-mobile.nav-landscape .nav-btn-add-trigger {
    width: 36px;
    height: 36px;
    font-size: 18px;
}

.nav-mobile.nav-landscape .nav-btn-drag-handle {
    top: auto;
    left: -14px;
    top: 50%;
    transform: translateY(-50%) rotate(90deg);
}

.nav-mobile.nav-landscape .nav-btn-remove-badge {
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    font-size: 9px;
}

/* ================================================
   Pointer Events for Overlay Elements
   ================================================ */

.nav-mode-overlay .nav-btn-library,
.nav-mode-overlay .nav-btn-library-backdrop,
.nav-mode-overlay .nav-btn-undo-toast,
.nav-mode-overlay .nav-btn-context-menu {
    pointer-events: auto;
}

/* ================================================
   iOS Safe Area
   ================================================ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .nav-btn-library {
        padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
    }

    .nav-btn-undo-toast {
        bottom: calc(env(safe-area-inset-bottom) + 80px);
    }
}

/* ================================================
   Nav mode bottom bar clearance — library needs extra
   bottom padding so last buttons aren't hidden behind it.
   Must come AFTER safe-area rule to win specificity.
   ================================================ */
.nav-customizer-edit .nav-btn-library {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
}

/* ================================================
   Reduced Motion
   ================================================ */

@media (prefers-reduced-motion: reduce) {
    .nav-customizer-jiggle {
        animation: none;
    }

    .nav-btn-library,
    .nav-btn-undo-toast,
    .nav-btn-context-menu {
        transition-duration: 0.01s;
    }
}
