/**
 * ProCargo Tables Styles
 * Data tables, sorting, filtering, pagination
 * 
 * @package ProCargo
 * @version 2.0.0
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */
:root {
    --procargo-table-bg: #ffffff;
    --procargo-table-border: #e5e7eb;
    --procargo-table-header-bg: #f9fafb;
    --procargo-table-header-text: #374151;
    --procargo-table-row-hover: #f3f4f6;
    --procargo-table-stripe: #fafafa;
    --procargo-table-text: #1f2937;
    --procargo-table-text-secondary: #6b7280;
}

.dark-theme,
[data-theme="dark"] {
    --procargo-table-bg: #1f2937;
    --procargo-table-border: #374151;
    --procargo-table-header-bg: #111827;
    --procargo-table-header-text: #e5e7eb;
    --procargo-table-row-hover: #374151;
    --procargo-table-stripe: #111827;
    --procargo-table-text: #f9fafb;
    --procargo-table-text-secondary: #9ca3af;
}

/* ==========================================================================
   Table Container
   ========================================================================== */
.procargo-table-container {
    background-color: var(--procargo-table-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.procargo-table-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--procargo-table-border);
}

.procargo-table-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--procargo-table-header-text);
    margin: 0;
}

.procargo-table-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ==========================================================================
   Table Filters
   ========================================================================== */
.procargo-table-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background-color: var(--procargo-table-header-bg);
    border-bottom: 1px solid var(--procargo-table-border);
}

.procargo-filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.procargo-filter-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--procargo-table-text-secondary);
    white-space: nowrap;
}

.procargo-filter-input,
.procargo-filter-select {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--procargo-table-border);
    border-radius: 0.375rem;
    background-color: var(--procargo-table-bg);
    color: var(--procargo-table-text);
    min-width: 150px;
}

.procargo-filter-select {
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1rem;
    appearance: none;
}

.procargo-filter-date {
    max-width: 140px;
}

.procargo-filter-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s;
}

.procargo-filter-btn-apply {
    background-color: #0066b3;
    color: white;
}

.procargo-filter-btn-apply:hover {
    background-color: #004d99;
}

.procargo-filter-btn-clear {
    background-color: transparent;
    color: var(--procargo-table-text-secondary);
    border: 1px solid var(--procargo-table-border);
}

.procargo-filter-btn-clear:hover {
    background-color: var(--procargo-table-row-hover);
}

/* Search */
.procargo-table-search {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.procargo-table-search input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    font-size: 0.875rem;
    border: 1px solid var(--procargo-table-border);
    border-radius: 0.375rem;
    background-color: var(--procargo-table-bg);
    color: var(--procargo-table-text);
}

.procargo-table-search input::placeholder {
    color: var(--procargo-table-text-secondary);
}

.procargo-table-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    color: var(--procargo-table-text-secondary);
    pointer-events: none;
}

/* ==========================================================================
   Table Wrapper (for horizontal scroll)
   ========================================================================== */
.procargo-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   Table Base
   ========================================================================== */
.procargo-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.procargo-table th,
.procargo-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--procargo-table-border);
}

/* ==========================================================================
   Table Header
   ========================================================================== */
.procargo-table thead {
    background-color: var(--procargo-table-header-bg);
}

.procargo-table th {
    font-weight: 600;
    color: var(--procargo-table-header-text);
    white-space: nowrap;
    user-select: none;
}

/* Sortable headers */
.procargo-table th.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 1.75rem;
}

.procargo-table th.sortable::after {
    content: '';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0.75rem;
    height: 0.75rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='%239ca3af' viewBox='0 0 24 24'%3e%3cpath d='M7 10l5 5 5-5H7z'/%3e%3c/svg%3e");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.5;
    transition: transform 0.15s, opacity 0.15s;
}

.procargo-table th.sortable:hover::after {
    opacity: 1;
}

.procargo-table th.sortable.asc::after {
    transform: translateY(-50%) rotate(180deg);
    opacity: 1;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='%230066b3' viewBox='0 0 24 24'%3e%3cpath d='M7 10l5 5 5-5H7z'/%3e%3c/svg%3e");
}

.procargo-table th.sortable.desc::after {
    opacity: 1;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='%230066b3' viewBox='0 0 24 24'%3e%3cpath d='M7 10l5 5 5-5H7z'/%3e%3c/svg%3e");
}

/* ==========================================================================
   Table Body
   ========================================================================== */
.procargo-table tbody tr {
    transition: background-color 0.15s;
}

.procargo-table tbody tr:hover {
    background-color: var(--procargo-table-row-hover);
}

.procargo-table td {
    color: var(--procargo-table-text);
    vertical-align: middle;
}

/* Striped rows */
.procargo-table.striped tbody tr:nth-child(even) {
    background-color: var(--procargo-table-stripe);
}

.procargo-table.striped tbody tr:nth-child(even):hover {
    background-color: var(--procargo-table-row-hover);
}

/* ==========================================================================
   Status Badges
   ========================================================================== */
.procargo-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    white-space: nowrap;
}

.procargo-status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
}

.procargo-status-pending {
    background-color: #fef3c7;
    color: #92400e;
}
.procargo-status-pending .procargo-status-dot {
    background-color: #f59e0b;
}

.procargo-status-processing,
.procargo-status-in_progress {
    background-color: #dbeafe;
    color: #1e40af;
}
.procargo-status-processing .procargo-status-dot,
.procargo-status-in_progress .procargo-status-dot {
    background-color: #3b82f6;
}

.procargo-status-completed,
.procargo-status-delivered,
.procargo-status-active {
    background-color: #d1fae5;
    color: #065f46;
}
.procargo-status-completed .procargo-status-dot,
.procargo-status-delivered .procargo-status-dot,
.procargo-status-active .procargo-status-dot {
    background-color: #10b981;
}

.procargo-status-cancelled,
.procargo-status-failed,
.procargo-status-archived {
    background-color: #fee2e2;
    color: #991b1b;
}
.procargo-status-cancelled .procargo-status-dot,
.procargo-status-failed .procargo-status-dot,
.procargo-status-archived .procargo-status-dot {
    background-color: #ef4444;
}

.procargo-status-draft {
    background-color: #f3f4f6;
    color: #4b5563;
}
.procargo-status-draft .procargo-status-dot {
    background-color: #6b7280;
}

/* Dark theme status badges */
.dark-theme .procargo-status-pending,
[data-theme="dark"] .procargo-status-pending {
    background-color: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.dark-theme .procargo-status-processing,
.dark-theme .procargo-status-in_progress,
[data-theme="dark"] .procargo-status-processing,
[data-theme="dark"] .procargo-status-in_progress {
    background-color: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.dark-theme .procargo-status-completed,
.dark-theme .procargo-status-delivered,
.dark-theme .procargo-status-active,
[data-theme="dark"] .procargo-status-completed,
[data-theme="dark"] .procargo-status-delivered,
[data-theme="dark"] .procargo-status-active {
    background-color: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

.dark-theme .procargo-status-cancelled,
.dark-theme .procargo-status-failed,
.dark-theme .procargo-status-archived,
[data-theme="dark"] .procargo-status-cancelled,
[data-theme="dark"] .procargo-status-failed,
[data-theme="dark"] .procargo-status-archived {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.dark-theme .procargo-status-draft,
[data-theme="dark"] .procargo-status-draft {
    background-color: rgba(107, 114, 128, 0.2);
    color: #d1d5db;
}

/* ==========================================================================
   Table Cell Types
   ========================================================================== */

/* Actions cell */
.procargo-table-actions-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.procargo-table-action {
    padding: 0.375rem;
    background: none;
    border: none;
    border-radius: 0.25rem;
    color: var(--procargo-table-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.procargo-table-action:hover {
    background-color: var(--procargo-table-row-hover);
    color: var(--procargo-table-text);
}

.procargo-table-action.view:hover {
    color: #0066b3;
}

.procargo-table-action.edit:hover {
    color: #f59e0b;
}

.procargo-table-action.delete:hover {
    color: #ef4444;
}

.procargo-table-action svg {
    width: 1.125rem;
    height: 1.125rem;
}

/* Checkbox cell */
.procargo-table-checkbox {
    width: 3rem;
}

.procargo-table-checkbox input {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* ID/Code cell */
.procargo-table-id {
    font-family: monospace;
    font-weight: 500;
    color: #0066b3;
}

/* Date cell */
.procargo-table-date {
    white-space: nowrap;
    color: var(--procargo-table-text-secondary);
}

/* Amount/Price cell */
.procargo-table-amount {
    font-family: monospace;
    font-weight: 500;
    white-space: nowrap;
}

/* Truncated text */
.procargo-table-truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Avatar cell */
.procargo-table-avatar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.procargo-table-avatar img {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    object-fit: cover;
}

.procargo-table-avatar-name {
    font-weight: 500;
}

.procargo-table-avatar-email {
    font-size: 0.75rem;
    color: var(--procargo-table-text-secondary);
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.procargo-table-empty {
    padding: 3rem 1.5rem;
    text-align: center;
}

.procargo-table-empty-icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 1rem;
    color: var(--procargo-table-text-secondary);
    opacity: 0.5;
}

.procargo-table-empty-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--procargo-table-text);
    margin-bottom: 0.5rem;
}

.procargo-table-empty-text {
    font-size: 0.875rem;
    color: var(--procargo-table-text-secondary);
}

/* ==========================================================================
   Loading State
   ========================================================================== */
.procargo-table-loading {
    position: relative;
    min-height: 200px;
}

.procargo-table-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dark-theme .procargo-table-loading::after,
[data-theme="dark"] .procargo-table-loading::after {
    background-color: rgba(17, 24, 39, 0.8);
}

.procargo-table-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--procargo-table-border);
    border-top-color: #0066b3;
    border-radius: 50%;
    animation: procargo-table-spin 0.8s linear infinite;
    z-index: 1;
}

@keyframes procargo-table-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Skeleton loading */
.procargo-table-skeleton td {
    padding: 1rem;
}

.procargo-skeleton {
    height: 1rem;
    background: linear-gradient(90deg, var(--procargo-table-border) 25%, var(--procargo-table-row-hover) 50%, var(--procargo-table-border) 75%);
    background-size: 200% 100%;
    animation: procargo-skeleton-shimmer 1.5s infinite;
    border-radius: 0.25rem;
}

.procargo-skeleton-sm {
    width: 60%;
}

.procargo-skeleton-md {
    width: 80%;
}

.procargo-skeleton-lg {
    width: 100%;
}

@keyframes procargo-skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ==========================================================================
   Pagination
   ========================================================================== */
.procargo-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--procargo-table-border);
}

.procargo-pagination-info {
    font-size: 0.875rem;
    color: var(--procargo-table-text-secondary);
}

.procargo-pagination-info strong {
    color: var(--procargo-table-text);
    font-weight: 600;
}

.procargo-pagination-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.procargo-pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--procargo-table-text);
    background-color: transparent;
    border: 1px solid var(--procargo-table-border);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s;
}

.procargo-pagination-btn:hover:not(:disabled) {
    background-color: var(--procargo-table-row-hover);
    border-color: var(--procargo-table-text-secondary);
}

.procargo-pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.procargo-pagination-btn.active {
    background-color: #0066b3;
    border-color: #0066b3;
    color: white;
}

.procargo-pagination-btn svg {
    width: 1rem;
    height: 1rem;
}

.procargo-pagination-ellipsis {
    padding: 0 0.25rem;
    color: var(--procargo-table-text-secondary);
}

/* Per page selector */
.procargo-pagination-per-page {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--procargo-table-text-secondary);
}

.procargo-pagination-per-page select {
    padding: 0.375rem 1.5rem 0.375rem 0.5rem;
    font-size: 0.875rem;
    border: 1px solid var(--procargo-table-border);
    border-radius: 0.375rem;
    background-color: var(--procargo-table-bg);
    color: var(--procargo-table-text);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.25rem center;
    background-repeat: no-repeat;
    background-size: 1rem;
    appearance: none;
}

/* ==========================================================================
   Table Stats Cards
   ========================================================================== */
.procargo-table-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--procargo-table-border);
}

.procargo-stat-card {
    padding: 1rem;
    background-color: var(--procargo-table-header-bg);
    border-radius: 0.5rem;
}

.procargo-stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--procargo-table-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.procargo-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--procargo-table-text);
}

.procargo-stat-change {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.procargo-stat-change.positive {
    color: #10b981;
}

.procargo-stat-change.negative {
    color: #ef4444;
}

/* ==========================================================================
   Bulk Actions
   ========================================================================== */
.procargo-bulk-actions {
    display: none;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background-color: #eff6ff;
    border-bottom: 1px solid #93c5fd;
}

.dark-theme .procargo-bulk-actions,
[data-theme="dark"] .procargo-bulk-actions {
    background-color: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
}

.procargo-bulk-actions.active {
    display: flex;
}

.procargo-bulk-count {
    font-size: 0.875rem;
    font-weight: 500;
    color: #1e40af;
}

.dark-theme .procargo-bulk-count,
[data-theme="dark"] .procargo-bulk-count {
    color: #93c5fd;
}

.procargo-bulk-buttons {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

/* ==========================================================================
   Responsive Table
   ========================================================================== */
@media (max-width: 768px) {
    .procargo-table-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .procargo-table-filters {
        flex-direction: column;
        align-items: stretch;
    }
    
    .procargo-filter-group {
        flex-wrap: wrap;
    }
    
    .procargo-table-search {
        max-width: none;
    }
    
    .procargo-pagination {
        flex-direction: column;
        align-items: center;
    }
    
    /* Card-style table on mobile */
    .procargo-table-responsive thead {
        display: none;
    }
    
    .procargo-table-responsive tbody tr {
        display: block;
        padding: 1rem;
        margin-bottom: 0.5rem;
        background-color: var(--procargo-table-bg);
        border: 1px solid var(--procargo-table-border);
        border-radius: 0.5rem;
    }
    
    .procargo-table-responsive tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--procargo-table-border);
    }
    
    .procargo-table-responsive tbody td:last-child {
        border-bottom: none;
    }
    
    .procargo-table-responsive tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--procargo-table-header-text);
        margin-right: 1rem;
    }
    
    .procargo-table-responsive .procargo-table-actions-cell {
        justify-content: flex-end;
    }
}

/* ==========================================================================
   Compact Table Variant
   ========================================================================== */
.procargo-table.compact th,
.procargo-table.compact td {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
}

/* ==========================================================================
   Bordered Table Variant
   ========================================================================== */
.procargo-table.bordered th,
.procargo-table.bordered td {
    border: 1px solid var(--procargo-table-border);
}

/* ==========================================================================
   Selection Highlight
   ========================================================================== */
.procargo-table tbody tr.selected {
    background-color: #eff6ff;
}

.dark-theme .procargo-table tbody tr.selected,
[data-theme="dark"] .procargo-table tbody tr.selected {
    background-color: rgba(59, 130, 246, 0.1);
}

/* ==========================================================================
   Row Expandable
   ========================================================================== */
.procargo-table-row-expandable {
    cursor: pointer;
}

.procargo-table-row-expandable td:first-child::before {
    content: '';
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    margin-right: 0.5rem;
    border-right: 2px solid var(--procargo-table-text-secondary);
    border-bottom: 2px solid var(--procargo-table-text-secondary);
    transform: rotate(-45deg);
    transition: transform 0.2s;
}

.procargo-table-row-expandable.expanded td:first-child::before {
    transform: rotate(45deg);
}

.procargo-table-row-details {
    display: none;
    background-color: var(--procargo-table-header-bg);
}

.procargo-table-row-details.visible {
    display: table-row;
}

.procargo-table-row-details td {
    padding: 1rem 1.5rem;
}
