/**
 * COA Archive - Styles
 * Responsive design matching WooCommerce aesthetics
 * Version 1.3.0
 */

/* =============================================
   CSS Custom Properties
   ============================================= */
:root {
    --coa-primary-color: #2563eb;
    --coa-primary-hover: #1d4ed8;
    --coa-secondary-color: #64748b;
    --coa-text-color: #1e293b;
    --coa-text-muted: #64748b;
    --coa-text-light: #94a3b8;
    --coa-bg-color: #ffffff;
    --coa-bg-secondary: #f8fafc;
    --coa-bg-hover: #f1f5f9;
    --coa-border-color: #e2e8f0;
    --coa-border-hover: #cbd5e1;
    --coa-success-color: #10b981;
    --coa-error-color: #ef4444;
    --coa-warning-color: #f59e0b;
    --coa-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --coa-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --coa-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --coa-radius-sm: 6px;
    --coa-radius-md: 8px;
    --coa-radius-lg: 12px;
    --coa-transition-fast: 150ms ease;
    --coa-transition-normal: 250ms ease;
}

/* =============================================
   Reset and Base Styles
   ============================================= */
.coa-archive-wrapper,
.coa-archive-wrapper * {
    box-sizing: border-box;
}

.coa-archive-wrapper {
    font-family: inherit;
    color: var(--coa-text-color);
    line-height: 1.6;
}

/* =============================================
   Section Titles
   ============================================= */
.coa-section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--coa-text-color);
    margin: 0;
    padding: 0;
}

/* =============================================
   Latest COA Section - Inline PDF Viewer
   ============================================= */
.coa-latest-section {
    margin-bottom: 2rem;
}

.coa-latest-section .coa-section-title {
    margin-bottom: 1rem;
}

/* Inline PDF Container - Fixed height approach for reliability */
.coa-inline-pdf-container {
    width: 100%;
    min-height: 700px;
    height: 80vh;
    max-height: 1000px;
    margin-bottom: 1rem;
    border: 1px solid var(--coa-border-color);
    border-radius: var(--coa-radius-lg);
    overflow: hidden;
    background: #525659;
}

.coa-inline-pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
}

/* COA Footer (Details + Button) */
.coa-latest-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* COA Details */
.coa-latest-details {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 1rem;
    background: var(--coa-bg-secondary);
    border: 1px solid var(--coa-border-color);
    border-radius: var(--coa-radius-md);
    flex: 1;
}

.coa-detail-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.coa-detail-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--coa-text-color);
}

.coa-detail-value {
    font-size: 0.875rem;
    color: var(--coa-text-muted);
}

/* =============================================
   Native Details/Summary Collapsible Section
   ============================================= */
.coa-search-details {
    border: 1px solid var(--coa-border-color);
    border-radius: var(--coa-radius-lg);
    overflow: hidden;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.coa-search-summary {
    display: block;
    padding: 1rem 1.25rem;
    background: var(--coa-bg-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--coa-text-color);
    user-select: none;
    transition: background var(--coa-transition-fast);
}

.coa-search-summary:hover {
    background: var(--coa-bg-hover);
}

.coa-search-summary:focus {
    outline: 2px solid var(--coa-primary-color);
    outline-offset: -2px;
}

/* Content area */
.coa-search-content {
    padding: 1.25rem;
    border-top: 1px solid var(--coa-border-color);
    background: var(--coa-bg-color);
}

/* Search Title */
.coa-search-title {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--coa-text-color);
    margin: 0 0 1rem 0;
}

/* =============================================
   Search Controls
   ============================================= */
.coa-search-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Search Input */
.coa-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 200px;
}

.coa-search-input {
    width: 100%;
    height: 48px;
    padding: 0 48px 0 16px; /* Normal left padding - no icon */
    font-size: 1rem;
    color: var(--coa-text-color);
    background: var(--coa-bg-color);
    border: 1px solid var(--coa-border-color);
    border-radius: var(--coa-radius-md);
    outline: none;
    transition: border-color var(--coa-transition-fast), box-shadow var(--coa-transition-fast);
}

.coa-search-input:focus {
    border-color: var(--coa-primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.coa-search-input::placeholder {
    color: var(--coa-text-light);
}

.coa-search-clear {
    position: absolute;
    right: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: var(--coa-bg-hover);
    color: var(--coa-text-muted);
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
    transition: all var(--coa-transition-fast);
}

.coa-search-clear:hover {
    background: var(--coa-border-color);
    color: var(--coa-text-color);
}

.coa-search-clear.coa-visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* Search Spinner */
.coa-search-spinner {
    position: absolute;
    right: 14px;
    width: 20px;
    height: 20px;
    border: 2px solid var(--coa-border-color);
    border-top-color: var(--coa-primary-color);
    border-radius: 50%;
    opacity: 0;
    visibility: hidden;
    animation: coa-spin 0.6s linear infinite;
}

.coa-search-spinner.coa-visible {
    opacity: 1;
    visibility: visible;
}

.coa-loading .coa-search-clear {
    opacity: 0 !important;
    visibility: hidden !important;
}

@keyframes coa-spin {
    to { transform: rotate(360deg); }
}

/* =============================================
   Results Container
   ============================================= */
.coa-results-container {
    min-height: 100px;
}

.coa-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Result Card */
.coa-result-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    background: var(--coa-bg-color);
    border: 1px solid var(--coa-border-color);
    border-radius: var(--coa-radius-md);
    transition: all var(--coa-transition-fast);
}

.coa-result-card:hover {
    border-color: var(--coa-border-hover);
    box-shadow: var(--coa-shadow-sm);
}

.coa-card-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 60px;
    background: var(--coa-bg-secondary);
    border-radius: var(--coa-radius-sm);
    color: var(--coa-error-color);
}

.coa-card-content {
    flex: 1;
    min-width: 0;
}

.coa-card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--coa-text-color);
    margin: 0 0 0.375rem 0;
    word-break: break-word;
    line-height: 1.3;
}

.coa-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.coa-card-date {
    font-size: 0.8125rem;
    color: var(--coa-text-muted);
}

.coa-card-lot {
    font-size: 0.8125rem;
    color: var(--coa-text-muted);
}

.coa-card-actions {
    display: flex;
    align-items: center;
}

/* =============================================
   Buttons
   ============================================= */
.coa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    border-radius: var(--coa-radius-md);
    cursor: pointer;
    transition: all var(--coa-transition-fast);
}

.coa-btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    color: var(--coa-text-muted);
    background: var(--coa-bg-color);
    border: 1px solid var(--coa-border-color);
    border-radius: var(--coa-radius-md);
}

.coa-btn-icon:hover {
    color: var(--coa-primary-color);
    border-color: var(--coa-primary-color);
    background: rgba(37, 99, 235, 0.05);
}

/* Fullscreen Button */
.coa-btn-fullscreen {
    color: var(--coa-primary-color);
    background: var(--coa-bg-color);
    border: 1px solid var(--coa-primary-color);
    white-space: nowrap;
}

.coa-btn-fullscreen:hover {
    color: #ffffff;
    background: var(--coa-primary-color);
}

.coa-btn-fullscreen svg {
    flex-shrink: 0;
}

/* Highlight */
.coa-highlight {
    background: #fef3c7;
    color: #92400e;
    padding: 0 2px;
    border-radius: 2px;
}

/* =============================================
   Results Message
   ============================================= */
.coa-results-message {
    display: none;
}

.coa-results-message.coa-visible {
    display: block;
}

.coa-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--coa-text-muted);
}

.coa-message svg {
    color: var(--coa-text-light);
}

.coa-message p {
    margin: 0;
    font-size: 1rem;
}

.coa-error svg {
    color: var(--coa-error-color);
}

/* =============================================
   Fullscreen Modal
   ============================================= */
.coa-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--coa-transition-normal);
}

.coa-modal.coa-modal-open {
    opacity: 1;
    visibility: visible;
}

.coa-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.coa-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 95vw;
    height: 95vh;
    max-width: 1400px;
    background: var(--coa-bg-color);
    border-radius: var(--coa-radius-lg);
    box-shadow: var(--coa-shadow-lg);
    transform: scale(0.95);
    transition: transform var(--coa-transition-normal);
}

.coa-modal.coa-modal-open .coa-modal-content {
    transform: scale(1);
}

.coa-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--coa-border-color);
    flex-shrink: 0;
}

.coa-modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--coa-text-color);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.coa-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--coa-text-muted);
    border-radius: var(--coa-radius-sm);
    cursor: pointer;
    transition: all var(--coa-transition-fast);
}

.coa-modal-close:hover {
    background: var(--coa-bg-hover);
    color: var(--coa-text-color);
}

.coa-modal-body {
    flex: 1;
    overflow: hidden;
    background: #525659;
}

.coa-modal-pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
}

/* Body class when modal is open */
body.coa-modal-body-open {
    overflow: hidden;
}

/* =============================================
   Loading State Animations
   ============================================= */
.coa-loading .coa-results-grid {
    opacity: 0.5;
    pointer-events: none;
}

/* Result card animation */
.coa-result-card {
    animation: coa-fade-in var(--coa-transition-normal) ease backwards;
}

.coa-result-card:nth-child(1) { animation-delay: 0ms; }
.coa-result-card:nth-child(2) { animation-delay: 50ms; }
.coa-result-card:nth-child(3) { animation-delay: 100ms; }
.coa-result-card:nth-child(4) { animation-delay: 150ms; }
.coa-result-card:nth-child(5) { animation-delay: 200ms; }
.coa-result-card:nth-child(6) { animation-delay: 250ms; }

@keyframes coa-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================
   Responsive Design
   ============================================= */

/* Tablet */
@media (max-width: 768px) {
    .coa-inline-pdf-container {
        min-height: 500px;
        height: 70vh;
        max-height: 700px;
    }

    .coa-latest-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .coa-latest-details {
        flex-direction: column;
        gap: 0.75rem;
    }

    .coa-btn-fullscreen {
        justify-content: center;
    }

    .coa-results-grid {
        grid-template-columns: 1fr;
    }

    .coa-search-summary {
        padding: 0.875rem 1rem;
    }

    .coa-search-content {
        padding: 1rem;
    }

    .coa-modal-content {
        width: 100vw;
        height: 100vh;
        max-width: none;
        border-radius: 0;
    }
}

/* Mobile */
@media (max-width: 480px) {
    .coa-section-title {
        font-size: 1.125rem;
    }

    .coa-inline-pdf-container {
        min-height: 400px;
        height: 60vh;
        max-height: 500px;
    }

    .coa-search-controls {
        flex-direction: column;
    }

    .coa-search-input-wrapper {
        min-width: 100%;
    }

    .coa-filter-group {
        width: 100%;
    }

    .coa-search-input {
        height: 44px;
        font-size: 0.9375rem;
    }

    .coa-month-input {
        height: 44px;
        font-size: 0.8125rem;
        width: 100%;
    }

    .coa-result-card {
        padding: 0.875rem;
        gap: 0.75rem;
    }

    .coa-card-icon {
        width: 40px;
        height: 50px;
    }

    .coa-card-icon svg {
        width: 24px;
        height: 24px;
    }

    .coa-card-title {
        font-size: 0.875rem;
    }

    .coa-btn-icon {
        width: 32px;
        height: 32px;
    }

    .coa-btn-icon svg {
        width: 16px;
        height: 16px;
    }

    .coa-modal-header {
        padding: 0.875rem 1rem;
    }

    .coa-modal-title {
        font-size: 1rem;
    }
}

/* =============================================
   WooCommerce Tab Integration
   ============================================= */
.woocommerce-tabs .coa-archive-wrapper {
    padding-top: 0.5rem;
}

/* Ensure tab content doesn't overflow */
.woocommerce-Tabs-panel--coa_archive {
    overflow: visible;
}

/* =============================================
   Print Styles
   ============================================= */
@media print {
    .coa-search-details,
    .coa-card-actions,
    .coa-btn-fullscreen,
    .coa-modal {
        display: none !important;
    }

    .coa-inline-pdf-container {
        height: auto;
        min-height: auto;
        page-break-inside: avoid;
    }

    .coa-result-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* =============================================
   Accessibility
   ============================================= */
.coa-btn:focus,
.coa-search-input:focus,
.coa-month-input:focus,
.coa-modal-close:focus {
    outline: 2px solid var(--coa-primary-color);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .coa-archive-wrapper *,
    .coa-modal * {
        animation: none !important;
        transition: none !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .coa-result-card,
    .coa-inline-pdf-container,
    .coa-search-details,
    .coa-modal-content {
        border-width: 2px;
    }
}

/* =============================================
   [coa_product_latest] Shortcode - Thumbnail
   ============================================= */
.coa-latest-thumbnail {
    display: inline-block;
    width: 150px;
    height: 200px;
    border: 1px solid var(--coa-border-color, #e0e0e0);
    border-radius: 4px;
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    position: relative;
}

.coa-latest-thumbnail:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.coa-latest-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.coa-latest-thumbnail--pdf iframe {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.coa-latest-thumbnail .coa-thumbnail-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
