/**
 * Share Modal - PC Builder
 *
 * Bottom sheet on mobile (< 640px), centered modal on desktop.
 * Uses CSS variables from theme-vars.css exclusively.
 *
 * Sections:
 *   1. Box Sizing Reset
 *   2. Overlay & Backdrop
 *   3. Content Panel (mobile-first: bottom sheet)
 *   4. Header
 *   5. Loading State
 *   6. Sections & Labels
 *   7. Share Link Row (URL + Copy + Native Share)
 *   8. Social Share Buttons
 *   9. Export Toggle & Panel
 *  10. Format Pills
 *  11. Preview Textarea & Export Copy
 *  12. Legacy: Buy Button & Toolbar
 *  13. Animations
 *  14. Reduced Motion
 *  15. Desktop (640px+) -- Centered Modal
 */


/* ============================================================
   1. Box Sizing Reset
   ============================================================ */

.share-modal *,
.share-modal *::before,
.share-modal *::after {
    box-sizing: border-box;
}


/* ============================================================
   2. Overlay & Backdrop
   ============================================================ */

.share-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.share-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
}


/* ============================================================
   3. Content Panel (mobile-first: bottom sheet)
   ============================================================ */

.share-modal__content {
    position: relative;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    padding: 0 20px 32px;
    box-shadow:
        0 -4px 24px rgba(0, 0, 0, 0.25),
        0 -12px 48px rgba(0, 0, 0, 0.15);
    animation: share-modal-slide-up 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Drag handle -- mobile (tappable to close) */
.share-modal__drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px 0 14px;
    margin: 0 0 4px;
    background: none;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.share-modal__drag-pill {
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-light);
    border-radius: 9999px;
    opacity: 0.7;
    transition: opacity 150ms ease, width 150ms ease;
}

.share-modal__drag-handle:hover .share-modal__drag-pill,
.share-modal__drag-handle:active .share-modal__drag-pill {
    opacity: 1;
    width: 52px;
}


/* ============================================================
   4. Header
   ============================================================ */

.share-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.share-modal__header-text {
    min-width: 0;
    flex: 1;
}

.share-modal__title {
    font-size: clamp(1.125rem, 2vw + 0.5rem, 1.375rem);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.share-modal__subtitle {
    margin: 6px 0 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* Close button */
.share-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
    flex-shrink: 0;
}

.share-modal__close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.share-modal__close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-modal__close svg {
    width: 16px;
    height: 16px;
}


/* ============================================================
   5. Loading State
   ============================================================ */

.share-modal__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 48px 20px;
}

.share-modal__loading-icon {
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: share-spinner 0.7s linear infinite;
}

.share-modal__loading-icon--small {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.share-modal__loading-text {
    font-size: 0.875rem;
    color: var(--text-muted);
}


/* ============================================================
   6. Sections & Labels
   ============================================================ */

.share-modal__section {
    margin-bottom: 24px;
}

.share-modal__section:last-child {
    margin-bottom: 0;
}

.share-modal__section--export {
    border-top: 1px solid var(--border);
    padding-top: 20px;
    margin-top: 4px;
    margin-bottom: 0;
}

.share-modal__label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.share-modal__label--inline {
    display: inline;
    margin-bottom: 0;
    font-size: 0.8125rem;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
    color: var(--text-secondary);
}


/* ============================================================
   7. Share Link Row (URL + Copy + Native Share)
   ============================================================ */

.share-modal__link-row {
    display: flex;
    gap: 8px;
}

.share-modal__link-input {
    flex: 1;
    min-width: 0;
    height: 48px;
    padding: 0 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 150ms ease;
}

.share-modal__link-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

/* Copy button */
.share-modal__copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 48px;
    height: 48px;
    padding: 0 16px;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 150ms ease, transform 100ms ease;
    flex-shrink: 0;
    background: var(--accent);
    color: #fff;
}

.share-modal__copy-btn:hover {
    background: var(--accent-hover);
}

.share-modal__copy-btn:active {
    transform: scale(0.97);
}

.share-modal__copy-btn--success {
    background: var(--success);
}

.share-modal__copy-btn--success:hover {
    background: var(--success);
}

.share-modal__copy-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-modal__copy-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.share-modal__copy-label {
    display: none;
}

/* Native share button -- visible on mobile, hidden on desktop */
.share-modal__native-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
    flex-shrink: 0;
}

.share-modal__native-btn:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
    background: var(--bg-hover);
}

.share-modal__native-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-modal__native-btn svg {
    width: 18px;
    height: 18px;
}


/* ============================================================
   8. Social Share Buttons
   ============================================================ */

.share-modal__social-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.share-modal__social-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 68px;
    padding: 14px 8px 12px;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: filter 150ms ease, transform 150ms ease;
    text-decoration: none;
    font-family: inherit;
    line-height: 1;
}

.share-modal__social-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.share-modal__social-btn:active {
    filter: brightness(0.95);
    transform: translateY(0);
}

.share-modal__social-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-modal__social-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.share-modal__social-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* WhatsApp */
.share-modal__social-btn--whatsapp {
    background: #25D366;
    color: #fff;
}

/* Twitter/X -- adapts to theme */
.share-modal__social-btn--twitter {
    background: var(--text-primary);
    color: var(--bg-primary);
}

/* Reddit */
.share-modal__social-btn--reddit {
    background: #FF4500;
    color: #fff;
}

/* Email */
.share-modal__social-btn--email {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}


/* ============================================================
   9. Export Toggle & Panel
   ============================================================ */

.share-modal__export-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.share-modal__export-toggle:hover {
    color: var(--text-primary);
    border-color: var(--border-light);
    background: var(--bg-hover);
}

.share-modal__export-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.share-modal__chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 200ms ease;
    opacity: 0.6;
}

.share-modal__chevron--open {
    transform: rotate(180deg);
}

.share-modal__export-panel {
    padding-top: 16px;
}


/* ============================================================
   10. Format Pills
   ============================================================ */

.share-modal__formats {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
    margin-bottom: 14px;
}

.share-modal__formats::-webkit-scrollbar {
    display: none;
}

.share-modal__format-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    min-height: 36px;
    border-radius: 9999px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
    flex-shrink: 0;
}

.share-modal__format-btn:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
    background: var(--bg-hover);
}

.share-modal__format-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-modal__format-btn--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.share-modal__format-btn--active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}


/* ============================================================
   11. Preview Textarea & Export Copy
   ============================================================ */

.share-modal__preview-wrap {
    min-height: 60px;
}

.share-modal__export-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.share-modal__preview {
    width: 100%;
    height: 130px;
    padding: 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 0.8125rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 150ms ease;
}

.share-modal__preview:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.share-modal__export-copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
    padding: 10px 18px;
    min-height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.share-modal__export-copy-btn:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
    background: var(--bg-hover);
}

.share-modal__export-copy-btn--success {
    border-color: var(--success);
    color: var(--success);
}

.share-modal__export-copy-btn--success:hover {
    border-color: var(--success);
    color: var(--success);
}

.share-modal__export-copy-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.share-modal__export-copy-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}


/* ============================================================
   12. Legacy: Buy Button & Toolbar (used by other templates)
   ============================================================ */

.share-modal__buy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--accent);
    background: transparent;
    border: 1px solid var(--accent);
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 150ms ease;
}

.share-modal__buy-btn:hover {
    background: var(--accent-light);
}

.share-modal__buy-btn svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.share-toolbar__btn--primary {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

.share-toolbar__btn--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}


/* ============================================================
   13. Animations
   ============================================================ */

@keyframes share-modal-slide-up {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes share-modal-fade-scale {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes share-spinner {
    to {
        transform: rotate(360deg);
    }
}


/* ============================================================
   14. Reduced Motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .share-modal__content {
        animation: none;
    }

    .share-modal__loading-icon {
        animation-duration: 1.5s;
    }

    .share-modal__social-btn:hover {
        filter: none;
        transform: none;
    }

    .share-modal__chevron {
        transition: none;
    }

    .share-modal__copy-btn:active {
        transform: none;
    }
}


/* ============================================================
   15. Desktop (640px+) -- Centered Modal
   ============================================================ */

@media (min-width: 640px) {

    /* Overlay: centered with safe padding */
    .share-modal {
        align-items: center;
        padding: 24px;
    }

    /* Content panel: card-style centered modal */
    .share-modal__content {
        max-width: 520px;
        border-radius: 16px;
        border-bottom: 1px solid var(--border);
        padding: 28px 32px 32px;
        box-shadow:
            0 0 0 1px rgba(0, 0, 0, 0.05),
            0 8px 24px rgba(0, 0, 0, 0.15),
            0 24px 64px -16px rgba(0, 0, 0, 0.3);
        animation: share-modal-fade-scale 0.2s cubic-bezier(0.32, 0.72, 0, 1);
    }

    /* Hide drag handle on desktop */
    .share-modal__drag-handle {
        display: none;
    }

    /* Close button: slightly larger on desktop */
    .share-modal__close {
        width: 40px;
        height: 40px;
    }

    .share-modal__close svg {
        width: 18px;
        height: 18px;
    }

    /* Show copy label text on desktop */
    .share-modal__copy-label {
        display: inline;
    }

    /* Hide native share on desktop (no Web Share API context) */
    .share-modal__native-btn {
        display: none;
    }

    /* Social buttons: larger, more spacious */
    .share-modal__social-row {
        gap: 12px;
    }

    .share-modal__social-btn {
        min-height: 80px;
        padding: 16px 8px 14px;
        border-radius: var(--radius-lg);
    }

    .share-modal__social-btn svg {
        width: 26px;
        height: 26px;
    }

    .share-modal__social-label {
        font-size: 0.75rem;
    }

    /* Export toggle: slightly more padding */
    .share-modal__export-toggle {
        padding: 14px 18px;
    }
}
