/* ===========================================
   AUDIT TAB - Audit Log & Undo System
   Phase 6: Professional Grey Design
   Phase 26.16: Renamed from History to Audit
   =========================================== */

/* History Tab Container */
#history-tab {
    display: none;
    height: 100%;
    flex-direction: column;
    background: var(--color-bg-secondary);
}

#history-tab.active {
    display: flex;
}

/* History Header */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: white;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.history-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-header h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: #7F65EB;
    border-radius: 2px;
}

/* Refresh Button */
.history-refresh-btn {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-refresh-btn:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.history-refresh-btn svg {
    width: 16px;
    height: 16px;
}

.history-refresh-btn.loading svg {
    animation: spin 1s linear infinite;
}

/* Filters Section */
.history-filters {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.history-filter-select {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--color-text-primary);
    background: white;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
}

.history-filter-select:hover,
.history-filter-select:focus {
    border-color: var(--color-primary);
}

.history-search {
    flex: 1;
    min-width: 150px;
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--color-text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.history-search:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(112, 85, 226, 0.1);
}

.history-search::placeholder {
    color: var(--color-text-muted);
}

/* History List */
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Empty State */
.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--color-text-muted);
    text-align: center;
}

.history-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.history-empty p {
    font-size: 14px;
    margin: 0;
}

/* History Item Card */
.history-item {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 10px;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.history-item:hover {
    border-color: #d1d5db;
    box-shadow: var(--shadow-sm);
}

.history-item:last-child {
    margin-bottom: 0;
}

/* Item Header */
.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.history-item-type {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Type Badge Colors - Professional greys with subtle hints */
.history-type-badge.data_cleaning {
    background: #e5e7eb;
    color: #374151;
}

.history-type-badge.formula_generation {
    background: #dbeafe;
    color: #1e40af;
}

.history-type-badge.model_building {
    background: #ede9fe;
    color: #5b21b6;
}

.history-type-badge.error_fixing {
    background: #fee2e2;
    color: #991b1b;
}

.history-type-badge.structure_change {
    background: #fef3c7;
    color: #92400e;
}

.history-type-badge.cell_change {
    background: #d1fae5;
    color: #065f46;
}

.history-type-badge.bulk_operation {
    background: #f3e8ff;
    color: #7c3aed;
}

.history-type-badge.chat {
    background: #f3f4f6;
    color: #4b5563;
}

/* Status Badge */
.history-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 500;
}

.history-status-badge.success {
    background: #dcfce7;
    color: #166534;
}

.history-status-badge.failed {
    background: #fee2e2;
    color: #991b1b;
}

.history-status-badge.pending {
    background: #fef3c7;
    color: #92400e;
}

.history-status-badge.executing {
    background: #dbeafe;
    color: #1e40af;
}

.history-status-badge.undone {
    background: #f3f4f6;
    color: #6b7280;
}

.history-status-badge .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Item Description */
.history-item-description {
    font-size: 13px;
    color: var(--color-text-primary);
    margin-bottom: 10px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Item Meta Row */
.history-item-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
}

.history-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-meta-item svg {
    width: 12px;
    height: 12px;
    opacity: 0.7;
}

/* Item Footer - Undo Section */
.history-item-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--color-border);
}

.history-time {
    font-size: 11px;
    color: var(--color-text-muted);
}

/* Phase 26.16: Approved By Display */
.history-approved-by {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--color-text-muted);
    margin-left: 12px;
}

.history-approved-by svg {
    color: var(--color-primary);
    opacity: 0.7;
}

/* Undo Button */
.history-undo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.history-undo-btn:hover:not(:disabled) {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.history-undo-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.history-undo-btn svg {
    width: 14px;
    height: 14px;
}

/* Undo Countdown Timer */
.undo-countdown {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--color-text-muted);
}

.undo-countdown.urgent {
    color: #dc2626;
    font-weight: 500;
}

.undo-countdown-bar {
    width: 60px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}

.undo-countdown-progress {
    height: 100%;
    background: var(--color-primary);
    transition: width 1s linear;
}

.undo-countdown.urgent .undo-countdown-progress {
    background: #dc2626;
}

/* Pagination */
.history-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: white;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.history-page-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-secondary);
    font-size: 12px;
    transition: all var(--transition-fast);
}

.history-page-btn:hover:not(:disabled) {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.history-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.history-page-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.history-page-info {
    font-size: 12px;
    color: var(--color-text-secondary);
    padding: 0 12px;
}

/* Stats Summary Bar */
.history-stats {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    background: var(--color-bg-tertiary);
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.history-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.history-stat-value {
    font-weight: 600;
    color: var(--color-text-primary);
}

.history-stat-label {
    color: var(--color-text-secondary);
}

/* Loading Skeleton */
.history-skeleton {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 10px;
}

.skeleton-line {
    height: 12px;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-line:last-child {
    margin-bottom: 0;
}

.skeleton-line.short {
    width: 40%;
}

.skeleton-line.medium {
    width: 70%;
}

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

/* Detail Modal */
.history-detail-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    animation: fadeIn 0.2s ease;
}

.history-detail-modal.hidden {
    display: none;
}

.history-detail-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.history-detail-header {
    background: #7F65EB;
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-detail-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.history-detail-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

.history-detail-close:hover {
    opacity: 1;
}

.history-detail-close svg {
    width: 20px;
    height: 20px;
}

.history-detail-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.detail-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 13px;
    color: var(--color-text-primary);
    line-height: 1.5;
}

.detail-value.code {
    font-family: 'Courier New', monospace;
    background: var(--color-bg-tertiary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    overflow-x: auto;
}

.history-detail-footer {
    padding: 16px 20px;
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Toast Notifications for History */
.history-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1f2937;
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 10001;
}

.history-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.history-toast.success {
    background: #166534;
}

.history-toast.error {
    background: #991b1b;
}

/* Responsive Adjustments */
@media (max-width: 400px) {
    .history-filters {
        flex-direction: column;
    }

    .history-filter-select,
    .history-search {
        width: 100%;
    }

    .history-item-meta {
        gap: 8px;
    }

    .history-stats {
        gap: 8px;
    }
}
