/* AG Grid Viewer Styles */

.ag-viewer {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #fff;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.ag-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: wrap;
    gap: 12px;
}

.ag-viewer-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ag-viewer-title h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
}

.ag-viewer-count {
    font-size: 13px;
    background: #e8e8e8;
    color: #555;
    padding: 4px 12px;
    border-radius: 12px;
}

.ag-viewer-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ag-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: #fff;
    color: #333;
    cursor: pointer;
    transition: all 0.15s;
    height: 36px;
    box-sizing: border-box;
}

.ag-btn:hover {
    background: #f5f5f5;
    border-color: #b0b0b0;
}

.ag-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ag-btn svg {
    flex-shrink: 0;
}

.ag-btn-primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.ag-btn-primary:hover {
    background: #1d4ed8;
}

.ag-btn-danger {
    color: #dc2626;
    border-color: #dc2626;
}

.ag-btn-danger:hover {
    background: #dc2626;
    color: #fff;
}

.ag-viewer-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: #666;
    text-align: center;
}

.ag-viewer-empty h3 {
    margin: 0 0 8px;
    color: #333;
}

.ag-viewer-empty p {
    margin: 0;
}

/* AG Grid Theme Customizations */
.ag-theme-alpine {
    --ag-header-background-color: #f8f9fa;
    --ag-header-foreground-color: #333;
    --ag-header-cell-hover-background-color: #e8e8e8;
    --ag-row-hover-color: #f5f5f5;
    --ag-selected-row-background-color: #e3f2fd;
    --ag-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --ag-font-size: 13px;
    --ag-grid-size: 6px;
    --ag-list-item-height: 32px;
}

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

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

.ag-theme-alpine .ag-right-aligned-cell {
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    font-size: 12px;
}

.ag-theme-alpine .ag-paging-panel {
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    padding: 8px 16px;
}

.ag-theme-alpine .ag-paging-button {
    padding: 4px 8px;
    border-radius: 4px;
}

.ag-theme-alpine .ag-paging-button:hover {
    background: #e0e0e0;
}

/* Column group headers */
.ag-theme-alpine .ag-header-group-cell {
    background: #e8eef4;
    border-bottom: 2px solid #2563eb;
}

/* Pinned columns */
.ag-theme-alpine .ag-pinned-left-header,
.ag-theme-alpine .ag-pinned-left-cols-container {
    border-right: 2px solid #e0e0e0;
}

/* Config Modal Styles */
.ag-config-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: 10000;
}

.ag-config-modal-content {
    background: #fff;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.ag-config-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.ag-config-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.ag-config-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.ag-config-close:hover {
    color: #333;
}

.ag-config-modal-body {
    flex: 1;
    overflow: auto;
    padding: 20px;
    background: #f8f9fa;
}

.ag-config-modal-body pre {
    margin: 0;
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    color: #333;
    white-space: pre-wrap;
    word-break: break-word;
}

.ag-config-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
}

/* Center aligned cells for numeric columns */
.ag-theme-alpine .ag-center-aligned-cell {
    text-align: center;
}

/* Grand total row - prevent hover background change */
.ag-theme-alpine .ag-row-pinned-bottom,
.ag-theme-alpine .ag-row-pinned-bottom.ag-row-hover,
.ag-theme-alpine .ag-row-pinned-bottom:hover,
.ag-theme-alpine .ag-pinned-bottom-floating-row,
.ag-theme-alpine .ag-floating-bottom .ag-row,
.ag-theme-alpine .ag-floating-bottom .ag-row:hover,
.ag-theme-alpine .ag-floating-bottom .ag-row.ag-row-hover {
    background-color: #1e3a5f !important;
    --ag-row-hover-color: #1e3a5f !important;
}

.ag-theme-alpine .ag-row-pinned-bottom .ag-cell,
.ag-theme-alpine .ag-row-pinned-bottom:hover .ag-cell,
.ag-theme-alpine .ag-row-pinned-bottom.ag-row-hover .ag-cell,
.ag-theme-alpine .ag-floating-bottom .ag-row .ag-cell,
.ag-theme-alpine .ag-floating-bottom .ag-row:hover .ag-cell {
    color: #fff !important;
    background-color: #1e3a5f !important;
}

/* ARR Analysis Panel Styles */
.arr-analysis-panel .arr-toggle input[type=checkbox]:checked + .arr-toggle-slider {
    background: linear-gradient(135deg, #00d4ff 0%, #00ff88 100%) !important;
}

.arr-analysis-panel .arr-toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #ffffff;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.arr-analysis-panel .arr-toggle input[type=checkbox]:checked + .arr-toggle-slider::after {
    transform: translateX(16px);
}

/* Gap filled cell styling */
.cell-gap-filled {
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        rgba(255, 159, 67, 0.15) 3px,
        rgba(255, 159, 67, 0.15) 6px
    ) !important;
    border: 1px dashed #ff9f43 !important;
}

/* Change detection cell styling */
.cell-change-new_customer {
    background: rgba(0, 212, 255, 0.15) !important;
}

.cell-change-churn {
    background: rgba(255, 71, 87, 0.15) !important;
}

.cell-change-major_upsell,
.cell-change-upsell {
    background: rgba(0, 255, 136, 0.15) !important;
}

.cell-change-major_downsell,
.cell-change-downsell {
    background: rgba(255, 107, 107, 0.15) !important;
}

/* Change badges */
.change-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 700;
    vertical-align: middle;
}

.badge-new {
    background: rgba(0, 212, 255, 0.3);
    color: #00d4ff;
}

.badge-churn {
    background: rgba(255, 71, 87, 0.3);
    color: #ff4757;
}

.badge-upsell {
    background: rgba(0, 255, 136, 0.3);
    color: #00ff88;
}

.badge-downsell {
    background: rgba(255, 107, 107, 0.3);
    color: #ff6b6b;
}

/* Editable cell styling */
.cell-editable {
    cursor: pointer !important;
    position: relative;
}

.cell-editable::after {
    content: '✏️';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.cell-editable:hover::after {
    opacity: 0.6;
}

/* ========== IMPROVED TOGGLE STYLING ========== */
.arr-toggle input[type=checkbox]:checked + .arr-toggle-slider {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%) !important;
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
}

.arr-toggle-slider {
    background: #2a2a4a !important;
    transition: all 0.3s ease;
}

.arr-toggle-slider::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all 0.3s ease;
}

.arr-toggle input[type=checkbox]:checked + .arr-toggle-slider::after {
    transform: translateX(16px);
}

/* ========== CHANGE DETECTION CELL BORDERS ========== */
.cell-change-new {
    border: 2px solid #00d4ff !important;
    background: rgba(0, 212, 255, 0.08) !important;
}

.cell-change-churn {
    border: 2px solid #ff4757 !important;
    background: rgba(255, 71, 87, 0.08) !important;
}

.cell-change-upsell {
    border: 2px solid #00ff88 !important;
    background: rgba(0, 255, 136, 0.08) !important;
}

.cell-change-downsell {
    border: 2px solid #ff6b6b !important;
    background: rgba(255, 107, 107, 0.08) !important;
}

/* ========== SMALL CIRCULAR BADGES (TOP-RIGHT) ========== */
.change-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 8px;
    line-height: 1;
    z-index: 10;
}

.dot-new {
    color: #00d4ff;
    text-shadow: 0 0 4px rgba(0, 212, 255, 0.8);
}

.dot-churn {
    color: #ff4757;
    text-shadow: 0 0 4px rgba(255, 71, 87, 0.8);
}

.dot-upsell {
    color: #00ff88;
    text-shadow: 0 0 4px rgba(0, 255, 136, 0.8);
}

.dot-downsell {
    color: #ff6b6b;
    text-shadow: 0 0 4px rgba(255, 107, 107, 0.8);
}

/* Make ARR cells position relative for badge positioning */
.arr-cell {
    position: relative !important;
}

/* ========== TOGGLE SWITCH STYLING ========== */
/* Hide the actual checkbox input - VERY SPECIFIC SELECTOR */
.arr-toggle-label > input[type="checkbox"].arr-toggle-input,
.arr-analysis-panel input[type="checkbox"].arr-toggle-input,
input.arr-toggle-input,
.arr-toggle-input {
    position: absolute !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

/* The visual toggle track */
.arr-toggle-track {
    position: relative;
    display: inline-block !important;
    min-width: 44px;
    width: 44px;
    min-height: 24px;
    height: 24px;
    background: #3a3a5a;
    border-radius: 12px;
    border: 1px solid #555;
    transition: all 0.3s ease;
    cursor: pointer;
    flex-shrink: 0;
    vertical-align: middle;
    box-sizing: border-box;
}

.arr-toggle-track::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: #888;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Active/Checked state */
.arr-toggle-track.active {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%) !important;
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.5);
}

.arr-toggle-track.active::after {
    transform: translateX(18px);
    background: #fff;
}

/* Hover state */
.arr-toggle-label:hover .arr-toggle-track {
    background: #4a4a6a;
}

.arr-toggle-label:hover .arr-toggle-track.active {
    background: linear-gradient(135deg, #00e4ff 0%, #00aadd 100%) !important;
}


/* ========== TOGGLE SWITCH STYLING ========== */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

/* Hide the actual checkbox input - COMPREHENSIVE */
.switch input[type=checkbox] {
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
    pointer-events: none !important;
    visibility: hidden !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

.switch input {
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
    pointer-events: none !important;
    visibility: hidden !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #4a4a6a;
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: #888;
    transition: 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.switch input:checked + .slider {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.5);
    border-color: #00d4ff;
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
    background-color: #fff;
}

.switch input:focus + .slider {
    box-shadow: 0 0 3px #00d4ff;
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 8px;
}


/* Active state for sliders (JS-controlled) */
.slider.active {
    background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%) !important;
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.5) !important;
    border-color: #00d4ff !important;
}

.slider.active:before {
    transform: translateX(20px) !important;
    background-color: #fff !important;
}


/* SQL and Config Editor Textarea Styling */
.ag-config-textarea,
.ag-sql-textarea {
    width: 100%;
    min-height: 400px;
    height: 400px;
    padding: 16px;
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #00ff88;
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 8px;
    resize: vertical;
    outline: none;
}

.ag-config-textarea:focus,
.ag-sql-textarea:focus {
    border-color: #00d4ff;
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.2);
}

.ag-config-textarea[readonly],
.ag-sql-textarea[readonly] {
    cursor: default;
    opacity: 0.9;
}

/* Ensure modal body has proper height for textarea */
.ag-sql-editor-content .ag-config-modal-body,
.ag-config-editor-content .ag-config-modal-body {
    min-height: 450px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Config Editor pre styling */
.ag-config-modal-body pre {
    background: #1a1a2e;
    color: #00ff88;
    padding: 16px;
    border-radius: 8px;
    min-height: 400px;
    max-height: 500vh;
    overflow: auto;
    font-size: 13px;
    line-height: 1.6;
}


/* ============================================================================== */
/* Animated Change Detection Badges                                             */
/* ============================================================================== */

/* Base style for all change cells */
.ag-cell.arr-change-new,
.ag-cell.arr-change-churn,
.ag-cell.arr-change-upsell,
.ag-cell.arr-change-downsell,
.ag-cell.arr-gap-filled {
    position: relative !important;
    overflow: visible !important;
}


/* ===== AG Grid Layout Fix (Safe Version 2026-01-31d) ===== */
/* Only target AG Grid elements, not global page elements */

/* AG Viewer container - use fixed height as fallback */
.ag-viewer {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 280px);
    overflow: hidden;
}

/* Grid container fills remaining space */
#agGridContainer {
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* AG Grid internal elements */
#agGridContainer .ag-root-wrapper {
    height: 100%;
}

#agGridContainer .ag-body-viewport {
    overflow: auto;
}

/* Pinned bottom (grand total) row */
#agGridContainer .ag-floating-bottom {
    flex-shrink: 0;
}

/* Horizontal scroll bar */
#agGridContainer .ag-body-horizontal-scroll {
    flex-shrink: 0;
    min-height: 12px;
}

/* Custom scrollbar styling */
#agGridContainer ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#agGridContainer ::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 5px;
}

#agGridContainer ::-webkit-scrollbar-thumb {
    background: rgba(99,102,241,0.4);
    border-radius: 5px;
}

#agGridContainer ::-webkit-scrollbar-thumb:hover {
    background: rgba(99,102,241,0.6);
}

/* ===== Blue Scrollbar Styling (2026-01-31e) ===== */
/* Match the grand total row blue color */

/* AG Grid scrollbars */
.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar,
.ag-theme-alpine .ag-body-horizontal-scroll-viewport::-webkit-scrollbar,
.ag-theme-alpine .ag-center-cols-viewport::-webkit-scrollbar,
#agGridContainer ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-track,
.ag-theme-alpine .ag-body-horizontal-scroll-viewport::-webkit-scrollbar-track,
.ag-theme-alpine .ag-center-cols-viewport::-webkit-scrollbar-track,
#agGridContainer ::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.5);
    border-radius: 6px;
}

.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-thumb,
.ag-theme-alpine .ag-body-horizontal-scroll-viewport::-webkit-scrollbar-thumb,
.ag-theme-alpine .ag-center-cols-viewport::-webkit-scrollbar-thumb,
#agGridContainer ::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border-radius: 6px;
    border: 2px solid rgba(30, 41, 59, 0.5);
}

.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-thumb:hover,
.ag-theme-alpine .ag-body-horizontal-scroll-viewport::-webkit-scrollbar-thumb:hover,
.ag-theme-alpine .ag-center-cols-viewport::-webkit-scrollbar-thumb:hover,
#agGridContainer ::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #334155 0%, #475569 100%);
}

/* Scrollbar corner */
.ag-theme-alpine .ag-body-viewport::-webkit-scrollbar-corner,
#agGridContainer ::-webkit-scrollbar-corner {
    background: rgba(30, 41, 59, 0.5);
}

/* Firefox scrollbar styling */
.ag-theme-alpine .ag-body-viewport,
.ag-theme-alpine .ag-body-horizontal-scroll-viewport,
.ag-theme-alpine .ag-center-cols-viewport,
#agGridContainer {
    scrollbar-width: thin;
    scrollbar-color: #334155 rgba(30, 41, 59, 0.5);
}
