/* ============================================================
   Social Share — Shared CSS
   Styles for SocialShareManager (assets/shared/js/social-share-manager.js)
   Complements assets/css/social-sharing-theme.css (legacy panel styles)
   ============================================================ */

/* ─── CSS Custom Properties (Theme Tokens) ─────────────────── */
/* Maps --share-* aliases to the app's existing theme variables
   (--bg-panel, --text-primary, --accent-color, etc.)
   so the share panel automatically inherits database-injected theme colors. */

:root {
    --share-bg: var(--bg-panel, #ffffff);
    --share-text: var(--text-primary, #333333);
    --share-text-secondary: var(--text-secondary, #666666);
    --share-border: var(--border-color, #e0e0e0);
    --share-btn-bg: var(--hover-bg, #f5f5f5);
    --share-btn-hover: var(--active-bg, #e8e8e8);
    --share-accent: var(--accent-color, #4a90d9);
    --share-accent-hover: var(--accent-hover, #3a7bc8);
    --share-backdrop: rgba(0, 0, 0, 0.5);
    --share-header-bg: var(--bg-ui, #f8f9fa);
    --share-preview-bg: var(--bg-ui, #f8f9fa);
    --share-preview-border: var(--accent-color, #4a90e2);
    --share-notification-bg: var(--text-primary, #333333);
    --share-success: var(--success-color, #4caf50);
    --share-error: var(--error-color, #f44336);
    --share-info: var(--info-color, #333333);
}


/* ─── Backdrop Overlay ─────────────────────────────────────── */

.social-share-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--share-backdrop);
    z-index: 10050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease, visibility 300ms ease;
}

.social-share-backdrop.visible {
    opacity: 1;
    visibility: visible;
}

/* ─── Share Panel (Main Container) ─────────────────────────── */

.social-share-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 450px;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    background: var(--share-bg);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 10051;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 300ms ease;
}

.social-share-panel.visible {
    transform: translateX(0);
}

/* RTL: panel slides from left */
.social-share-panel[dir="rtl"] {
    right: auto;
    left: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(-100%);
}

.social-share-panel[dir="rtl"].visible {
    transform: translateX(0);
}

/* ─── Panel Header ─────────────────────────────────────────── */

.social-share-panel-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--share-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--share-header-bg);
    flex-shrink: 0;
}

.social-share-panel-title {
    margin: 0;
    color: var(--share-accent);
    font-size: 20px;
    font-weight: 600;
}

.social-share-panel-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--share-text-secondary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 200ms ease, color 200ms ease;
    line-height: 1;
}

.social-share-panel-close:hover {
    background: var(--share-btn-hover);
    color: var(--share-text);
}

/* ─── Panel Body ───────────────────────────────────────────── */

.social-share-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ─── Preview Section ──────────────────────────────────────── */

.social-share-preview {
    background: var(--share-preview-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    border-left: 4px solid var(--share-preview-border);
}

.social-share-panel[dir="rtl"] .social-share-preview {
    border-left: none;
    border-right: 4px solid var(--share-preview-border);
}

.social-share-preview-title {
    font-weight: 600;
    color: var(--share-text);
    margin-bottom: 8px;
    font-size: 16px;
    line-height: 1.4;
}

.social-share-preview-description {
    color: var(--share-text-secondary);
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.social-share-preview-url {
    color: var(--share-accent);
    font-size: 12px;
    word-break: break-all;
}


/* ─── Quote Preview Section ────────────────────────────────── */

.social-share-quote-preview {
    margin-bottom: 24px;
}

.social-share-quote-text {
    margin: 0;
    padding: 16px 20px;
    background: var(--share-preview-bg);
    border-left: 4px solid var(--share-accent);
    border-radius: 0 8px 8px 0;
    color: var(--share-text);
    font-style: italic;
    font-size: 15px;
    line-height: 1.6;
}

.social-share-panel[dir="rtl"] .social-share-quote-text {
    border-left: none;
    border-right: 4px solid var(--share-accent);
    border-radius: 8px 0 0 8px;
}

/* ─── Platform Buttons Section ─────────────────────────────── */

.social-share-platforms h4,
.social-share-actions h4 {
    margin: 0 0 16px 0;
    color: var(--share-text);
    font-size: 16px;
    font-weight: 600;
}

.social-share-buttons-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.social-share-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px;
    border: 2px solid var(--share-border);
    border-radius: 12px;
    background: var(--share-btn-bg);
    cursor: pointer;
    transition: border-color 200ms ease, background 200ms ease, transform 200ms ease;
    color: var(--share-text);
    font-size: 14px;
    font-family: inherit;
}

.social-share-btn:hover {
    border-color: var(--share-accent);
    background: var(--share-btn-hover);
    transform: translateY(-2px);
}

.social-share-icon {
    font-size: 18px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.social-share-icon svg {
    width: 20px;
    height: 20px;
    display: block;
}

.social-share-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--share-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Platform-specific icon colors */
.social-share-btn[data-platform="facebook"] .social-share-icon { color: #1877F2; }
.social-share-btn[data-platform="twitter"] .social-share-icon { color: var(--share-text); }
.social-share-btn[data-platform="whatsapp"] .social-share-icon { color: #25D366; }
.social-share-btn[data-platform="telegram"] .social-share-icon { color: #0088cc; }
.social-share-btn[data-platform="linkedin"] .social-share-icon { color: #0A66C2; }
.social-share-btn[data-platform="email"] .social-share-icon { color: var(--share-text-secondary); }

/* ─── Action Buttons Section ───────────────────────────────── */

.social-share-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.social-share-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px;
    border: 2px solid var(--share-border);
    border-radius: 12px;
    background: var(--share-btn-bg);
    cursor: pointer;
    transition: border-color 200ms ease, background 200ms ease, transform 200ms ease;
    color: var(--share-text);
    font-size: 14px;
    font-family: inherit;
}

.social-share-action-btn:hover {
    border-color: var(--share-accent);
    background: var(--share-btn-hover);
    transform: translateY(-2px);
}

.social-share-action-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--share-accent);
}

.social-share-action-icon svg {
    width: 20px;
    height: 20px;
    display: block;
}

.social-share-action-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--share-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ─── Native Share Button ──────────────────────────────────── */

.social-share-native {
    margin-top: 8px;
}

.social-share-native-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    border: 2px solid var(--share-accent);
    border-radius: 12px;
    background: var(--share-accent);
    color: #ffffff;
    cursor: pointer;
    transition: background 200ms ease, border-color 200ms ease;
    font-weight: 600;
    font-size: 15px;
    font-family: inherit;
}

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

.social-share-native-btn svg {
    width: 18px;
    height: 18px;
    stroke: #ffffff;
}

/* ─── Toast Notification ───────────────────────────────────── */

.social-share-notification {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 28px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transition: transform 300ms ease, opacity 300ms ease, visibility 300ms ease;
    z-index: 10060;
    color: #ffffff;
    pointer-events: none;
    white-space: nowrap;
}

.social-share-notification.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.social-share-notification-success {
    background: var(--share-success);
}

.social-share-notification-error {
    background: var(--share-error);
}

.social-share-notification-info {
    background: var(--share-info);
}

/* ─── QR Code Modal ────────────────────────────────────────── */

.social-share-qr-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--share-backdrop);
    z-index: 10055;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease, visibility 300ms ease;
}

.social-share-qr-modal.visible {
    opacity: 1;
    visibility: visible;
}

.social-share-qr-content {
    background: var(--share-bg);
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 300ms ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.social-share-qr-modal.visible .social-share-qr-content {
    transform: scale(1);
}

.social-share-qr-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--share-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--share-header-bg);
}

.social-share-qr-header h3 {
    margin: 0;
    color: var(--share-accent);
    font-size: 18px;
    font-weight: 600;
}

.social-share-qr-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--share-text-secondary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 200ms ease;
    line-height: 1;
}

.social-share-qr-close:hover {
    background: var(--share-btn-hover);
}

.social-share-qr-body {
    padding: 24px;
    text-align: center;
}

.social-share-qr-container {
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
}

.social-share-qr-canvas {
    border: 1px solid var(--share-border);
    border-radius: 8px;
}

.social-share-qr-instruction {
    color: var(--share-text-secondary);
    font-size: 14px;
    margin: 0 0 20px 0;
    line-height: 1.5;
}

.social-share-qr-fallback {
    margin-bottom: 16px;
}

.social-share-qr-url-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--share-border);
    border-radius: 8px;
    background: var(--share-btn-bg);
    color: var(--share-text);
    font-size: 13px;
    font-family: monospace;
    box-sizing: border-box;
}

.social-share-qr-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.social-share-qr-download {
    padding: 10px 24px;
    border: 2px solid var(--share-accent);
    border-radius: 8px;
    background: var(--share-btn-bg);
    color: var(--share-accent);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: background 200ms ease, color 200ms ease;
}

.social-share-qr-download:hover {
    background: var(--share-accent);
    color: #ffffff;
}


/* ─── End-of-Chapter CTA Card ──────────────────────────────── */

.share-chapter-cta {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    margin: 32px 0 16px;
    background: var(--share-preview-bg);
    border: 2px solid var(--share-border);
    border-radius: 14px;
    transition: border-color 200ms ease;
}

.share-chapter-cta:hover {
    border-color: var(--share-accent);
}

.share-cta-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--share-accent);
    border-radius: 10px;
    color: #ffffff;
}

.share-cta-icon svg {
    width: 18px;
    height: 18px;
    stroke: #ffffff;
}

.share-cta-content {
    flex: 1;
    min-width: 0;
}

.share-cta-content h4 {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
    color: var(--share-text);
}

.share-cta-content p {
    margin: 0;
    font-size: 13px;
    color: var(--share-text-secondary);
    line-height: 1.4;
}

.share-cta-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: var(--share-accent);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 200ms ease;
    white-space: nowrap;
}

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

.share-cta-btn svg {
    width: 16px;
    height: 16px;
    stroke: #ffffff;
}

/* ─── Share Quote Button (Text Selection Menu) ─────────────── */

.share-quote-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-family: inherit;
}

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

/* ─── Focus Visible (Keyboard Navigation) ──────────────────── */

.social-share-panel-close:focus-visible,
.social-share-btn:focus-visible,
.social-share-action-btn:focus-visible,
.social-share-native-btn:focus-visible,
.social-share-qr-close:focus-visible,
.social-share-qr-download:focus-visible,
.share-cta-btn:focus-visible,
.share-quote-btn:focus-visible {
    outline: 3px solid var(--share-accent);
    outline-offset: 2px;
}

/* ─── Mobile Responsive (≤ 824px) ──────────────────────────── */

@media (max-width: 824px) {

    /* No persistent floating share button on mobile */
    .floating-share-btn {
        display: none !important;
    }

    /* Full-screen panel on mobile */
    .social-share-panel {
        width: 100%;
    }

    /* Platform grid: 2 columns on mobile */
    .social-share-buttons-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Action grid stays 2 columns */
    .social-share-actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* CTA card: stack vertically on mobile */
    .share-chapter-cta {
        flex-direction: column;
        text-align: center;
        padding: 20px 16px;
    }

    .share-cta-btn {
        width: 100%;
        justify-content: center;
    }

    /* QR modal: slightly wider on mobile */
    .social-share-qr-content {
        width: 95%;
    }
}


/* ─── Loading state for action buttons ─────────────────────── */
.social-share-action-btn.social-share-action-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.social-share-action-btn.social-share-action-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid var(--share-border);
    border-top-color: var(--share-accent);
    border-radius: 50%;
    animation: share-spin 0.6s linear infinite;
}

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

/* ─── Generated image overlay ──────────────────────────────── */
.social-share-image-overlay {
    position: fixed;
    inset: 0;
    z-index: 10100;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.social-share-image-modal {
    background: var(--share-bg);
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    position: relative;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.social-share-image-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    font-size: 24px;
    color: #fff;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 1;
    line-height: 1;
    transition: background 0.2s;
}

[dir="rtl"] .social-share-image-close {
    right: auto;
    left: 8px;
}

.social-share-image-close:hover {
    background: rgba(0, 0, 0, 0.85);
}

.social-share-generated-img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
}

.social-share-image-actions {
    display: flex;
    justify-content: center;
    margin-top: 12px;
}

.social-share-image-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    background: var(--share-accent);
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.social-share-image-download:hover {
    background: var(--share-accent-hover);
}


/* ─── Large generate image button ──────────────────────────── */
.social-share-generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 20px;
    margin-top: 12px;
    background: var(--share-btn-bg);
    color: var(--share-text);
    border: 2px solid var(--share-border);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 200ms ease, background 200ms ease, transform 200ms ease;
}

.social-share-generate-btn .social-share-action-icon {
    color: var(--share-text);
}

.social-share-generate-btn .social-share-action-icon svg {
    stroke: var(--share-text);
}

.social-share-generate-btn:hover {
    border-color: var(--share-accent);
    background: var(--share-btn-hover);
    transform: translateY(-2px);
}

.social-share-generate-btn.social-share-action-loading {
    opacity: 0.7;
    pointer-events: none;
}

.social-share-generate-btn.social-share-action-loading::after {
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
}

/* ─── Share button in image modal ──────────────────────────── */
.social-share-image-share-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    background: var(--share-btn-bg);
    color: var(--share-text);
    border: 1px solid var(--share-border);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.social-share-image-share-btn:hover {
    background: var(--share-btn-hover);
}

.social-share-image-actions {
    gap: 10px;
}
