/**
 * Trail Intel - Unified AG-Grid Theme
 * Custom styling for all AG-Grid instances across the platform
 * Provides consistent, professional look with Trail Intel branding
 */

/* ========================================
   TOOLBAR STYLES
   ======================================== */

.ag-grid-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border-radius: 8px 8px 0 0;
    border-bottom: 2px solid #3b82f6;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.grid-search-input {
    padding: 8px 12px;
    border: 1px solid #475569;
    border-radius: 6px;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 14px;
    min-width: 200px;
    transition: all 0.2s ease;
}

.grid-search-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: #0f172a;
}

.grid-search-input::placeholder {
    color: #64748b;
}

.grid-row-count {
    font-size: 13px;
    color: #94a3b8;
    padding: 6px 12px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
    font-weight: 500;
}

.toolbar-btn {
    padding: 8px 14px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.toolbar-btn:active {
    transform: translateY(0);
}

.toolbar-btn:disabled {
    background: #475569;
    cursor: not-allowed;
    opacity: 0.5;
}

/* ========================================
   GRID WRAPPER
   ======================================== */

.ag-grid-wrapper {
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* ========================================
   AG-GRID THEME CUSTOMIZATION
   ======================================== */

/* Grid Background */
.ag-theme-alpine {
    --ag-background-color: #ffffff;
    --ag-foreground-color: #1e293b;
    --ag-header-background-color: #f8fafc;
    --ag-header-foreground-color: #0f172a;
    --ag-odd-row-background-color: #ffffff;
    --ag-row-hover-color: #f1f5f9;
    --ag-selected-row-background-color: #dbeafe;
    --ag-range-selection-background-color: rgba(59, 130, 246, 0.1);
    --ag-border-color: #e2e8f0;
    --ag-row-border-color: #f1f5f9;
    
    /* Grid spacing */
    --ag-grid-size: 6px;
    --ag-cell-horizontal-padding: 12px;
    
    /* Typography */
    --ag-font-size: 14px;
    --ag-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    
    /* Borders */
    --ag-borders: solid 1px;
    --ag-border-radius: 0;
    
    /* Icons */
    --ag-icon-font-family: 'agGridAlpine';
}

/* Header Styling */
.ag-theme-alpine .ag-header {
    border-bottom: 2px solid #3b82f6;
    font-weight: 600;
}

.ag-theme-alpine .ag-header-cell {
    padding: 12px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ag-theme-alpine .ag-header-cell-label {
    font-weight: 600;
    color: #475569;
}

/* Row Styling */
.ag-theme-alpine .ag-row {
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.15s ease;
}

.ag-theme-alpine .ag-row-hover {
    background-color: #f8fafc;
}

.ag-theme-alpine .ag-row-selected {
    background-color: #dbeafe !important;
    border-left: 3px solid #3b82f6;
}

.ag-theme-alpine .ag-row-selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #3b82f6;
}

/* Cell Styling */
.ag-theme-alpine .ag-cell {
    padding: 10px 12px;
    line-height: 1.5;
}

.ag-theme-alpine .ag-cell.text-center {
    text-align: center;
    justify-content: center;
}

/* Pagination */
.ag-theme-alpine .ag-paging-panel {
    border-top: 2px solid #e2e8f0;
    padding: 12px 16px;
    background: #f8fafc;
}

.ag-theme-alpine .ag-paging-button {
    color: #3b82f6;
    margin: 0 4px;
}

.ag-theme-alpine .ag-paging-button:disabled {
    color: #cbd5e1;
}

/* Filter Panels */
.ag-theme-alpine .ag-filter {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.ag-theme-alpine .ag-filter-toolpanel {
    background: #f8fafc;
}

/* Floating Filters */
.ag-theme-alpine .ag-floating-filter {
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
}

.ag-theme-alpine .ag-floating-filter-input {
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 13px;
}

.ag-theme-alpine .ag-floating-filter-input:focus {
    border-color: #3b82f6;
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Checkboxes */
.ag-theme-alpine .ag-checkbox-input-wrapper {
    color: #3b82f6;
}

.ag-theme-alpine .ag-checkbox-input-wrapper.ag-checked {
    background-color: #3b82f6;
    border-color: #3b82f6;
}

.ag-theme-alpine .ag-checkbox-input-wrapper:focus-within {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* ========================================
   CUSTOM CELL RENDERERS
   ======================================== */

/* Thumbnail Cell */
.thumbnail-cell {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 10px !important;
}

/* Thumbnails */
.grid-thumbnail {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #e2e8f0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: block;
}

.grid-thumbnail:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #3b82f6;
    cursor: pointer;
    z-index: 10;
}

.no-thumbnail {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border: 2px dashed #cbd5e1;
    border-radius: 6px;
    font-size: 24px;
    opacity: 0.5;
}

/* Confidence Bars */
.confidence-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.confidence-bar {
    height: 8px;
    border-radius: 4px;
    transition: width 0.3s ease;
    min-width: 20px;
}

.confidence-text {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    min-width: 35px;
    text-align: right;
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

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

.status-warning {
    background: #fef3c7;
    color: #92400e;
}

.status-error {
    background: #fee2e2;
    color: #991b1b;
}

.status-info {
    background: #dbeafe;
    color: #1e40af;
}

.status-pending {
    background: #f3e8ff;
    color: #6b21a8;
}

.status-default {
    background: #f1f5f9;
    color: #475569;
}

/* Action Buttons */
.grid-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.grid-action-btn {
    padding: 6px 10px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.grid-action-btn:hover {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.grid-action-btn:active {
    transform: translateY(0);
}

.grid-action-btn.danger:hover {
    background: #ef4444;
    border-color: #ef4444;
}

.grid-action-btn.success:hover {
    background: #22c55e;
    border-color: #22c55e;
}

/* ========================================
   RESPONSIVE STYLES
   ======================================== */

@media (max-width: 1024px) {
    .ag-grid-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .toolbar-left,
    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .grid-search-input {
        flex: 1;
        min-width: 150px;
    }
    
    .ag-theme-alpine {
        --ag-font-size: 13px;
        --ag-cell-horizontal-padding: 8px;
    }
}

@media (max-width: 768px) {
    .ag-grid-toolbar {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .toolbar-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .grid-thumbnail {
        width: 50px;
        height: 50px;
    }
    
    .ag-theme-alpine {
        --ag-font-size: 12px;
        --ag-cell-horizontal-padding: 6px;
    }
    
    .ag-theme-alpine .ag-header-cell {
        padding: 10px 8px;
        font-size: 12px;
    }
    
    .grid-row-count {
        font-size: 12px;
        padding: 4px 8px;
    }
}

@media (max-width: 480px) {
    .toolbar-right {
        flex-direction: column;
        gap: 6px;
    }
    
    .toolbar-btn {
        width: 100%;
        justify-content: center;
    }
    
    .grid-search-input {
        width: 100%;
    }
    
    .grid-thumbnail {
        width: 40px;
        height: 40px;
    }
    
    .confidence-bar-container {
        flex-direction: column;
        gap: 4px;
    }
}

/* ========================================
   LOADING & EMPTY STATES
   ======================================== */

.ag-theme-alpine .ag-overlay-loading-wrapper {
    background: rgba(255, 255, 255, 0.9);
}

.ag-theme-alpine .ag-overlay-loading-center {
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.ag-theme-alpine .ag-overlay-no-rows-wrapper {
    padding: 40px 20px;
}

.ag-theme-alpine .ag-overlay-no-rows-center {
    color: #64748b;
    font-size: 14px;
}

/* Custom no-data message */
.grid-no-data {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #64748b;
}

.grid-no-data-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.grid-no-data-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #475569;
}

.grid-no-data-message {
    font-size: 14px;
    color: #64748b;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.ag-theme-alpine .text-bold {
    font-weight: 600;
}

.ag-theme-alpine .text-muted {
    color: #64748b;
}

.ag-theme-alpine .text-success {
    color: #22c55e;
}

.ag-theme-alpine .text-warning {
    color: #eab308;
}

.ag-theme-alpine .text-error {
    color: #ef4444;
}

.ag-theme-alpine .text-info {
    color: #3b82f6;
}

/* Selection checkbox styling */
.ag-theme-alpine .ag-selection-checkbox {
    margin-right: 8px;
}

/* Improve scrollbar appearance */
.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 5px;
}

.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .ag-grid-toolbar {
        display: none;
    }
    
    .ag-theme-alpine {
        border: 1px solid #000;
    }
    
    .ag-theme-alpine .ag-header {
        background: #f0f0f0 !important;
    }
    
    .grid-action-btn {
        display: none;
    }
}
