/**
 * IntelliDB Enterprise - Visual Query Builder Styles
 */

/* ============================================================================
   Container Layout
   ============================================================================ */

.query-builder-container {
    display: flex;
    height: 100%;
    background: #1a1a1a;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ============================================================================
   Sidebar - Schema Browser
   ============================================================================ */

.query-builder-sidebar {
    width: 280px;
    background: #252525;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.schema-browser {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 15px;
}

.schema-browser h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

#table-search {
    width: 100%;
    padding: 8px 12px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 13px;
    margin-bottom: 15px;
}

#table-search:focus {
    outline: none;
    border-color: #4a9eff;
}

#table-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for table list */
#table-list::-webkit-scrollbar {
    width: 8px;
}

#table-list::-webkit-scrollbar-track {
    background: #1a1a1a;
}

#table-list::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

#table-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Table items */
.table-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s ease;
}

.table-item:hover {
    background: #333;
    border-color: #4a9eff;
    transform: translateX(2px);
}

.table-item:active {
    cursor: grabbing;
}

.table-item.dragging {
    opacity: 0.5;
}

.table-icon {
    font-size: 18px;
    margin-right: 10px;
}

.table-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
}

.table-schema {
    font-size: 11px;
    color: #888;
    background: #1a1a1a;
    padding: 2px 6px;
    border-radius: 3px;
}

/* ============================================================================
   Main Area - Canvas and SQL
   ============================================================================ */

.query-builder-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Canvas Area */
.query-builder-canvas {
    flex: 1;
    background: #1a1a1a;
    position: relative;
    overflow: auto;
    min-height: 400px;
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 16px;
    text-align: center;
    pointer-events: none;
}

/* SQL Display Area */
.query-builder-sql {
    background: #252525;
    border-top: 1px solid #333;
    padding: 15px;
    max-height: 300px;
    display: flex;
    flex-direction: column;
}

.query-builder-sql h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

#generated-sql {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #e0e0e0;
    overflow: auto;
    margin-bottom: 10px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.sql-actions {
    display: flex !important;
    gap: 12px !important;
    justify-content: flex-end !important;
    padding: 15px 0 5px 0 !important;
    border-top: 2px solid #444 !important;
    margin-top: 15px !important;
    background: #252525 !important;
}

/* Execute button - make it VERY prominent */
#execute-btn,
.sql-actions .button-primary {
    padding: 12px 24px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    background: linear-gradient(135deg, #4a9eff 0%, #3a8eef 100%) !important;
    border: 2px solid #5aa8ff !important;
    box-shadow: 0 4px 12px rgba(74, 158, 255, 0.5) !important;
    color: #fff !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

#execute-btn:hover,
.sql-actions .button-primary:hover {
    background: linear-gradient(135deg, #5aa8ff 0%, #4a9eff 100%) !important;
    box-shadow: 0 6px 16px rgba(74, 158, 255, 0.6) !important;
    transform: translateY(-2px) !important;
    border-color: #6ab8ff !important;
}

/* Validate and Clear buttons */
#validate-btn,
#clear-btn,
.sql-actions .button-secondary {
    padding: 10px 20px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    background: #444 !important;
    border: 1px solid #666 !important;
    color: #e0e0e0 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

#validate-btn:hover,
#clear-btn:hover,
.sql-actions .button-secondary:hover {
    background: #555 !important;
    border-color: #777 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4) !important;
}

/* ============================================================================
   Canvas Elements - Tables
   ============================================================================ */

.canvas-table {
    position: absolute;
    background: #2a2a2a;
    border: 2px solid #4a9eff;
    border-radius: 8px;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: move;
    z-index: 10;
}

.canvas-table.selected {
    border-color: #66b3ff;
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

.canvas-table-header {
    background: #4a9eff;
    color: #fff;
    padding: 10px 12px;
    border-radius: 6px 6px 0 0;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.canvas-table-alias {
    font-size: 11px;
    opacity: 0.8;
    margin-left: 8px;
}

.canvas-table-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: background 0.2s;
}

.canvas-table-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.canvas-table-columns {
    max-height: 300px;
    overflow-y: auto;
}

.canvas-column {
    padding: 8px 12px;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.canvas-column:hover {
    background: #333;
}

.canvas-column:last-child {
    border-bottom: none;
}

.canvas-column-checkbox {
    margin-right: 8px;
}

.canvas-column-name {
    flex: 1;
    font-size: 13px;
    color: #e0e0e0;
}

.canvas-column-type {
    font-size: 11px;
    color: #888;
    background: #1a1a1a;
    padding: 2px 6px;
    border-radius: 3px;
}

.canvas-column-key {
    margin-left: 6px;
    font-size: 11px;
    color: #ffd700;
}

/* ============================================================================
   Canvas Elements - Joins/Connectors
   ============================================================================ */

.canvas-connector {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

.canvas-connector line {
    stroke: #4a9eff;
    stroke-width: 2;
    fill: none;
}

.canvas-connector.join-inner line {
    stroke: #4a9eff;
}

.canvas-connector.join-left line {
    stroke: #66bb6a;
}

.canvas-connector.join-right line {
    stroke: #ffa726;
}

.canvas-connector.join-full line {
    stroke: #ab47bc;
}

.join-label {
    position: absolute;
    background: #2a2a2a;
    border: 1px solid #4a9eff;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    color: #fff;
    pointer-events: all;
    cursor: pointer;
    z-index: 15;
}

.join-label:hover {
    background: #333;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.button-primary {
    background: #4a9eff;
    color: #fff;
}

.button-primary:hover {
    background: #3a8eef;
}

.button-primary:active {
    background: #2a7edf;
}

.button-secondary {
    background: #444;
    color: #e0e0e0;
}

.button-secondary:hover {
    background: #555;
}

.button-secondary:active {
    background: #333;
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================================
   Modals and Dialogs
   ============================================================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

.modal-close {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #333;
    color: #fff;
}

.modal-body {
    color: #e0e0e0;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ============================================================================
   Form Elements
   ============================================================================ */

.form-group {
    margin-bottom: 15px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 500;
    color: #e0e0e0;
}

.form-input,
.form-select {
    width: 100%;
    padding: 8px 12px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 13px;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: #4a9eff;
}

/* ============================================================================
   WHERE Clause Builder
   ============================================================================ */

.where-builder {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 15px;
    margin-top: 15px;
}

.where-builder-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.where-builder-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.condition-group {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 10px;
}

.condition-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.condition-operator-toggle {
    display: flex;
    gap: 5px;
}

.operator-btn {
    padding: 4px 12px;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.operator-btn.active {
    background: #4a9eff;
    border-color: #4a9eff;
    color: #fff;
}

.condition-item {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px;
    background: #252525;
    border-radius: 4px;
}

.condition-item select,
.condition-item input {
    flex: 1;
    min-width: 0;
}

.condition-remove {
    background: #d32f2f;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    transition: background 0.2s;
}

.condition-remove:hover {
    background: #c62828;
}

.add-condition-btn {
    width: 100%;
    padding: 8px;
    background: #333;
    border: 1px dashed #555;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.add-condition-btn:hover {
    background: #444;
    border-color: #4a9eff;
}

/* ============================================================================
   Tooltips
   ============================================================================ */

.tooltip {
    position: absolute;
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 2000;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.tooltip::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #333;
}

/* ============================================================================
   Validation Results
   ============================================================================ */

.validation-result {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 15px;
    margin-top: 15px;
}

.validation-result.valid {
    border-color: #66bb6a;
}

.validation-result.invalid {
    border-color: #ef5350;
}

.validation-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.validation-icon {
    font-size: 20px;
    margin-right: 10px;
}

.validation-icon.valid {
    color: #66bb6a;
}

.validation-icon.invalid {
    color: #ef5350;
}

.validation-message {
    font-size: 14px;
    font-weight: 500;
    color: #fff;
}

.validation-details {
    font-size: 13px;
    color: #e0e0e0;
    margin-top: 10px;
}

.validation-cost {
    display: inline-block;
    background: #1a1a1a;
    padding: 4px 8px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    margin-top: 5px;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media (max-width: 1024px) {
    .query-builder-sidebar {
        width: 240px;
    }

    .canvas-table {
        min-width: 180px;
    }
}

@media (max-width: 768px) {
    .query-builder-container {
        flex-direction: column;
    }

    .query-builder-sidebar {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid #333;
    }

    .query-builder-sql {
        max-height: 200px;
    }
}

/* ============================================================================
   Animations
   ============================================================================ */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.pulse {
    animation: pulse 2s infinite;
}

/* ============================================================================
   Utility Classes
   ============================================================================ */

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: #888;
}

.text-success {
    color: #66bb6a;
}

.text-error {
    color: #ef5350;
}

.text-warning {
    color: #ffa726;
}

.mt-10 {
    margin-top: 10px;
}

.mb-10 {
    margin-bottom: 10px;
}

.p-10 {
    padding: 10px;
}

/* ============================================================================
   Inline Query Builder Container (for embedding in SQL Editor)
   ============================================================================ */

#visual-query-builder-container {
    min-height: 600px;
    height: 600px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    overflow: hidden;
}

#query-builder-root {
    width: 100%;
    height: 100%;
}

/* Ensure the query builder container fills its parent */
#query-builder-root .query-builder-container {
    height: 100%;
}