/**
 * Product Documents Manager - Frontend Styles
 *
 * @package Product_Documents_Manager
 */

/* ==========================================================================
   Variables and Reset
   ========================================================================== */

:root {
    --pdm-primary: #C71F2A;
    --pdm-primary-hover: #A01820;
    --pdm-secondary: #6c757d;
    --pdm-secondary-hover: #5a6268;
    --pdm-border: #dcdcde;
    --pdm-bg: #fff;
    --pdm-bg-alt: #f6f7f7;
    --pdm-text: #1d2327;
    --pdm-text-light: #50575e;
    --pdm-focus: #C71F2A;
    --pdm-success: #00a32a;
    --pdm-error: #d63638;
    --pdm-spacing: 16px;
    --pdm-radius: 4px;
}

.pdm-filters,
.pdm-table-wrapper,
.pdm-table {
    box-sizing: border-box;
}

.pdm-filters *,
.pdm-table-wrapper *,
.pdm-table * {
    box-sizing: inherit;
}

/* Screen reader text */
.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    width: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    word-wrap: normal !important;
}

/* ==========================================================================
   Filters Section
   ========================================================================== */

.pdm-filters {
    background: var(--pdm-bg);
    border: 1px solid var(--pdm-border);
    border-radius: var(--pdm-radius);
    padding: calc(var(--pdm-spacing) * 1.5);
    margin-bottom: calc(var(--pdm-spacing) * 1.5);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.3s ease;
}

.pdm-filters:focus-within {
    box-shadow: 0 2px 8px rgba(34, 113, 177, 0.08);
}

.pdm-filters-row {
    display: flex;
    flex-direction: column;
    gap: calc(var(--pdm-spacing) * 0.875);
}

/* Row 1: Search + Category */
.pdm-filter-row-primary {
    display: grid;
    grid-template-columns: 1fr 30%;
    gap: var(--pdm-spacing);
    align-items: end;
}

/* Category filter specific sizing */
.pdm-filter-category {
    min-width: 0;
}

/* Row 2: Filter Buttons */
.pdm-filter-row-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--pdm-spacing) * 1.5);
    padding-top: 4px;
}

/* Row 3: Date Range + Clear Button */
.pdm-filter-row-tertiary {
    display: flex;
    gap: var(--pdm-spacing);
    align-items: end;
    background: linear-gradient(to bottom, var(--pdm-bg-alt), var(--pdm-bg));
    border: 1px solid rgba(220, 220, 222, 0.5);
    border-radius: calc(var(--pdm-radius) + 2px);
    padding: calc(var(--pdm-spacing) * 0.875);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.pdm-filter-row-tertiary:hover {
    border-color: var(--pdm-border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

/* Clear button only variant */
.pdm-filter-row-clear-only {
    background: transparent;
    border: none;
    padding: 0;
    justify-content: flex-end;
}

.pdm-filter-row-clear-only:hover {
    box-shadow: none;
}

.pdm-filter-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.pdm-filter-item label {
    font-weight: 600;
    font-size: 13px;
    color: var(--pdm-text);
    margin: 0;
    transition: color 0.2s ease;
    letter-spacing: -0.01em;
}

.pdm-filter-item:focus-within label {
    color: var(--pdm-primary);
}

/* Search field gets special treatment */
.pdm-filter-search {
    flex: 1;
    min-width: 0;
}

.pdm-search-input {
    width: 100%;
    padding: 10px 14px;
    padding-left: 38px;
    border: 1.5px solid var(--pdm-border);
    border-radius: calc(var(--pdm-radius) + 2px);
    font-size: 14px;
    line-height: 1.5;
    color: var(--pdm-text);
    background-color: var(--pdm-bg);
    background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"%3E%3Cpath d="M7.333 12.667A5.333 5.333 0 1 0 7.333 2a5.333 5.333 0 0 0 0 10.667ZM14 14l-2.9-2.9" stroke="%2350575e" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 16px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.pdm-search-input:hover {
    border-color: rgba(34, 113, 177, 0.3);
}

.pdm-search-input:focus {
    outline: none;
    border-color: var(--pdm-focus);
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
    background-color: #fff;
    transform: translateY(-1px);
}

.pdm-search-input::placeholder {
    color: var(--pdm-text-light);
    opacity: 0.65;
}

.pdm-filter-select,
.pdm-date-input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--pdm-border);
    border-radius: var(--pdm-radius);
    font-size: 14px;
    line-height: 1.5;
    color: var(--pdm-text);
    background-color: var(--pdm-bg);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    cursor: pointer;
}

.pdm-filter-select:hover,
.pdm-date-input:hover {
    border-color: rgba(34, 113, 177, 0.3);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.pdm-filter-select:focus,
.pdm-date-input:focus {
    outline: none;
    border-color: var(--pdm-focus);
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

/* Date inputs in the tertiary row */
.pdm-filter-row-tertiary .pdm-filter-item {
    flex: 1;
}

.pdm-filter-row-tertiary .pdm-date-input {
    background-color: var(--pdm-bg);
    border-color: rgba(220, 220, 222, 0.8);
}

.pdm-filter-row-tertiary .pdm-date-input:hover {
    background-color: #fff;
}

/* Clear button styling */
.pdm-filter-actions {
    display: flex;
    align-items: flex-end;
}

.pdm-filter-actions-inline {
    margin-left: auto;
}

.pdm-filter-actions .pdm-button-secondary {
    height: 42px;
    padding-left: 18px;
    padding-right: 18px;
    font-weight: 500;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.pdm-filter-actions .pdm-button-secondary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Premium Filter Buttons
   ========================================================================== */

.pdm-filter-button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.pdm-filter-group-label {
    font-weight: 600;
    font-size: 13px;
    color: var(--pdm-text);
    letter-spacing: -0.01em;
    line-height: 1.4;
}

.pdm-filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Premium Filter Button Base Styles */
.pdm-filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: 1.5px solid var(--pdm-border);
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--pdm-text);
    background: var(--pdm-bg);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    user-select: none;
    position: relative;
}

/* Hover state - subtle lift */
.pdm-filter-btn:hover:not(.pdm-filter-btn-active) {
    border-color: rgba(199, 31, 42, 0.35);
    background: #fafbfc;
    transform: translateY(0);
    box-shadow: none;
}

/* Active/Pressed state - premium highlight */
.pdm-filter-btn-active,
.pdm-filter-btn[aria-pressed="true"] {
    border-color: var(--pdm-primary);
    background: var(--pdm-primary);
    color: #fff;
    box-shadow: none;
    transform: translateY(0);
}

.pdm-filter-btn-active:hover,
.pdm-filter-btn[aria-pressed="true"]:hover {
    background: var(--pdm-primary-hover);
    border-color: var(--pdm-primary-hover);
    box-shadow: none;
    transform: translateY(0);
}

/* Focus state - accessible and beautiful */
.pdm-filter-btn:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: 2px;
    box-shadow: none;
}

.pdm-filter-btn-active:focus,
.pdm-filter-btn[aria-pressed="true"]:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: 2px;
    box-shadow: none;
}

/* Active state pressed animation */
.pdm-filter-btn:active {
    transform: translateY(0);
}

/* Filter button icon styling */
.pdm-filter-icon {
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.pdm-filter-btn-active .pdm-filter-icon,
.pdm-filter-btn:hover .pdm-filter-icon {
    transform: scale(1.08);
}

/* Disabled state */
.pdm-filter-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.pdm-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--pdm-radius);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.pdm-button:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: 2px;
}

.pdm-button-primary {
    background: var(--pdm-primary);
    border-color: var(--pdm-primary);
    color: #fff;
}

.pdm-button-primary:hover:not(:disabled) {
    background: var(--pdm-primary-hover);
    border-color: var(--pdm-primary-hover);
    color: #fff;
}

.pdm-button-secondary {
    background: var(--pdm-bg);
    border-color: var(--pdm-border);
    color: var(--pdm-text);
}

.pdm-button-secondary:hover:not(:disabled) {
    background: var(--pdm-bg-alt);
    border-color: var(--pdm-secondary);
}

.pdm-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   Table Wrapper
   ========================================================================== */

.pdm-table-wrapper {
    background: var(--pdm-bg);
    border: 1px solid var(--pdm-border);
    border-radius: var(--pdm-radius);
    overflow: hidden;
}

.pdm-bulk-actions {
    padding: var(--pdm-spacing);
    border-bottom: 1px solid var(--pdm-border);
    background: var(--pdm-bg-alt);
}

.pdm-selected-count {
    font-weight: 600;
    margin-left: 4px;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.pdm-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: calc(var(--pdm-spacing) * 2);
    color: var(--pdm-text-light);
}

.pdm-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--pdm-border);
    border-top-color: var(--pdm-primary);
    border-radius: 50%;
    animation: pdm-spin 0.8s linear infinite;
}

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

/* ==========================================================================
   Table Container
   ========================================================================== */

.pdm-table-container {
    overflow-x: auto;
    position: relative;
}

.pdm-table-container:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: -2px;
}

/* ==========================================================================
   Table
   ========================================================================== */

.pdm-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 14px;
}

.pdm-table thead {
    position: sticky;
    top: 0;
    background: var(--pdm-bg-alt);
    z-index: 10;
}

.pdm-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--pdm-text);
    border-bottom: 2px solid var(--pdm-border);
    white-space: nowrap;
}

.pdm-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--pdm-border);
    color: var(--pdm-text);
}

.pdm-table tbody tr {
    transition: background-color 0.15s ease;
}

.pdm-table tbody tr:hover {
    background-color: var(--pdm-bg-alt);
}

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

/* Column widths */
.pdm-col-checkbox {
    width: 40px;
    text-align: center;
}

.pdm-col-product {
    min-width: 200px;
}

.pdm-col-doc-type {
    width: 140px;
}

.pdm-col-language {
    width: 100px;
}

.pdm-col-size {
    width: 100px;
    text-align: right;
}

.pdm-col-download {
    width: 80px;
    text-align: center;
}

/* ==========================================================================
   Table Sorting
   ========================================================================== */

.pdm-sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 32px !important;
    transition: all 0.2s ease;
}

.pdm-sortable:hover {
    background-color: rgba(34, 113, 177, 0.05);
    color: var(--pdm-primary);
}

.pdm-sortable:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: -2px;
}

.pdm-sort-label {
    display: inline-block;
}

.pdm-sort-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

.pdm-sortable:hover .pdm-sort-icon {
    opacity: 0.6;
}

/* Sort icon - default state (both arrows) */
.pdm-sort-icon::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 5px solid currentColor;
    position: absolute;
    top: 2px;
}

.pdm-sort-icon::after {
    content: '';
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    position: absolute;
    bottom: 2px;
}

/* Active sorting - ascending */
.pdm-sorted-asc .pdm-sort-icon {
    opacity: 1;
    color: var(--pdm-primary);
}

.pdm-sorted-asc .pdm-sort-icon::after {
    opacity: 0.3;
}

.pdm-sorted-asc .pdm-sort-icon::before {
    border-bottom-color: var(--pdm-primary);
}

/* Active sorting - descending */
.pdm-sorted-desc .pdm-sort-icon {
    opacity: 1;
    color: var(--pdm-primary);
}

.pdm-sorted-desc .pdm-sort-icon::before {
    opacity: 0.3;
}

.pdm-sorted-desc .pdm-sort-icon::after {
    border-top-color: var(--pdm-primary);
}

/* Active sorted column background */
.pdm-sorted-asc,
.pdm-sorted-desc {
    background-color: rgba(34, 113, 177, 0.04);
}

/* ==========================================================================
   Table Elements
   ========================================================================== */

/* Checkboxes */
.pdm-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
}

.pdm-table input[type="checkbox"]:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: 2px;
}

/* Product links */
.pdm-table a {
    color: var(--pdm-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.pdm-table a:hover {
    color: var(--pdm-primary-hover);
    text-decoration: underline;
}

.pdm-table a:focus {
    outline: 2px solid var(--pdm-focus);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Download link */
.pdm-download-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--pdm-radius);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.pdm-download-link:hover {
    background-color: var(--pdm-bg-alt);
    text-decoration: none;
}

.pdm-download-link .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.pdm-empty-state {
    padding: calc(var(--pdm-spacing) * 3);
    text-align: center;
    color: var(--pdm-text-light);
}

.pdm-empty-state p {
    margin: 0;
    font-size: 16px;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Tablet: Adjust layout */
@media screen and (max-width: 1024px) {
    .pdm-filter-row-primary {
        grid-template-columns: 1fr 35%;
    }

    .pdm-filter-button-group {
        flex: 1 1 100%;
    }
}

/* Mobile: Stack everything */
@media screen and (max-width: 782px) {
    .pdm-filters {
        padding: var(--pdm-spacing);
    }

    .pdm-filter-row-primary {
        grid-template-columns: 1fr;
        gap: var(--pdm-spacing);
    }

    .pdm-filter-row-secondary {
        flex-direction: column;
        gap: var(--pdm-spacing);
    }

    .pdm-filter-button-group {
        width: 100%;
    }

    .pdm-filter-buttons {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
        gap: 8px;
    }

    .pdm-filter-btn {
        width: 100%;
        justify-content: center;
        padding: 10px 14px;
    }

    .pdm-filter-row-tertiary {
        flex-direction: column;
        gap: calc(var(--pdm-spacing) * 0.75);
    }

    .pdm-filter-actions {
        width: 100%;
    }

    .pdm-filter-actions .pdm-button-secondary {
        width: 100%;
        justify-content: center;
    }

    .pdm-table {
        font-size: 13px;
    }

    .pdm-table th,
    .pdm-table td {
        padding: 10px 12px;
    }

    /* Adjust sortable headers for mobile */
    .pdm-sortable {
        padding-right: 28px !important;
    }

    .pdm-sort-icon {
        right: 8px;
        width: 14px;
        height: 14px;
    }

    /* Stack table on small screens */
    .pdm-table thead {
        display: none;
    }

    .pdm-table tbody,
    .pdm-table tr,
    .pdm-table td {
        display: block;
        width: 100%;
    }

    .pdm-table tr {
        margin-bottom: var(--pdm-spacing);
        border: 1px solid var(--pdm-border);
        border-radius: var(--pdm-radius);
        overflow: hidden;
    }

    .pdm-table td {
        text-align: left !important;
        padding-left: 50%;
        position: relative;
        border-bottom: 1px solid var(--pdm-border);
    }

    .pdm-table td:last-child {
        border-bottom: none;
    }

    .pdm-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        width: calc(50% - 24px);
        font-weight: 600;
        color: var(--pdm-text);
    }

    .pdm-col-checkbox {
        width: 100%;
        padding-left: 12px !important;
    }

    .pdm-col-checkbox::before {
        content: none;
    }

    .pdm-bulk-actions {
        text-align: center;
    }
}

@media screen and (max-width: 600px) {
    .pdm-filters,
    .pdm-table-wrapper {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .pdm-filters,
    .pdm-bulk-actions,
    .pdm-col-checkbox,
    .pdm-col-download {
        display: none !important;
    }

    .pdm-table-wrapper {
        border: none;
    }

    .pdm-table {
        border: 1px solid #000;
    }

    .pdm-table th,
    .pdm-table td {
        border: 1px solid #000;
    }

    .pdm-sort-icon {
        display: none;
    }
}

/* ==========================================================================
   Accessibility Enhancements
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --pdm-border: #000;
        --pdm-text: #000;
        --pdm-bg: #fff;
    }

    .pdm-button:focus,
    .pdm-search-input:focus,
    .pdm-filter-select:focus,
    .pdm-date-input:focus,
    .pdm-sortable:focus {
        outline: 3px solid #000;
    }

    .pdm-sort-icon::before,
    .pdm-sort-icon::after {
        border-color: #000 transparent transparent transparent;
    }

    .pdm-sorted-asc .pdm-sort-icon::before,
    .pdm-sorted-desc .pdm-sort-icon::after {
        border-color: #000 transparent transparent transparent;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible support */
.pdm-button:focus:not(:focus-visible),
.pdm-search-input:focus:not(:focus-visible),
.pdm-filter-select:focus:not(:focus-visible),
.pdm-date-input:focus:not(:focus-visible),
.pdm-table input[type="checkbox"]:focus:not(:focus-visible),
.pdm-table a:focus:not(:focus-visible),
.pdm-sortable:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}
