/* SQL Explorer Styles */

/* Schema Diagram Enhancements for Hierarchical Layout */
.diagram-controls button {
  padding: 6px 10px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.diagram-controls button:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.layout-toggle-btn {
  background: #4f46e5 !important;
  color: white !important;
  border: none !important;
  font-weight: 500;
}

.layout-toggle-btn:hover {
  background: #4338ca !important;
}

/* Node styling for hierarchical layout */
.table-node {
  /* Removed transitions to prevent vibration */
}

.node-rect {
  /* Removed transitions to prevent vibration */
}

.relationship-link {
  transition: stroke-opacity 0.3s ease, stroke-width 0.3s ease;
}

/* Layer backgrounds */
.layer-backgrounds rect {
  pointer-events: none;
}

.layer-backgrounds text {
  pointer-events: none;
  user-select: none;
}

/* Orphan table styling */
.orphan-indicator {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* Improved tooltip styling */
.schema-tooltip {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  max-width: 300px;
  word-wrap: break-word;
}

/* Table info panel improvements */
.table-info-content {
  background: white;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.table-stats {
  margin-top: 8px;
}

.table-stats > div {
  padding: 4px 0;
  border-bottom: 1px solid #f3f4f6;
}

.table-stats > div:last-child {
  border-bottom: none;
}

/* Main container and layout */
.sql-explorer-container {
  min-height: 100vh;
  background-color: #f3f4f6; /* bg-gray-100 */
  display: flex;
  flex-direction: column;
}

.dark .sql-explorer-container {
  background-color: #111827; /* dark:bg-gray-900 */
}

/* Header styles */
.sql-explorer-header {
  background-color: white;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  border-bottom: 1px solid #e5e7eb;
}

.dark .sql-explorer-header {
  background-color: #1f2937; /* dark:bg-gray-800 */
  border-bottom-color: #374151; /* dark:border-gray-700 */
}

/* Analytics-matching button styles */
.sql-explorer-btn {
  font-weight: 500;
  padding: 0.75rem 1.25rem;
  border-radius: 0.375rem;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
  font-size: 0.875rem;
  transition: all 0.15s ease-in-out;
  focus: outline-none;
  focus-visible: ring-2 ring-offset-2;
}

/* Primary button - matches analytics-btn-primary */
.sql-explorer-btn-primary {
  background-color: #059669; /* green-600 */
  color: white;
  font-weight: 700;
}

.sql-explorer-btn-primary:hover {
  background-color: #047857; /* green-700 */
}

.sql-explorer-btn-primary:focus {
  box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.5);
}

/* Secondary button - matches analytics-btn-secondary */
.sql-explorer-btn-secondary {
  background-color: #e5e7eb; /* gray-200 */
  color: #1f2937; /* gray-800 */
}

.sql-explorer-btn-secondary:hover {
  background-color: #d1d5db; /* gray-300 */
}

.dark .sql-explorer-btn-secondary {
  background-color: #374151; /* gray-700 */
  color: white;
}

.dark .sql-explorer-btn-secondary:hover {
  background-color: #4b5563; /* gray-600 */
}

/* Purple/AI button - matches analytics purple theme */
.sql-explorer-btn-purple {
  background-color: #4f46e5; /* indigo-600 */
  color: white;
  font-weight: 700;
}

.sql-explorer-btn-purple:hover {
  background-color: #4338ca; /* indigo-700 */
}

.sql-explorer-btn-purple:focus {
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.5);
}

/* White/secondary button - matches analytics-btn-secondary alternative */
.sql-explorer-btn-white {
  background-color: white;
  color: #374151; /* gray-700 */
  border: 1px solid #d1d5db; /* gray-300 */
}

.sql-explorer-btn-white:hover {
  background-color: #f9fafb; /* gray-50 */
  border-color: #9ca3af; /* gray-400 */
}

.dark .sql-explorer-btn-white {
  background-color: #374151; /* gray-700 */
  color: white;
  border-color: #4b5563; /* gray-600 */
}

.dark .sql-explorer-btn-white:hover {
  background-color: #4b5563; /* gray-600 */
  border-color: #6b7280; /* gray-500 */
}

/* Danger button - matches analytics-btn-danger */
.sql-explorer-btn-danger {
  background-color: #dc2626; /* red-600 */
  color: white;
  font-weight: 700;
}

.sql-explorer-btn-danger:hover {
  background-color: #b91c1c; /* red-700 */
}

.sql-explorer-btn-danger:focus {
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.5);
}

/* Small button variant */
.sql-explorer-btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Modal styles */
.sql-explorer-modal {
  position: fixed;
  inset: 0;
  background-color: rgba(75, 85, 99, 0.5);
  overflow-y: auto;
  height: 100%;
  width: 100%;
  z-index: 50;
}

.sql-explorer-modal-content {
  position: relative;
  top: 2.5rem;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.dark .sql-explorer-modal-content {
  background-color: #1f2937;
}

/* Modal header */
.sql-explorer-modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dark .sql-explorer-modal-header {
  border-bottom-color: #374151;
}

.sql-explorer-modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
}

.dark .sql-explorer-modal-title {
  color: white;
}

/* Form inputs - matching analytics-form-input */
.sql-explorer-input {
  margin-top: 0.25rem;
  display: block;
  width: 100%;
  border-radius: 0.375rem;
  border: 1px solid #d1d5db; /* border-gray-300 */
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  background-color: white;
  color: #111827;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.sql-explorer-input:focus {
  outline: none;
  border-color: #4f46e5; /* indigo-500 */
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.dark .sql-explorer-input {
  background-color: #111827; /* dark:bg-gray-900 */
  border-color: #4b5563; /* dark:border-gray-600 */
  color: white;
}

.dark .sql-explorer-input:focus {
  border-color: #4f46e5; /* indigo-500 */
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Select inputs - matching analytics-form-select */
.sql-explorer-select {
  margin-top: 0.25rem;
  display: block;
  width: 100%;
  border-radius: 0.375rem;
  border: 1px solid #d1d5db;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  background-color: white;
  color: #111827;
  padding: 0.5rem 2.5rem 0.5rem 0.75rem;
  font-size: 0.875rem;
  max-width: 400px;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Fixed width selects for filter bars */
.sql-explorer-select.w-32 {
  width: 9.6rem;
  max-width: 9.6rem;
  flex-shrink: 0;
}

.sql-explorer-select.w-36 {
  width: 10.8rem;
  max-width: 10.8rem;
  flex-shrink: 0;
}

.sql-explorer-select:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.dark .sql-explorer-select {
  background-color: #111827;
  border-color: #4b5563;
  color: white;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
}

.dark .sql-explorer-select:focus {
  border-color: #4f46e5;
}

/* Form labels - matching analytics-form-label */
.sql-explorer-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151; /* gray-700 */
  margin-bottom: 0.25rem;
}

.dark .sql-explorer-label {
  color: #d1d5db; /* gray-300 */
}

/* Loading indicators */
.sql-explorer-loading {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 2px solid rgba(79, 70, 229, 0.3);
  border-top-color: #4f46e5;
  border-radius: 50%;
  animation: sql-explorer-spin 1s linear infinite;
}

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

/* Query Tabs */
.modern-query-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: transparent;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #6b7280;
  white-space: nowrap;
  max-width: 180px;
  transition: all 0.2s ease;
  position: relative;
}

.dark .modern-query-tab {
  color: #9ca3af;
}

.modern-query-tab:hover {
  background: #f3f4f6;
  color: #374151;
}

.dark .modern-query-tab:hover {
  background: #374151;
  color: #e5e7eb;
}

.modern-query-tab.active {
  background: #e0e7ff !important;
  color: #4338ca !important;
  font-weight: 500;
}

.dark .modern-query-tab.active {
  background: #312e81 !important;
  color: #c7d2fe !important;
}

.modern-query-tab .tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.modern-query-tab .tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 0.25rem;
  transition: all 0.2s;
  flex-shrink: 0;
  opacity: 0;
}

.modern-query-tab:hover .tab-close {
  opacity: 1;
}

.modern-query-tab .tab-close:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.dark .modern-query-tab .tab-close:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.new-tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
}

.new-tab-btn:hover {
  background-color: #f3f4f6;
}

.dark .new-tab-btn:hover {
  background-color: #374151;
}

/* History and Query items */
.history-item,
.saved-query {
  padding: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  cursor: pointer;
  transition: background-color 0.2s;
}

.dark .history-item,
.dark .saved-query {
  border-color: #374151;
}

.history-item:hover,
.saved-query:hover {
  background: #f9fafb;
}

.dark .history-item:hover,
.dark .saved-query:hover {
  background: #374151;
}

.history-query {
  font-family: monospace;
  font-size: 0.75rem;
  color: #1f2937;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dark .history-query {
  color: #e5e7eb;
}

.history-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #6b7280;
}

.dark .history-meta {
  color: #9ca3af;
}

.history-error {
  color: #ef4444;
}

/* Results grid */
#results-grid {
  min-height: 400px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
}

.dark .results-header {
  border-color: #374151;
}

/* Error message styling */
.error-message {
  padding: 2rem;
  text-align: center;
  color: #dc2626;
}

.dark .error-message {
  color: #f87171;
}

/* Saved queries folder structure */
.saved-folder {
  margin-bottom: 1rem;
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  cursor: pointer;
  font-weight: 500;
  color: #374151;
  transition: background-color 0.2s;
}

.dark .folder-header {
  color: #e5e7eb;
}

.folder-header:hover {
  background: #f3f4f6;
}

.dark .folder-header:hover {
  background: #374151;
}

.saved-folder.collapsed .folder-queries {
  display: none;
}

.saved-query {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.5rem 0.5rem 1.5rem;
}

.query-name {
  flex: 1;
  font-size: 0.875rem;
  color: #4b5563;
}

.dark .query-name {
  color: #d1d5db;
}

.query-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.saved-query:hover .query-actions {
  opacity: 1;
}

.query-actions button {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: #6b7280;
  border-radius: 0.25rem;
  transition: background-color 0.2s;
}

.query-actions button:hover {
  background: #e5e7eb;
  color: #374151;
}

.dark .query-actions button:hover {
  background: #4b5563;
  color: #e5e7eb;
}

/* Monaco editor adjustments */
.monaco-editor {
  border-top: 1px solid #e5e7eb;
}

.dark .monaco-editor {
  border-color: #374151;
}

/* Panel resizing */
.resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s;
}

.resizer:hover,
.resizer.active {
  background: #6366f1;
}

body.resizing {
  cursor: col-resize;
  user-select: none;
}

/* Schema tree styles */
.schema-item.selected > div,
.table-item.selected > div {
  background-color: #e5e7eb;
  border-left: 3px solid #4f46e5;
  padding-left: calc(0.5rem - 3px);
}

.dark .schema-item.selected > div,
.dark .table-item.selected > div {
  background-color: #374151;
  border-left: 3px solid #6366f1;
  padding-left: calc(0.5rem - 3px);
}

/* Enhanced column display */
.column-item {
  transition: background-color 0.2s;
}

/* AI Assistant panel */
.ai-assistant-panel {
  background: white;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid #e5e7eb;
  transform: translateY(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease-in-out;
  opacity: 0;
  overflow: hidden;
}

.ai-assistant-panel.expanded {
  transform: translateY(0);
  opacity: 1;
}

.ai-assistant-panel.collapsing {
  transform: translateY(-100%);
  opacity: 0;
}

.dark .ai-assistant-panel {
  background: #1f2937;
  border-bottom-color: #374151;
}

.ai-assistant-header {
  padding: 0.75rem 1rem;
  background: #faf5ff;
  border-bottom: 1px solid #e9d5ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dark .ai-assistant-header {
  background: rgba(139, 92, 246, 0.2);
  border-bottom-color: #7c3aed;
}

/* Content overflow prevention */
pre, code {
  overflow-x: auto;
  word-wrap: break-word;
}

/* Ensure flex children can shrink properly */
.flex > * {
  min-width: 0;
}