/* ==========================================================================
   Mobile UX/UI - Artikle
   Bottom sheets, toasts, confirm modals, sticky actions, bottom tab bar,
   swipe indicators, pull-to-refresh, skeleton loading, mobile-aware visibility
   ========================================================================== */

/* ---------- Bottom Sheet & Backdrop ---------- */
.bottom-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0);
    transition: background 0.25s ease;
    pointer-events: none;
}

.bottom-sheet-backdrop.open {
    background: rgba(0, 0, 0, 0.6);
    pointer-events: auto;
}

[data-theme="light"] .bottom-sheet-backdrop.open {
    background: rgba(0, 0, 0, 0.4);
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1101;
    background: var(--color-surface);
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
    overflow-y: auto;
    padding: 0.5rem 1.5rem 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.bottom-sheet.open {
    transform: translateY(0);
    pointer-events: auto;
}

[data-theme="light"] .bottom-sheet {
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    margin: 0.5rem auto 1rem;
}

.bottom-sheet h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.bottom-sheet-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Desktop: bottom sheet becomes centered modal */
@media (min-width: 769px) {
    .bottom-sheet {
        bottom: auto;
        top: 50%;
        left: 50%;
        right: auto;
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0;
        border-radius: var(--radius);
        max-width: 480px;
        width: 90vw;
        padding-bottom: 1.5rem;
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    }

    .bottom-sheet.open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    .bottom-sheet-handle {
        display: none;
    }
}

/* ---------- Toast Notifications ---------- */
.toast-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: calc(4rem + env(safe-area-inset-top, 0px));
    pointer-events: none;
}

.toast {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    max-width: 420px;
    width: calc(100% - 2rem);
    transform: translateY(-120%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    pointer-events: auto;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    border-left: 3px solid var(--color-success);
}

.toast-error {
    border-left: 3px solid var(--color-error);
}

.toast-info {
    border-left: 3px solid var(--color-primary);
}

[data-theme="light"] .toast {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ---------- Confirm Modal ---------- */
.confirm-message {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ---------- Sticky Selection Actions (Mobile) ---------- */
@media (max-width: 768px) {
    #selection-actions {
        position: sticky;
        bottom: 0;
        z-index: 100;
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
        margin: 0 -1rem;
        width: calc(100% + 2rem);
    }

    #selection-actions {
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    }

    [data-theme="light"] #selection-actions {
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    }
}

/* ---------- Sticky Article Header ---------- */
.sticky-article-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    box-shadow: var(--shadow);
    transform: translateY(-100%);
    transition: transform 0.25s ease;
}

.sticky-article-header.visible {
    transform: translateY(0);
}

.sticky-article-header-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    color: var(--color-text);
    text-decoration: none;
    flex-shrink: 0;
}

.sticky-article-header-back:hover {
    text-decoration: none;
    color: var(--color-primary);
}

.sticky-article-header-title {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 0.5rem;
}

.sticky-article-header-overflow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    background: none;
    border: none;
    color: var(--color-text);
    cursor: pointer;
    flex-shrink: 0;
}

.sticky-article-header-overflow:hover {
    color: var(--color-primary);
}

/* Overflow menu items */
.overflow-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 44px;
    padding: 0.75rem 0;
    background: none;
    border: none;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    text-align: left;
}

.overflow-menu-item:last-child {
    border-bottom: none;
}

.overflow-menu-item:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.overflow-menu-item-danger {
    color: var(--color-error);
}

.overflow-menu-item-danger:hover {
    color: var(--color-error);
}

.overflow-menu-item svg {
    flex-shrink: 0;
}

/* Article view overflow button (mobile only) */
.article-view-overflow-btn {
    display: none;
}

.article-view-title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.article-view-title-row h1 {
    flex: 1;
}

/* Show/hide based on viewport */
@media (max-width: 768px) {
    .article-header-actions {
        display: none;
    }

    .article-view-overflow-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        background: none;
        border: none;
        color: var(--color-text-muted);
        cursor: pointer;
        flex-shrink: 0;
    }

    .article-view-overflow-btn:hover {
        color: var(--color-text);
    }

    .article-view-header h1 {
        font-size: 1.35rem;
    }

    .article-content {
        padding-bottom: 1rem;
    }
}

@media (min-width: 769px) {
    .sticky-article-header-overflow {
        display: none;
    }
}

@media (max-width: 768px) {
    .sticky-article-header-actions {
        display: none;
    }
}

/* ---------- Bottom Tab Bar ---------- */
.bottom-tab-bar {
    display: none;
}

@media (max-width: 768px) {
    .bottom-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.2);
        min-height: 56px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        align-items: stretch;
    }

    [data-theme="light"] .bottom-tab-bar {
        box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.06);
    }

    .has-tab-bar {
        padding-top: 0;
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    /* Hide entire navbar on mobile - navigation handled by bottom tab bar */
    .has-tab-bar > .navbar {
        display: none;
    }

    /* Hide footer when bottom tab bar is present */
    .has-tab-bar > .footer {
        display: none;
    }
}

.bottom-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 44px;
    padding: 0.5rem 0;
    color: var(--color-text-muted);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.bottom-tab:hover {
    text-decoration: none;
    color: var(--color-text);
}

.bottom-tab.active {
    color: var(--color-primary);
}

.bottom-tab-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.bottom-tab-add .bottom-tab-icon {
    width: 40px;
    height: 40px;
    background: var(--color-primary);
    border-radius: 50%;
    color: #fff;
}


/* ---------- Swipe Indicators ---------- */
.swipe-indicator {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
    z-index: -1;
}

.swipe-indicator-archive {
    left: 0;
    justify-content: flex-start;
    background: var(--color-success);
    color: #fff;
}

.swipe-indicator-delete {
    right: 0;
    justify-content: flex-end;
    background: var(--color-error);
    color: #fff;
}

@media (max-width: 768px) {
    .article-table tbody tr {
        position: relative;
        overflow: hidden;
    }

    /* Prevent native browser context menu on long-press of article links */
    .article-table tbody tr,
    .article-table tbody tr a {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ---------- Pull-to-Refresh ---------- */
.pull-to-refresh-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    z-index: 300;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    pointer-events: none;
}

.pull-to-refresh-indicator svg {
    width: 24px;
    height: 24px;
    color: var(--color-text-muted);
}

.pull-to-refresh-indicator.refreshing svg {
    animation: ptr-spin 0.6s linear infinite;
}

@keyframes ptr-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    body {
        overscroll-behavior-y: contain;
    }
}

/* ---------- Skeleton Loading ---------- */
@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

.skeleton-row {
    display: flex;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
    gap: 0.75rem;
}

.skeleton-checkbox {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    background: var(--color-border);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}

.skeleton-title {
    height: 14px;
    border-radius: 3px;
    background: var(--color-border);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    flex: 1;
}

.skeleton-meta {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.375rem;
    padding-left: 2rem;
}

.skeleton-meta-item {
    height: 10px;
    width: 80px;
    border-radius: 3px;
    background: var(--color-border);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Stagger animation */
.skeleton-row:nth-child(2) * { animation-delay: 0.15s; }
.skeleton-row:nth-child(3) * { animation-delay: 0.3s; }
.skeleton-row:nth-child(4) * { animation-delay: 0.45s; }
.skeleton-row:nth-child(5) * { animation-delay: 0.6s; }

/* ---------- Mobile-Aware Visibility ---------- */
.empty-state-mobile {
    display: none;
}

.mobile-bookmarklet-notice {
    display: none;
}

.load-more-mobile {
    display: none;
}

@media (max-width: 768px) {
    .empty-state-desktop {
        display: none;
    }

    .empty-state-mobile {
        display: block;
    }

    .desktop-only-bookmarklet {
        display: none;
    }

    .mobile-bookmarklet-notice {
        display: block;
        font-size: 0.85rem;
        color: var(--color-text-muted);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        padding: 0.75rem 1rem;
        margin: 0.5rem 0;
    }

    .pagination {
        display: none;
    }

    .load-more-mobile {
        display: block;
        text-align: center;
        margin-top: 1.5rem;
    }

    .load-more-mobile .btn {
        width: 100%;
        min-height: 44px;
    }
}

@media (min-width: 769px) {
    .empty-state-mobile {
        display: none;
    }

    .mobile-bookmarklet-notice {
        display: none;
    }
}

/* ---------- Mobile Highlight Toolbar ---------- */
@media (max-width: 768px) {
    .highlight-toolbar {
        position: fixed;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 60px);
        left: 0.5rem;
        right: 0.5rem;
        border-radius: 12px;
        justify-content: center;
        box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.15);
    }

    .highlight-toolbar button {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .highlights-list {
        gap: 1rem;
    }

    .highlight-card {
        flex-direction: column;
        gap: 0.25rem;
    }

    .highlight-card-text {
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .highlight-card-date {
        align-self: flex-end;
    }

    /* Onboarding Wizard - Mobile */
    .onboarding-backdrop {
        align-items: flex-end;
    }

    .onboarding-card {
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 2rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
    }
}
