/* components/quote-card.css
 * ============================================
 * Quote card component with modern CSS nesting.
 * Uses :has() for parent-state styling and container queries
 * for component-responsive layouts.
 *
 * Browser support: Chrome 112+, Firefox 117+, Safari 16.4+
 * Graceful degradation: Rules still apply in older browsers
 *
 * Last updated: 2026-01-16
 * See: docs/delivery/74-bootstrap-vanilla-css/74-4.md
 */

/* === COLLECTION ICON COLORS === */
:root {
    /* Card outline (existing gold) */
    --qs-collect-card-outline: #D4AF37;

    /* Bookmark fill colors */
    --qs-collect-fill: #654321;           /* Library Brown - collected state */
    --qs-collect-fill-hover: #7B5229;     /* 15% lighter for hover */
    --qs-collect-outline: #6c757d;        /* Neutral gray - uncollected */

    /* Icon size (single source of truth) */
    --qs-collect-icon-size: 1.25rem;      /* 20px at default font size */
}

/* === QUOTE CARD BASE === */
.quote-card {
    background-color: var(--bs-card-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    position: relative;
    margin-bottom: 0.5rem;
    overflow: visible !important;
    z-index: auto !important;
    /* Note: margin/padding transitions removed to prevent CLS on load.
     * The .removing class has its own transitions for exit animation. */
    transition: opacity 0.5s ease-in-out,
                box-shadow 0.3s ease;

    /* Subtle hover effect without transform (prevents stacking issues) */
    &:hover {
        transform: none !important;
        box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
    }

    /* Collected state - gold highlight */
    &.quote-card-collected {
        background-color: rgba(var(--bs-warning-rgb), 0.05);
        border: 2px solid var(--bs-warning);
        box-shadow: 0 0 0 1px var(--bs-warning);
    }

    /* Card body padding */
    & .card-body {
        padding: 1rem;
    }

    /* Horizontal rule */
    & hr {
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
    }

    /* Dropdown positioning */
    & .dropdown-menu {
        z-index: 1055;
    }

    /* Override Bootstrap mb-3 (16px) with 8px spacing.
     * Template uses .quote-card.mb-3 - this counters Bootstrap's !important. */
    &.mb-3 {
        margin-bottom: 0.5rem !important;
    }
}

/* === QUOTE TEXT === */
.quote-text {
    font-style: italic;
    color: var(--bs-secondary);
    font-size: 1.1rem;
    line-height: 1.5;
}

/* === COLLECTION ICON === */
.collect-icon {
    color: var(--qs-collect-outline);
    cursor: pointer;
    transition: color 150ms ease-out, transform 150ms ease-out;
    font-size: var(--qs-collect-icon-size);
    width: var(--qs-collect-icon-size);
    height: var(--qs-collect-icon-size);

    &:hover {
        transform: scale(1.1);
        color: var(--qs-collect-fill-hover);
    }

    &.collected {
        color: var(--qs-collect-fill);

        &:hover {
            transform: scale(1.1);
            color: var(--qs-collect-fill-hover);
        }
    }
}

/* === HTMX ANIMATIONS === */
.quote-card {
    /* Slide-in animation */
    &.htmx-added {
        opacity: 0;
        transform: translateX(10px);
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    &.htmx-added-settle {
        opacity: 1;
        transform: translateX(0);
    }

    /* Swap animation */
    &.htmx-swapping {
        opacity: 0;
        transform: translateX(10px);
        pointer-events: none;
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    /* Removal animation */
    &.removing {
        transform: scaleY(0);
        opacity: 0;
        margin-top: 0;
        margin-bottom: 0;
        padding: 0;
        transition: transform 0.5s ease-in-out,
                    opacity 0.5s ease-in-out,
                    margin 0.5s ease-in-out,
                    padding 0.5s ease-in-out;
    }
}

/* === METADATA === */
.metadata-content {
    font-size: 0.9rem;
}

.quote-metadata {
    overflow: hidden;

    & a {
        word-wrap: break-word;
        word-break: break-word;
    }
}

.quote-originator {
    max-width: 100%;
    display: inline-flex;
    font-size: 0.99rem;

    & a {
        line-height: 1.4;
        display: inline-block;
        max-width: 100%;
    }

    &.mb-2 {
        margin-bottom: 0 !important;
    }
}

.quote-card-source {
    max-width: 100%;
    display: inline-flex;

    & a {
        line-height: 1.4;
        display: inline-block;
        max-width: 100%;
    }
}

.quote-source-container {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
}

/* === TAGS === */
.quote-tags .badge {
    transition: background-color 0.2s ease;

    &:hover {
        background-color: var(--bs-gray-200) !important;
    }
}

.quote-tags-and-language {
    flex: 1 1 0;
    max-width: calc(100% - 360px);
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 0.5rem;
    margin-bottom: 0.125rem;

    & .badge {
        margin-bottom: 0.125rem;
        margin-top: 0.125rem;
        margin-right: 0.25rem;
    }

}

/* === ACTIONS === */
.quote-actions {
    margin-left: auto;
    margin-top: 0.25rem;
    white-space: nowrap;
}

/* Copy button: flex for icon centering, match star icon height */
.copy-quote-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1.5rem;
}

/* Copy dropdown (T021): Format selection dropdown
 * Must align vertically with share button and collection star.
 * Margin via me-3 class in template (desktop only).
 */
.copy-quote-dropdown {
    align-self: center;
}

/* Reset copy-quote-btn fixed height when in dropdown */
.btn-group.copy-quote-dropdown .btn.copy-quote-btn {
    height: auto;
}

/* Tight spacing between clipboard icon and dropdown caret */
.copy-quote-dropdown .copy-quote-btn {
    padding: 0.25rem;
    padding-right: 0.0625rem;  /* 1px gap to caret */
}
.copy-quote-dropdown .dropdown-toggle-split {
    padding: 0.25rem;
    padding-left: 0.0625rem;   /* 1px gap from icon */
    border-left: 0;
}

/* Regular desktop + mobile: hide top-right buttons, show in bottom row
 * Only huge desktops (≥1400px) get split layout with top-right buttons
 */
@media (max-width: 1399.98px) {
    /* Hide top-right collect/copy/share area */
    .quote-card-collect {
        display: none !important;
    }

    /* Mobile action buttons join the bottom quote-actions flex */
    .mobile-action-buttons {
        display: contents !important;
    }

    /* Mobile bounded button style (outline buttons) */
    .mobile-action-btn {
        background: transparent;
        border: 1px solid var(--bs-border-color, #dee2e6);
        border-radius: 6px;
        padding: 6px 10px;
        color: var(--bs-secondary, #6c757d);
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 38px;
        min-height: 38px;
        transition: all 0.15s ease;
    }

    .mobile-action-btn:hover {
        background: var(--bs-light, #f8f9fa);
        border-color: var(--bs-secondary, #6c757d);
    }

    /* Mobile copy dropdown split button */
    .mobile-copy-dropdown {
        display: inline-flex;
    }

    .mobile-copy-dropdown .copy-quote-btn {
        border-radius: 6px 0 0 6px;
        border-right: 0;
    }

    .mobile-copy-dropdown .dropdown-toggle-split {
        border-radius: 0 6px 6px 0;
        padding: 6px 6px;
        min-width: auto;
    }

    /* Copy button hover - primary blue */
    .mobile-action-btn.copy-quote-btn:hover,
    .mobile-copy-dropdown:hover .copy-quote-btn,
    .mobile-copy-dropdown:hover .dropdown-toggle-split {
        border-color: var(--bs-primary, #0d6efd);
        color: var(--bs-primary, #0d6efd);
    }

    /* Share button hover - primary blue */
    .mobile-action-btn.share-quote-btn:hover {
        border-color: var(--bs-primary, #0d6efd);
        color: var(--bs-primary, #0d6efd);
    }

    /* Collect button - library brown */
    .mobile-action-btn.collect-icon {
        color: var(--qs-collect-outline, #6c757d);
    }

    .mobile-action-btn.collect-icon:hover {
        border-color: var(--qs-collect-fill-hover, #7B5229);
        color: var(--qs-collect-fill-hover, #7B5229);
    }

    .mobile-action-btn.collect-icon.collected {
        border-color: var(--qs-collect-fill, #654321);
        color: var(--qs-collect-fill, #654321);
    }

    /* Find Similar - icon only on regular desktop + mobile */
    .quote-actions .similar-quotes-link {
        padding: 6px 10px;
        min-width: 38px;
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .quote-actions .similar-quotes-link .find-similar-text {
        display: none;
    }

    .quote-actions .similar-quotes-link .icon-search-heart {
        margin: 0;
        font-size: 1rem;
    }

    /* Full Quote - icon only, match other button sizes */
    .quote-actions .extended-version-link.btn {
        padding: 6px 10px !important;
        width: 38px !important;
        min-width: 38px !important;
        max-width: 38px !important;
        min-height: 38px;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        box-sizing: border-box !important;
        font-size: 0 !important; /* Collapse whitespace text node */
        margin-right: 0 !important; /* Reset Bootstrap me-1, use gap instead */
    }

    .quote-actions .extended-version-link i {
        margin: 0 !important;
        font-size: 1rem !important; /* Restore icon size */
    }

    .quote-actions .extended-version-link small {
        display: none !important;
    }

    /* quote-actions layout for regular desktop + mobile */
    .quote-actions {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 0.5rem;
    }
}

/* === HUGE DESKTOP (≥1400px) ===
 * Split layout: copy/share/collect in top-right, Find Similar in bottom
 * Styled with outline borders to match mobile aesthetic
 */
@media (min-width: 1400px) {
    /* Show top-right buttons on huge desktops */
    .quote-card-collect {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
    }

    /* Hide mobile action buttons in bottom row */
    .mobile-action-buttons {
        display: none !important;
    }

    /* Style top-right buttons with outline aesthetic */
    .quote-card-collect .copy-quote-dropdown .btn,
    .quote-card-collect .share-quote-btn,
    .quote-card-collect .collect-icon {
        background: transparent;
        border: 1px solid var(--bs-border-color, #dee2e6) !important;
        border-radius: 6px;
        padding: 6px 10px !important;
        min-width: 38px;
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        transition: all 0.15s ease;
        text-decoration: none !important;
    }

    .quote-card-collect .copy-quote-dropdown .btn:hover,
    .quote-card-collect .share-quote-btn:hover {
        background: var(--bs-light, #f8f9fa);
        border-color: var(--bs-primary, #0d6efd);
        color: var(--bs-primary, #0d6efd);
    }

    /* Copy dropdown special handling */
    .quote-card-collect .copy-quote-dropdown {
        display: inline-flex;
    }

    .quote-card-collect .copy-quote-dropdown .copy-quote-btn {
        border-radius: 6px 0 0 6px;
        border-right: 0;
    }

    .quote-card-collect .copy-quote-dropdown .dropdown-toggle-split {
        border-radius: 0 6px 6px 0;
        padding: 6px 6px;
        min-width: auto;
    }

    /* Collect icon hover */
    .quote-card-collect .collect-icon:hover {
        border-color: var(--qs-collect-fill-hover, #7B5229);
    }

    .quote-card-collect .collect-icon.collected {
        border-color: var(--qs-collect-fill, #654321);
    }

    /* Reset Bootstrap margins - use gap instead */
    .quote-card-collect .me-1,
    .quote-card-collect .me-2 {
        margin-right: 0 !important;
    }

    /* Quote detail: show top-right buttons, hide bottom mobile actions */
    .quote-detail-collect {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
    }

    .quote-detail-mobile-actions {
        display: none !important;
    }

    /* Style top-right quote-detail buttons with outline */
    .quote-detail-collect .copy-quote-dropdown .btn,
    .quote-detail-collect .share-quote-btn,
    .quote-detail-collect .collect-icon {
        background: transparent;
        border: 1px solid var(--bs-border-color, #dee2e6) !important;
        border-radius: 6px;
        padding: 6px 10px !important;
        min-width: 38px;
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        transition: all 0.15s ease;
        text-decoration: none !important;
    }

    .quote-detail-collect .copy-quote-dropdown .btn:hover,
    .quote-detail-collect .share-quote-btn:hover {
        background: var(--bs-light, #f8f9fa);
        border-color: var(--bs-primary, #0d6efd);
        color: var(--bs-primary, #0d6efd);
    }

    .quote-detail-collect .copy-quote-dropdown {
        display: inline-flex;
    }

    .quote-detail-collect .copy-quote-dropdown .copy-quote-btn {
        border-radius: 6px 0 0 6px;
        border-right: 0;
    }

    .quote-detail-collect .copy-quote-dropdown .dropdown-toggle-split {
        border-radius: 0 6px 6px 0;
        padding: 6px 6px;
        min-width: auto;
    }

    .quote-detail-collect .collect-icon:hover {
        border-color: var(--qs-collect-fill-hover, #7B5229);
    }

    .quote-detail-collect .collect-icon.collected {
        border-color: var(--qs-collect-fill, #654321);
    }

    /* Reset Bootstrap margins - use gap instead */
    .quote-detail-collect .me-1,
    .quote-detail-collect .me-2 {
        margin-right: 0 !important;
    }

    .quote-detail-collect .collection-container {
        gap: 0.5rem;
    }
}

/* === QUOTE DETAIL PAGE STYLES === */

/* Social share buttons styling (always visible) */
.social-share-btn {
    background: transparent;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--bs-secondary, #6c757d);
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    text-decoration: none;
}

.social-share-btn:hover {
    background: var(--bs-light, #f8f9fa);
    border-color: var(--bs-primary, #0d6efd);
    color: var(--bs-primary, #0d6efd);
}

/* Regular desktop + mobile: hide top-right quote-detail buttons, show bottom mobile actions */
@media (max-width: 1399.98px) {
    .quote-detail-collect {
        display: none !important;
    }

    .quote-detail-mobile-actions {
        display: flex !important;
    }
}

.copy-format-menu {
    min-width: 10rem;
    font-size: 0.875rem;
}

.copy-format-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
}

.copy-format-menu .dropdown-item i {
    width: 1rem;
    text-align: center;
    flex-shrink: 0;
}

/* Loading state */
.htmx-request .collection-star {
    opacity: 0.5;
    pointer-events: none;
}

.find-similar-button {
    &.htmx-request .btn-content {
        display: none;
    }

    &.htmx-request .find-similar-indicator {
        display: inline-block !important;
    }
}

/* === HIGHLIGHT === */
.highlight-match {
    background-color: rgba(var(--bs-warning-rgb), 0.2);
    padding: 0.1em 0.2em;
    border-radius: 0.2em;
}

/* === SEARCH HEART ICON === */
.icon-search-heart {
    font-size: 1.2em;
    line-height: 1;
    vertical-align: middle;
    margin-bottom: 2px;
    display: inline-block;
}

/* === SOURCE ICONS === */
.source-icons {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;

    & .bi {
        transform: translateY(0.2em);
    }
}

.wikiquote-icon {
    width: 16px;
    height: 16px;
    aspect-ratio: 1;
    vertical-align: top;
    opacity: 0.8;
    margin-top: 0.15rem;

    &:hover {
        opacity: 1;
    }
}

/* === REMOVE DIALOG === */
.remove-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1050;
    background: var(--bs-white);
    border-radius: var(--bs-border-radius);
    box-shadow: var(--bs-box-shadow-lg);
    padding: 1rem;
}

/* === ADSENSE === */
.adsbygoogle[data-adsbygoogle-status="done"] + .ad-placeholder {
    display: none;
}

.ad-placeholder {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8f9fa;
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 768px) {
    .quote-tags-and-language {
        max-width: calc(100% - 260px);
    }
}

/* === MOBILE-ONLY STYLES (<576px) ===
 * Smaller fonts/padding for phone screens
 * Button styles inherited from 1399.98px block above
 */
@media (max-width: 576px) {
    .quote-card {
        & .card-body {
            padding: 0.625rem;
        }

        & hr {
            margin-top: 0.375rem;
            margin-bottom: 0.375rem;
        }
    }

    .quote-text {
        font-size: 1rem;
        line-height: 1.4;
    }

    .quote-tags-row {
        display: block !important;
        margin-top: 0.375rem !important;
    }

    .quote-no-tags-row {
        display: block !important;
    }

    .quote-metadata {
        max-width: 100%;
        width: 100%;
        margin-bottom: 0;
        font-size: 0.8rem;
    }

    .quote-originator {
        font-size: 0.88rem;

        &.mb-2 {
            margin-bottom: 0.25rem !important;
        }
    }

    .quote-card-source {
        font-size: 0.8rem;
    }

    .quote-tags-and-language {
        flex: none;
        max-width: 100% !important;
        min-width: 100% !important;
        width: 100% !important;
        margin-bottom: 0;
        display: flex !important;
        flex-wrap: wrap !important;

        & .badge {
            display: inline-block !important;
            width: auto !important;
            margin-bottom: 0.125rem;
            padding: 0.2rem 0.4rem;
            font-size: 0.7rem;
        }
    }

    .quote-actions {
        margin-left: 0 !important;
        margin-top: 0.25rem !important;
        margin-bottom: 0 !important;
        width: 100%;

        & .btn-sm {
            padding: 0.25rem 0.5rem;
            font-size: 0.75rem;

            & small {
                font-size: 0.7rem;
            }
        }
    }

    .quote-admin-actions .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;

        & small {
            font-size: 0.7rem;
        }
    }
}

/* === CONTAINER QUERY EXAMPLE ===
 * Component adapts to container size, not viewport
 * Enable by adding container-type: inline-size to parent
 */
.quote-grid {
    container-type: inline-size;
}

@container (min-width: 400px) {
    .quote-card {
        /* Grid layout when container is wide enough */
        & .card-body {
            display: grid;
            grid-template-columns: 1fr auto;
            gap: 1rem;
        }
    }
}

/* === :has() EXAMPLE ===
 * Hide quote card if text is empty (no JS needed)
 * Gracefully degrades: older browsers just show the card
 */
.quote-card:has(.quote-text:empty) {
    display: none;
}
