/*
 * PDF Generator for WooCommerce – Premium Frontend Styles v2.3.0
 *
 * Design philosophy:
 *   1. Inherit from active WooCommerce/theme wherever possible
 *   2. Use CSS custom properties (--pgw-*) for plugin-specific branding
 *   3. Zero !important — styles are scoped under .pgw-* selectors
 *   4. Responsive-first with progressive enhancement
 *   5. Supports prefers-color-scheme for dark mode-aware themes
 */

/* ============================================================
   CSS Custom Properties – injected via wp_add_inline_style()
   Fallbacks provided for safety.
   ============================================================ */
:root {
    --pgw-primary:       #1a56db;
    --pgw-primary-rgb:   26, 86, 219;
    --pgw-secondary:     #f3f4f6;
    --pgw-secondary-rgb: 243, 244, 246;

    /* Derived from primary */
    --pgw-primary-hover:  color-mix(in srgb, var(--pgw-primary) 82%, #000);
    --pgw-primary-light:  rgba(var(--pgw-primary-rgb), 0.08);
    --pgw-primary-ring:   rgba(var(--pgw-primary-rgb), 0.25);

    /* Theme-inherited text & surface — uses inherit / currentColor wherever possible */
    --pgw-text:           inherit;
    --pgw-text-muted:     #6b7280;
    --pgw-text-inverse:   #ffffff;
    --pgw-surface:        transparent;
    --pgw-surface-raised: var(--pgw-secondary);
    --pgw-border:         #e5e7eb;
    --pgw-border-strong:  #d1d5db;

    /* Inherited font stack from theme — never overrides the theme font */
    --pgw-font:           inherit;

    /* Transition presets */
    --pgw-transition:     0.18s ease;

    /* Radius — matches common WooCommerce themes */
    --pgw-radius:         6px;
    --pgw-radius-lg:      10px;
    --pgw-radius-pill:    9999px;

    /* Shadows */
    --pgw-shadow-sm:      0 1px 2px rgba(0, 0, 0, 0.05);
    --pgw-shadow-md:      0 4px 12px rgba(0, 0, 0, 0.08);
    --pgw-shadow-focus:   0 0 0 3px var(--pgw-primary-ring);
}

/* ============================================================
   Dark-mode aware themes: adjust surfaces automatically
   ============================================================ */
@media (prefers-color-scheme: dark) {
    :root {
        --pgw-text-muted:     #9ca3af;
        --pgw-text-inverse:   #111827;
        --pgw-surface-raised: rgba(var(--pgw-secondary-rgb), 0.1);
        --pgw-border:         #374151;
        --pgw-border-strong:  #4b5563;
        --pgw-shadow-sm:      0 1px 2px rgba(0, 0, 0, 0.2);
        --pgw-shadow-md:      0 4px 12px rgba(0, 0, 0, 0.3);
    }
}

/* ============================================================
   Account wrapper – inherits theme fonts & colors
   ============================================================ */
.pgw-account-wrap {
    font-family: var(--pgw-font);
    color: var(--pgw-text);
    line-height: 1.5;
}

.pgw-account-wrap h2 {
    font-size: 1.35em;
    font-weight: 700;
    margin: 0 0 1em;
    color: var(--pgw-text);
    letter-spacing: -0.01em;
}

/* ============================================================
   Download buttons (shared by shortcodes + My Account)
   ============================================================ */
.pgw-dl-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 0.45em 1em;
    border: none;
    border-radius: var(--pgw-radius);
    text-decoration: none;
    font-family: var(--pgw-font);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    transition:
        opacity var(--pgw-transition),
        transform var(--pgw-transition),
        box-shadow var(--pgw-transition);
    box-shadow: var(--pgw-shadow-sm);
}

.pgw-dl-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    box-shadow: var(--pgw-shadow-md);
    text-decoration: none;
}

.pgw-dl-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.pgw-dl-btn:focus-visible {
    outline: none;
    box-shadow: var(--pgw-shadow-focus);
}

/* Color variants — use CSS custom property with hardcoded fallback per type */
.pgw-dl-inv {
    background: var(--pgw-primary);
    color: var(--pgw-text-inverse);
}

.pgw-dl-quo {
    background: #059669;
    color: var(--pgw-text-inverse);
}

.pgw-dl-rep {
    background: #d97706;
    color: var(--pgw-text-inverse);
}

/* Visited / link color reset (theme may apply :visited styles) */
.pgw-dl-btn,
.pgw-dl-btn:visited,
.pgw-dl-btn:link {
    color: var(--pgw-text-inverse);
}

/* Loading state (toggled via JS) */
.pgw-dl-btn.pgw-loading {
    opacity: 0.65;
    pointer-events: none;
    cursor: wait;
}

/* ============================================================
   Doc list shortcode wrapper
   ============================================================ */
.pgw-doc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    margin: 0.625em 0;
}

/* ============================================================
   My Account: PDF Documents table
   ============================================================ */
.pgw-account-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
    border: 1px solid var(--pgw-border);
    border-radius: var(--pgw-radius-lg);
    overflow: hidden;
    background: var(--pgw-surface);
}

.pgw-account-table thead th {
    background: var(--pgw-primary);
    color: var(--pgw-text-inverse);
    padding: 0.75em 0.9em;
    text-align: left;
    font-family: var(--pgw-font);
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: none;
    white-space: nowrap;
}

.pgw-account-table tbody tr {
    border-bottom: 1px solid var(--pgw-border);
    transition: background var(--pgw-transition);
}

.pgw-account-table tbody tr:hover {
    background: var(--pgw-primary-light);
}

.pgw-account-table tbody tr:last-child {
    border-bottom: none;
}

.pgw-account-table td {
    padding: 0.7em 0.9em;
    vertical-align: middle;
    color: var(--pgw-text);
    border-bottom: 1px solid var(--pgw-border);
}

.pgw-account-table tbody tr:last-child td {
    border-bottom: none;
}

.pgw-account-table td a:not(.pgw-dl-btn) {
    color: var(--pgw-primary);
    text-decoration: none;
    font-weight: 600;
    transition: color var(--pgw-transition);
}

.pgw-account-table td a:not(.pgw-dl-btn):hover {
    text-decoration: underline;
    color: var(--pgw-primary-hover);
}

/* ============================================================
   Status badges — inherit radius from plugin tokens
   ============================================================ */
.pgw-status {
    display: inline-block;
    padding: 0.2em 0.65em;
    border-radius: var(--pgw-radius-pill);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1.5;
    white-space: nowrap;
}

.pgw-status-completed  { background: #d1fae5; color: #065f46; }
.pgw-status-processing { background: #dbeafe; color: #1e40af; }
.pgw-status-pending    { background: #fef3c7; color: #92400e; }
.pgw-status-cancelled  { background: #fee2e2; color: #991b1b; }
.pgw-status-refunded   { background: var(--pgw-surface-raised); color: var(--pgw-text-muted); }
.pgw-status-on-hold    { background: #ede9fe; color: #5b21b6; }
.pgw-status-default    { background: var(--pgw-surface-raised); color: var(--pgw-text-muted); }

/* ============================================================
   "No doc" placeholder
   ============================================================ */
.pgw-no-doc {
    color: var(--pgw-text-muted);
    font-size: 0.75rem;
    font-style: italic;
    opacity: 0.6;
}

/* ============================================================
   Docs cell
   ============================================================ */
.pgw-docs-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3em;
}

/* ============================================================
   Empty state
   ============================================================ */
.pgw-empty {
    text-align: center;
    padding: 3em 1.5em;
    color: var(--pgw-text-muted);
}

.pgw-empty-icon {
    font-size: 3em;
    line-height: 1;
    margin-bottom: 0.4em;
    opacity: 0.5;
}

.pgw-empty p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ============================================================
   Pagination
   ============================================================ */
.pgw-pagination {
    display: flex;
    gap: 0.3em;
    justify-content: center;
    margin-top: 1.25em;
    flex-wrap: wrap;
}

.pgw-pagination a,
.pgw-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1em;
    padding: 0.35em 0.7em;
    border: 1px solid var(--pgw-border);
    border-radius: var(--pgw-radius);
    font-family: var(--pgw-font);
    font-size: 0.8125rem;
    text-decoration: none;
    color: var(--pgw-text);
    transition:
        background var(--pgw-transition),
        border-color var(--pgw-transition),
        color var(--pgw-transition);
}

.pgw-pagination a:hover {
    background: var(--pgw-primary-light);
    border-color: var(--pgw-primary);
    color: var(--pgw-primary);
}

.pgw-pagination a:focus-visible {
    outline: none;
    box-shadow: var(--pgw-shadow-focus);
}

.pgw-pagination .current {
    background: var(--pgw-primary);
    border-color: var(--pgw-primary);
    color: var(--pgw-text-inverse);
    font-weight: 600;
}

/* ============================================================
   Stats cards (if shown on frontend)
   ============================================================ */
.pgw-account-stats {
    display: flex;
    gap: 0.75em;
    margin-bottom: 1.5em;
    flex-wrap: wrap;
}

.pgw-stat-card {
    background: var(--pgw-surface-raised);
    border-radius: var(--pgw-radius-lg);
    padding: 0.9em 1.25em;
    min-width: 8.75em;
    text-align: center;
    border: 1px solid var(--pgw-border);
    transition: box-shadow var(--pgw-transition);
}

.pgw-stat-card:hover {
    box-shadow: var(--pgw-shadow-sm);
}

.pgw-stat-number {
    font-size: 1.75em;
    font-weight: 700;
    color: var(--pgw-primary);
    line-height: 1;
}

.pgw-stat-label {
    font-size: 0.75rem;
    color: var(--pgw-text-muted);
    margin-top: 0.25em;
}

/* ============================================================
   Toast notification
   ============================================================ */
.pgw-toast {
    position: fixed;
    bottom: 1.5em;
    right: 1.5em;
    z-index: 99999;
    padding: 0.875em 1.25em;
    border-radius: var(--pgw-radius-lg);
    font-family: var(--pgw-font);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--pgw-text-inverse);
    max-width: 20em;
    box-shadow: var(--pgw-shadow-md);
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.pgw-toast--success { background: #059669; }
.pgw-toast--error   { background: #dc2626; }
.pgw-toast--fade    { opacity: 0; }

/* ============================================================
   Print: hide interactive elements, show clean table
   ============================================================ */
@media print {
    .pgw-dl-btn,
    .pgw-pagination,
    .pgw-toast { display: none; }

    .pgw-account-table {
        border: 1px solid #ccc;
        font-size: 11pt;
    }

    .pgw-account-table thead th {
        background: #333;
        color: #fff;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .pgw-status {
        border: 1px solid currentColor;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ============================================================
   Responsive — card layout on small screens
   ============================================================ */
@media (max-width: 640px) {
    .pgw-account-table thead {
        display: none;
    }

    .pgw-account-table,
    .pgw-account-table tbody {
        display: block;
    }

    .pgw-account-table tbody tr {
        display: block;
        margin-bottom: 0.875em;
        border: 1px solid var(--pgw-border);
        border-radius: var(--pgw-radius-lg);
        overflow: hidden;
        background: var(--pgw-surface);
    }

    .pgw-account-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5em 0.75em;
        border-bottom: 1px solid var(--pgw-border);
    }

    .pgw-account-table tbody tr td:last-child {
        border-bottom: none;
    }

    .pgw-account-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.6875rem;
        color: var(--pgw-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.03em;
        margin-right: 0.5em;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .pgw-docs-cell {
        justify-content: flex-end;
    }

    .pgw-dl-btn {
        font-size: 0.75rem;
        padding: 0.4em 0.75em;
    }

    .pgw-account-stats {
        justify-content: center;
    }

    .pgw-stat-card {
        flex: 1;
        min-width: 6.25em;
    }
}

/* ============================================================
   Accessibility: reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .pgw-dl-btn,
    .pgw-account-table tbody tr,
    .pgw-pagination a,
    .pgw-stat-card,
    .pgw-toast {
        transition: none;
    }

    .pgw-dl-btn:hover {
        transform: none;
    }
}
