/* Data Workbench Styles */

:root {
    --panel-bg: var(--card-bg);
    --panel-border: var(--border-color);
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --info-color: #3b82f6;
}

/* Main App Layout */
.bdw-app {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1rem 2rem 1rem;
}

/* Resizable Layout */
.resizable-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    max-height: none;
}

.resizable-layout.resizing {
    cursor: ns-resize;
    user-select: none;
}

/* Main Content Panel */
.main-content-panel {
    display: flex;
    flex-direction: column;
    min-height: 150px;
    overflow: hidden;
}

.main-content-panel .panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* SQL Console Panel */
.sql-console-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sql-console-panel .panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sql-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sql-content bdw-sql-console {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Resize Handle */
.resize-handle {
    height: 8px;
    background: var(--border-color);
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    user-select: none;
}

.resize-handle:hover {
    background: var(--primary-color);
}

.resize-grip {
    width: 40px;
    height: 3px;
    background: var(--text-secondary);
    border-radius: 2px;
    position: relative;
}

.resize-grip::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--text-secondary);
    border-radius: 1px;
}

.resize-grip::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--text-secondary);
    border-radius: 1px;
}

.resize-handle:hover .resize-grip,
.resize-handle:hover .resize-grip::before,
.resize-handle:hover .resize-grip::after {
    background: white;
}

/* Progress Bar for Detailed Stats */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--input-bg);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 1rem;
}

.stats-results {
    max-height: 400px;
    overflow-y: auto;
}

/* Stats Button Description */
.stats-button-description {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--input-bg);
    border-radius: 4px;
    border-left: 3px solid var(--info-color);
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--input-bg);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

.tab-actions {
    display: flex;
    gap: 0.5rem;
}

/* Tab Content */
.tab-content {
    position: relative;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    height: 100%;
    overflow: auto;
}

/* Tab Panel Specific Styles */
#dataTab.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

#schemaTab bdw-schema-card,
#statsTab bdw-stats-panel {
    display: block;
    width: 100%;
    flex: 1;
    overflow: auto;
}

#schemaTab bdw-schema-card .panel,
#statsTab bdw-stats-panel .panel {
    border: none;
    padding: 0;
    background: transparent;
}

#schemaTab bdw-schema-card .panel h3,
#statsTab bdw-stats-panel .panel h3 {
    margin-top: 0;
}

/* File Drop Zone */
.file-drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    background: var(--panel-bg);
    transition: border-color 0.2s, background-color 0.2s;
    cursor: pointer;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 5%, var(--panel-bg));
}

.file-drop-zone input[type="file"] {
    display: none;
}

.drop-text {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.drop-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--button-bg);
    color: var(--button-text);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--button-hover);
}

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

.btn-primary:hover {
    background: color-mix(in srgb, var(--primary-color) 90%, black);
}

/* URL Input */
.url-input-group {
    display: flex;
    gap: 0.5rem;
    max-width: 500px;
    margin: 1rem auto 0;
}

.url-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-primary);
}

/* Panel Layout - Updated for single column tabbed interface */
.panels-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

@media (min-width: 1200px) {
    /* No additional constraints for larger screens */
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 1.5rem;
}

.panel h3 {
    margin: 0 0 1rem 0;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: 600;
}

/* Data Grid Container */
.data-grid-container {
    display: flex;
    flex-direction: column;
    height: 400px;
    min-height: 200px;
    /* Removed max-height constraint to allow unlimited growth */
}

.data-grid-container.resizing {
    cursor: ns-resize;
    user-select: none;
}

/* Data Grid */
.data-grid {
    overflow: auto;
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 4px 4px 0 0;
    width: 100%;
    background: var(--panel-bg);
}

/* Data Grid Resize Handle */
.data-grid-resize-handle {
    height: 8px;
    background: var(--border-color);
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    user-select: none;
    border-radius: 0 0 4px 4px;
}

.data-grid-resize-handle:hover {
    background: var(--primary-color);
}

/* Data Grid Controls */
.data-grid-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    background: var(--panel-bg);
}

/* Reset Buttons */
.resize-reset-btn,
.column-reset-btn {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.resize-reset-btn:hover,
.column-reset-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.resize-reset-btn:active,
.column-reset-btn:active {
    transform: scale(0.95);
}

.data-grid table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-grid .resizable-table {
    table-layout: fixed;
    width: 100%;
}

.data-grid th,
.data-grid td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    width: 200px;
    min-width: 120px;
    max-width: 200px;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
}

.data-grid td .cell-content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.data-grid th {
    background: var(--card-bg);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 0;
}

.data-grid tr:hover {
    background: color-mix(in srgb, var(--primary-color) 3%, var(--panel-bg));
}

/* Column Header Layout */
.column-header {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0.5rem 0.75rem;
    position: relative;
}

.column-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Column Resize Handle */
.column-resize-handle {
    position: absolute;
    right: -2px;
    top: 0;
    bottom: 0;
    width: 12px;
    cursor: col-resize;
    background: linear-gradient(to right, transparent 30%, var(--border-color) 45%, var(--border-color) 55%, transparent 70%);
    border-right: 3px solid var(--border-color);
    transition: all 0.2s;
    z-index: 3;
    opacity: 0.6;
}

.column-resize-handle:hover {
    border-right-color: var(--primary-color);
    background: linear-gradient(to right, transparent 20%, var(--primary-color) 40%, var(--primary-color) 60%, transparent 80%);
    opacity: 1;
    width: 16px;
    right: -4px;
}

.column-resize-handle:active {
    border-right-color: var(--primary-color);
    background: var(--primary-color);
    opacity: 1;
    width: 16px;
    right: -4px;
}

/* Add a visual indicator when hovering over the header */
.column-header:hover .column-resize-handle {
    opacity: 0.8;
}

/* Make the entire header area show the resize cursor near the right edge */
.column-header {
    cursor: default;
}

.column-header:hover {
    background: color-mix(in srgb, var(--primary-color) 5%, var(--card-bg));
}

/* Copyable Cell Styles */
.copyable-cell {
    position: relative;
}

.copy-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
    z-index: 4;
    color: var(--text-secondary);
    white-space: nowrap;
}

.copyable-cell:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.copy-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* Schema Display */
.schema-table {
    width: 100%;
    font-size: 0.9rem;
}

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

.schema-table th {
    font-weight: 600;
    color: var(--text-primary);
}

.type-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.type-varchar { background: #ddd6fe; color: #5b21b6; }
.type-integer { background: #dbeafe; color: #1d4ed8; }
.type-double { background: #dcfce7; color: #166534; }
.type-boolean { background: #fef3c7; color: #92400e; }
.type-timestamp { background: #fce7f3; color: #be185d; }

/* Stats Panel */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.stat-item {
    text-align: center;
    padding: 0.75rem;
    background: var(--input-bg);
    border-radius: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    display: block;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Export Panel */
.export-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.format-btn {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background: var(--panel-bg);
    color: var(--text-primary);
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.format-btn:hover {
    border-color: var(--primary-color);
}

.format-btn.active {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 10%, var(--panel-bg));
    color: var(--primary-color);
}

.export-settings {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--input-bg);
    border-radius: 4px;
    display: none;
}

.export-settings.active {
    display: block;
}

.setting-group {
    margin-bottom: 0.75rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.setting-group select,
.setting-group input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-primary);
}

/* SQL Console */
.sql-textarea {
    width: 100%;
    height: 150px;
    min-height: 100px;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9rem;
    resize: vertical;
}

.sql-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    justify-content: space-between;
    align-items: center;
}

.sql-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Status Messages */
.status-message {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    font-size: 0.9rem;
}

.status-success {
    background: color-mix(in srgb, var(--success-color) 10%, var(--panel-bg));
    color: var(--success-color);
    border: 1px solid color-mix(in srgb, var(--success-color) 30%, var(--panel-bg));
}

.status-error {
    background: color-mix(in srgb, var(--error-color) 10%, var(--panel-bg));
    color: var(--error-color);
    border: 1px solid color-mix(in srgb, var(--error-color) 30%, var(--panel-bg));
}

.status-info {
    background: color-mix(in srgb, var(--info-color) 10%, var(--panel-bg));
    color: var(--info-color);
    border: 1px solid color-mix(in srgb, var(--info-color) 30%, var(--panel-bg));
}

/* Loading States */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--panel-bg);
    margin: 5% auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

.modal-header h3 {
    margin: 0;
    color: var(--primary-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--error-color);
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

/* Error Modal Styles */
.error-modal-content {
    max-width: 600px;
}

.error-header {
    background: linear-gradient(135deg, var(--error-color) 0%, #dc2626 100%);
    color: white;
    border-bottom: none;
}

.error-header h3 {
    color: white;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.error-details {
    margin-bottom: 1.5rem;
}

.error-details h4 {
    color: var(--text-primary);
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
}

.error-details p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

.error-explanation {
    background: var(--input-bg);
    padding: 1rem;
    border-radius: 6px;
    margin: 1rem 0;
    border-left: 3px solid var(--warning-color);
}

.error-explanation ul {
    margin: 0.5rem 0 0 0;
    padding-left: 1.2rem;
    color: var(--text-secondary);
}

.error-explanation li {
    margin: 0.3rem 0;
}

.error-actions h4 {
    color: var(--text-primary);
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.action-buttons .btn {
    flex: 1;
    min-width: 160px;
    padding: 0.75rem 1rem;
    font-weight: 600;
    justify-content: center;
    text-align: center;
}

.ignore-errors-btn {
    background: var(--warning-color) !important;
    border-color: var(--warning-color) !important;
}

.ignore-errors-btn:hover {
    background: #d97706 !important;
    border-color: #d97706 !important;
}

.ignore-explanation {
    background: var(--panel-bg);
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--info-color);
}

.ignore-explanation p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.ignore-explanation strong {
    color: var(--text-primary);
}

/* Ignore Errors Checkbox Styles */
.ignore-errors-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    user-select: none;
}

.ignore-errors-checkbox input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.ignore-errors-checkbox:hover {
    color: var(--primary-color);
}

.file-options {
    border: 1px solid var(--border-color);
}

.option-help {
    line-height: 1.4;
}

/* Mobile Optimization Notice */
.mobile-notice {
    display: none;
    background: var(--info-color);
    color: white;
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .mobile-notice {
        display: block;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .drop-actions {
        flex-direction: column;
    }
    
    .url-input-group {
        flex-direction: column;
    }
    
    .export-options {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    }
    
    .data-grid th,
    .data-grid td {
        max-width: 120px;
    }
    
    .tab-nav {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .tab-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .tab-actions {
        justify-content: center;
    }
    
    .modal-content {
        margin: 2% auto;
        width: 95%;
        max-height: 90vh;
    }
    
    .resizable-layout {
        min-height: 70vh;
    }
    
    .resize-handle {
        height: 12px;
    }
    
    .resize-grip {
        width: 60px;
        height: 4px;
    }
}