/**
 * Visual SQL Builder Styles
 */

/* Modal Base */
.vsb-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.vsb-modal.show {
    opacity: 1;
}

.vsb-modal-content {
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    background: #1a1a2e;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.vsb-modal.show .vsb-modal-content {
    transform: scale(1);
}

/* Header */
.vsb-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: linear-gradient(135deg, #16213e 0%, #1a1a2e 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.vsb-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vsb-header-left i {
    font-size: 24px;
    color: #667eea;
}

.vsb-header-left h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

.vsb-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.vsb-close-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.vsb-close-btn:hover {
    background: rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

/* Buttons */
.vsb-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.vsb-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.vsb-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.vsb-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.vsb-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.vsb-btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.vsb-btn-mini {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.vsb-btn-mini:hover {
    background: rgba(102, 126, 234, 0.3);
    color: #667eea;
}

/* Body */
.vsb-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Connection Panel */
.vsb-connection-panel {
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.vsb-connection-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.vsb-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 120px;
}

.vsb-field-small {
    flex: 0 0 80px;
    min-width: 80px;
}

.vsb-field-database {
    flex: 1.5;
}

.vsb-database-input-wrapper {
    display: flex;
    gap: 6px;
}

.vsb-database-input-wrapper input {
    flex: 1;
}

.vsb-browse-btn {
    padding: 8px 12px;
    background: rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    color: #667eea;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.vsb-browse-btn:hover {
    background: rgba(102, 126, 234, 0.3);
}

.vsb-sqlite-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 14px;
    background: rgba(52, 152, 219, 0.1);
    border: 1px solid rgba(52, 152, 219, 0.2);
    border-radius: 6px;
    font-size: 12px;
    color: #3498db;
}

.vsb-sqlite-hint i {
    font-size: 14px;
}

.vsb-field label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vsb-field input,
.vsb-field select {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
}

.vsb-field input:focus,
.vsb-field select:focus {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.vsb-field input:focus-visible,
.vsb-field select:focus-visible {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}

/* Main Content */
.vsb-main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Tables Panel (Left) */
.vsb-tables-panel {
    width: 260px;
    background: rgba(0, 0, 0, 0.2);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.vsb-panel-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-wrap: wrap;
}

.vsb-panel-header i {
    color: #667eea;
}

.vsb-panel-header span {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
}

.vsb-search-input {
    width: 100%;
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    font-size: 12px;
}

.vsb-tables-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.vsb-empty-state {
    text-align: center;
    padding: 30px 20px;
    color: rgba(255, 255, 255, 0.3);
}

.vsb-empty-state i {
    font-size: 32px;
    margin-bottom: 10px;
}

.vsb-empty-state p {
    font-size: 12px;
    margin: 0;
}

/* Table Items */
.vsb-table-item {
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    overflow: hidden;
}

.vsb-table-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.vsb-table-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.vsb-table-header i {
    font-size: 12px;
    color: #667eea;
}

.vsb-table-header span {
    flex: 1;
    font-size: 13px;
    color: #fff;
}

.vsb-expand-icon {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    transition: transform 0.2s;
}

.vsb-table-item.expanded .vsb-expand-icon {
    transform: rotate(180deg);
}

.vsb-columns-list {
    display: none;
    padding: 4px 8px 8px;
    background: rgba(0, 0, 0, 0.2);
}

.vsb-table-item.expanded .vsb-columns-list {
    display: block;
}

.vsb-column-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: grab;
    transition: background 0.2s;
}

.vsb-column-item:hover {
    background: rgba(102, 126, 234, 0.2);
}

.vsb-column-item i {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
}

.vsb-column-item span {
    flex: 1;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
}

.vsb-col-type {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    font-family: monospace;
}

/* Builder Panel (Center) */
.vsb-builder-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.vsb-operation-tabs {
    display: flex;
    padding: 12px 16px;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.vsb-tab {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.vsb-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.vsb-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.vsb-builder-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Sections */
.vsb-section {
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.vsb-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.vsb-section-header i {
    color: #667eea;
    font-size: 12px;
}

.vsb-section-header span {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vsb-section-collapsible .vsb-section-header {
    cursor: pointer;
}

.vsb-toggle-icon {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    transition: transform 0.2s;
}

.vsb-section.collapsed .vsb-toggle-icon {
    transform: rotate(-90deg);
}

.vsb-section.collapsed .vsb-section-content {
    display: none;
}

.vsb-section-content {
    padding: 12px 16px;
}

/* Drop Zones */
.vsb-drop-zone {
    min-height: 60px;
    padding: 12px;
    border: 2px dashed rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
    align-content: flex-start;
    transition: all 0.2s;
}

.vsb-drop-zone-sm {
    min-height: 40px;
}

.vsb-drop-zone-active {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.vsb-drop-hint {
    color: rgba(255, 255, 255, 0.3);
    font-size: 12px;
    width: 100%;
    text-align: center;
    padding: 10px;
}

/* Selected Items */
.vsb-selected-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    font-size: 12px;
    color: #fff;
}

.vsb-selected-item i {
    color: #667eea;
    font-size: 10px;
}

.vsb-alias {
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
}

.vsb-remove-btn {
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: rgba(231, 76, 60, 0.2);
    border-radius: 4px;
    color: #e74c3c;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    transition: all 0.2s;
}

.vsb-remove-btn:hover {
    background: rgba(231, 76, 60, 0.4);
}

/* Column Selected with aggregate */
.vsb-column-selected {
    flex-wrap: wrap;
}

.vsb-aggregate-select {
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
    font-size: 11px;
}

.vsb-col-name {
    font-family: monospace;
}

.vsb-alias-input {
    width: 60px;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
    font-size: 11px;
}

/* JOIN/WHERE/ORDER rows */
.vsb-join-row,
.vsb-where-row,
.vsb-order-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.vsb-join-row select,
.vsb-where-row select,
.vsb-order-row select {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
}

.vsb-join-row input,
.vsb-where-row input,
.vsb-order-row input {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    flex: 1;
    min-width: 100px;
}

.vsb-join-row span {
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
}

.vsb-join-type {
    width: 120px;
}

.vsb-join-table {
    width: 120px !important;
    flex: 0 !important;
}

.vsb-join-on {
    flex: 1 !important;
}

.vsb-where-column {
    width: 150px !important;
    flex: 0 !important;
}

.vsb-where-operator {
    width: 100px;
}

.vsb-where-value {
    flex: 1 !important;
}

.vsb-order-column {
    flex: 1 !important;
}

.vsb-order-direction {
    width: 80px;
}

.vsb-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    cursor: pointer;
}

.vsb-checkbox input {
    width: 14px;
    height: 14px;
}

/* Limit Content */
.vsb-limit-content {
    display: flex;
    gap: 20px;
}

.vsb-field-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vsb-field-inline label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

.vsb-field-inline input {
    width: 100px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
}

/* Preview Panel (Right) */
.vsb-preview-panel {
    width: 320px;
    background: rgba(0, 0, 0, 0.3);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.vsb-sql-preview {
    flex: 1;
    padding: 16px;
    overflow: auto;
    background: rgba(0, 0, 0, 0.2);
}

.vsb-sql-preview pre {
    margin: 0;
}

.vsb-sql-preview code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #e6e6e6;
    white-space: pre-wrap;
    word-break: break-word;
}

.vsb-preview-actions {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.vsb-preview-actions .vsb-btn {
    width: 100%;
    justify-content: center;
}

/* Query Result */
.vsb-query-result {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    max-height: 250px;
    display: flex;
    flex-direction: column;
}

.vsb-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(39, 174, 96, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.vsb-result-header span {
    font-size: 12px;
    color: #27ae60;
    font-weight: 500;
}

.vsb-result-count {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

.vsb-result-table {
    flex: 1;
    overflow: auto;
    padding: 8px;
}

.vsb-result-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.vsb-result-data-table th,
.vsb-result-data-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.vsb-result-data-table th {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

.vsb-result-data-table td {
    color: rgba(255, 255, 255, 0.8);
    font-family: monospace;
}

.vsb-no-results {
    text-align: center;
    padding: 20px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
}

.vsb-more-results {
    text-align: center;
    padding: 10px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 11px;
    margin: 0;
}

/* Footer */
.vsb-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

/* Scrollbar */
.vsb-tables-list::-webkit-scrollbar,
.vsb-builder-area::-webkit-scrollbar,
.vsb-sql-preview::-webkit-scrollbar,
.vsb-result-table::-webkit-scrollbar {
    width: 6px;
}

.vsb-tables-list::-webkit-scrollbar-track,
.vsb-builder-area::-webkit-scrollbar-track,
.vsb-sql-preview::-webkit-scrollbar-track,
.vsb-result-table::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.vsb-tables-list::-webkit-scrollbar-thumb,
.vsb-builder-area::-webkit-scrollbar-thumb,
.vsb-sql-preview::-webkit-scrollbar-thumb,
.vsb-result-table::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.vsb-tables-list::-webkit-scrollbar-thumb:hover,
.vsb-builder-area::-webkit-scrollbar-thumb:hover,
.vsb-sql-preview::-webkit-scrollbar-thumb:hover,
.vsb-result-table::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Responsive */
@media (max-width: 1200px) {
    .vsb-modal-content {
        width: 98%;
        height: 95vh;
    }

    .vsb-tables-panel {
        width: 220px;
    }

    .vsb-preview-panel {
        width: 280px;
    }
}

@media (max-width: 900px) {
    .vsb-main-content {
        flex-direction: column;
    }

    .vsb-tables-panel,
    .vsb-preview-panel {
        width: 100%;
        max-height: 200px;
    }

    .vsb-builder-panel {
        flex: 1;
    }
}
