/**
 * Database Tab Styles
 * Mongoku/Supabase-inspired database UI
 */

.database-container {
  display: flex;
  height: 100%;
  background: var(--editor-bg, #1e1e1e);
  color: var(--editor-text, #d4d4d4);
}

/* ============ Sidebar ============ */
.database-sidebar {
  width: 250px;
  border-right: 1px solid var(--border-color, #3e3e42);
  background: var(--sidebar-bg, #252526);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.collections-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #3e3e42);
  background: var(--header-bg, #2d2d30);
}

.collections-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--header-text, #cccccc);
}

.collections-header .btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

#collection-search {
  margin: 12px 12px 8px;
  padding: 6px 12px;
  background: var(--input-bg, #3c3c3c);
  border: 1px solid var(--border-color, #3e3e42);
  border-radius: 4px;
  color: var(--input-text, #cccccc);
  font-size: 13px;
}

#collection-search:focus {
  outline: none;
  border-color: var(--primary-color, #007acc);
  box-shadow: 0 0 0 1px var(--primary-color, #007acc);
}

.collections-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.collection-item {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s;
  font-size: 13px;
}

.collection-item:hover {
  background: var(--hover-bg, #2a2d2e);
}

.collection-item.active {
  background: var(--primary-bg, #094771);
  color: var(--primary-text, #ffffff);
}

.collection-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collection-count {
  font-size: 11px;
  opacity: 0.7;
  margin-left: 8px;
}

/* ============ Main Content ============ */
.database-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.database-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #3e3e42);
  background: var(--header-bg, #2d2d30);
}

.database-toolbar h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--header-text, #cccccc);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.toolbar-actions .btn {
  padding: 6px 12px;
  font-size: 13px;
}

#document-table-container {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

/* ============ Document Table ============ */
.document-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.document-table thead {
  background: var(--header-bg, #2d2d30);
  position: sticky;
  top: 0;
  z-index: 10;
}

.document-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border-color, #3e3e42);
  color: var(--header-text, #cccccc);
  cursor: pointer;
  user-select: none;
}

.document-table th:hover {
  background: var(--hover-bg, #2a2d2e);
}

.document-table th.sortable::after {
  content: '⇅';
  margin-left: 4px;
  opacity: 0.4;
}

.document-table th.sorted-asc::after {
  content: '↑';
  opacity: 1;
}

.document-table th.sorted-desc::after {
  content: '↓';
  opacity: 1;
}

.document-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color, #3e3e42);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-table tbody tr {
  transition: background 0.2s;
}

.document-table tbody tr:hover {
  background: var(--hover-bg, #2a2d2e);
}

.document-actions {
  display: flex;
  gap: 8px;
}

.document-actions button {
  padding: 4px 8px;
  font-size: 11px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  background: var(--button-bg, #0e639c);
  color: var(--button-text, #ffffff);
  transition: background 0.2s;
}

.document-actions button:hover {
  background: var(--button-hover, #1177bb);
}

.document-actions button.btn-danger {
  background: #c5352c;
}

.document-actions button.btn-danger:hover {
  background: #e24944;
}

/* ============ Pagination ============ */
.database-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color, #3e3e42);
  background: var(--header-bg, #2d2d30);
}

.pagination-info {
  font-size: 13px;
  color: var(--text-secondary, #cccccc);
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

.pagination-controls button {
  padding: 6px 12px;
  font-size: 13px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  background: var(--button-bg, #0e639c);
  color: var(--button-text, #ffffff);
  transition: background 0.2s;
}

.pagination-controls button:hover:not(:disabled) {
  background: var(--button-hover, #1177bb);
}

.pagination-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============ Empty State ============ */
.database-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
}

.database-empty-state i {
  font-size: 48px;
  color: var(--icon-color, #858585);
  margin-bottom: 16px;
}

.database-empty-state h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--header-text, #cccccc);
}

.database-empty-state p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary, #858585);
}

/* ============ Document Editor Modal ============ */
#document-editor-modal .modal-dialog {
  max-width: 800px;
}

#document-editor-container {
  min-height: 400px;
  background: var(--editor-bg, #1e1e1e);
  border: 1px solid var(--border-color, #3e3e42);
  border-radius: 4px;
  padding: 12px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 13px;
  color: var(--editor-text, #d4d4d4);
}

#document-json-editor {
  width: 100%;
  min-height: 400px;
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font: inherit;
  resize: vertical;
}

/* ============ Loading State ============ */
.database-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 14px;
  color: var(--text-secondary, #858585);
}

.database-loading i {
  margin-right: 8px;
  animation: spin 1s linear infinite;
}

/* ============ Error State ============ */
.database-error {
  padding: 16px;
  background: rgba(229, 66, 57, 0.1);
  border: 1px solid rgba(229, 66, 57, 0.3);
  border-radius: 4px;
  margin: 16px;
  color: #ff8888;
}

.database-error strong {
  display: block;
  margin-bottom: 8px;
}

/* ============ Read-Only Badge ============ */
.read-only-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  background: rgba(255, 170, 0, 0.2);
  border: 1px solid rgba(255, 170, 0, 0.4);
  border-radius: 3px;
  font-size: 11px;
  color: #ffaa00;
  margin-left: 12px;
}

.read-only-badge i {
  margin-right: 4px;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .database-sidebar {
    width: 200px;
  }
  
  .toolbar-actions {
    flex-wrap: wrap;
  }
  
  .document-table {
    font-size: 12px;
  }
  
  .document-table th,
  .document-table td {
    padding: 8px;
  }
}

/* ============ Query Builder ============ */
.query-builder-panel {
  position: absolute;
  top: 60px;
  left: 270px;
  right: 20px;
  bottom: 60px;
  background: var(--editor-bg, #1e1e1e);
  border: 1px solid var(--border-color, #3e3e42);
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.query-builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--header-bg, #2d2d30);
  border-bottom: 1px solid var(--border-color, #3e3e42);
}

.query-builder-header h5 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--header-text, #cccccc);
  display: flex;
  align-items: center;
  gap: 8px;
}

.query-builder-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.query-conditions-container {
  margin-bottom: 16px;
}

.query-condition {
  margin-bottom: 12px;
}

.query-condition .card-body {
  padding: 12px;
  background: var(--input-bg, #3c3c3c);
  border: 1px solid var(--border-color, #3e3e42);
}

.condition-field,
.condition-field-type,
.condition-operator,
.condition-value,
.condition-combinator {
  background: var(--input-bg, #3c3c3c);
  border: 1px solid var(--border-color, #3e3e42);
  color: var(--input-text, #cccccc);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
}

.condition-field:focus,
.condition-field-type:focus,
.condition-operator:focus,
.condition-value:focus,
.condition-combinator:focus {
  outline: none;
  border-color: var(--primary-color, #007acc);
  box-shadow: 0 0 0 1px var(--primary-color, #007acc);
}

.query-preview-container {
  margin-top: 16px;
}

.query-preview-code {
  background: var(--code-bg, #1e1e1e);
  border: 1px solid var(--border-color, #3e3e42);
  border-radius: 4px;
  padding: 12px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
  font-size: 12px;
  color: var(--code-text, #d4d4d4);
  max-height: 200px;
  overflow: auto;
}

.query-builder-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.query-builder-actions .btn {
  padding: 8px 16px;
  font-size: 13px;
}

.export-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color, #3e3e42);
}

.export-actions label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--header-text, #cccccc);
}

.query-builder-alert {
  margin-bottom: 16px;
}

/* Load/Save Query Modals */
.load-saved-query {
  border: 1px solid var(--border-color, #3e3e42);
  transition: all 0.2s;
}

.load-saved-query:hover {
  background: var(--hover-bg, #2a2d2e);
  border-color: var(--primary-color, #007acc);
}

.delete-saved-query {
  margin-left: 8px;
}

.delete-saved-query:hover {
  background: #e24944 !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   AnyDB Panel — Lovable-style database management UI
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Onboarding ────────────────────────────────────────────────────────── */

.anydb-onboarding {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-color, #1e1e1e);
}

.anydb-onboarding-card {
  text-align: center;
  max-width: 420px;
  padding: 3rem 2rem;
  border-radius: 16px;
  background: var(--sidebar-bg, #252526);
  border: 1px solid var(--border-color, #3c3c3c);
}

.anydb-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.5rem;
  border-radius: 16px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: white;
}

.anydb-onboarding-card h3 {
  color: var(--text-color, #e0e0e0);
  margin-bottom: 0.75rem;
}

.anydb-features {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0;
  text-align: left;
}

.anydb-features li {
  padding: 0.4rem 0;
  color: var(--text-secondary, #999);
  font-size: 0.9rem;
}

.anydb-features li i {
  margin-right: 0.5rem;
  width: 16px;
}

/* ── Connect Form ──────────────────────────────────────────────────────── */

.anydb-connect-form {
  text-align: left;
  margin: 1.5rem 0;
}

.anydb-connect-form .form-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-color, #e0e0e0);
}

.anydb-connect-form .form-text {
  font-size: 0.72rem;
}

.anydb-onboarding-footer {
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color, #3c3c3c);
}

/* ── Dashboard Layout ──────────────────────────────────────────────────── */

.anydb-dashboard {
  display: flex;
  height: 100%;
  background: var(--bg-color, #1e1e1e);
}

.anydb-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg, #252526);
  border-right: 1px solid var(--border-color, #3c3c3c);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.anydb-sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #3c3c3c);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.anydb-sidebar-header h4 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-color, #e0e0e0);
}

.anydb-status-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.anydb-status-badge.connected {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
}

.anydb-status-badge.connected i {
  font-size: 0.45rem;
  margin-right: 4px;
  vertical-align: middle;
}

.anydb-sidebar-section {
  padding: 12px;
}

.anydb-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #999);
}

/* ── Table List ────────────────────────────────────────────────────────── */

.anydb-table-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.anydb-table-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary, #999);
  transition: all 0.15s;
}

.anydb-table-item:hover {
  background: var(--hover-bg, #2a2d2e);
  color: var(--text-color, #e0e0e0);
}

.anydb-table-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
}

.anydb-table-item i {
  font-size: 0.75rem;
  opacity: 0.6;
}

/* ── Main Content ──────────────────────────────────────────────────────── */

.anydb-main {
  flex: 1;
  overflow: auto;
  padding: 0;
}

.anydb-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #3c3c3c);
}

.anydb-table-header h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-color, #e0e0e0);
}

.anydb-table-header .btn {
  margin-left: 6px;
}

/* ── Data Table ────────────────────────────────────────────────────────── */

.anydb-data-table-wrap {
  overflow-x: auto;
}

.anydb-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.anydb-data-table thead th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary, #999);
  background: var(--sidebar-bg, #252526);
  border-bottom: 1px solid var(--border-color, #3c3c3c);
  position: sticky;
  top: 0;
  z-index: 1;
}

.anydb-data-table tbody td {
  padding: 8px 12px;
  color: var(--text-color, #e0e0e0);
  border-bottom: 1px solid rgba(60, 60, 60, 0.4);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.anydb-data-table tbody tr:hover {
  background: var(--hover-bg, #2a2d2e);
}

.anydb-data-table code {
  font-size: 0.75rem;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.1);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ── Pagination ────────────────────────────────────────────────────────── */

.anydb-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-top: 1px solid var(--border-color, #3c3c3c);
  font-size: 0.85rem;
  color: var(--text-secondary, #999);
}

/* ── States ─────────────────────────────────────────────────────────────── */

.anydb-placeholder,
.anydb-loading,
.anydb-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  color: var(--text-secondary, #999);
}

.anydb-error {
  color: #f87171;
}

/* ── Engine Badges ─────────────────────────────────────────────────────── */

.anydb-engines {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 1rem 0;
}

.anydb-engine-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  background: rgba(99, 102, 241, 0.1);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.anydb-engine-badge.small {
  font-size: 0.7rem;
  padding: 2px 6px;
}

/* ── Engine Selector (Onboarding) ──────────────────────────────────────── */

.anydb-engine-select {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 1.25rem 0;
  text-align: left;
}

.anydb-engine-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-color, #3c3c3c);
  background: var(--bg-color, #1e1e1e);
  cursor: pointer;
  transition: all 0.15s;
}

.anydb-engine-option:hover {
  border-color: rgba(99, 102, 241, 0.4);
}

.anydb-engine-option.selected {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.08);
}

.anydb-engine-radio {
  flex-shrink: 0;
  font-size: 1.1rem;
  color: var(--text-secondary, #666);
}

.anydb-engine-option.selected .anydb-engine-radio {
  color: #6366f1;
}

.anydb-engine-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.anydb-engine-info strong {
  color: var(--text-color, #e0e0e0);
  font-size: 0.9rem;
}

.anydb-engine-info strong i {
  margin-right: 4px;
}

.anydb-engine-info span {
  color: var(--text-secondary, #999);
  font-size: 0.78rem;
}

/* ── Connection Info ───────────────────────────────────────────────────── */

.anydb-connection-info {
  border-bottom: 1px solid var(--border-color, #3c3c3c);
}

.anydb-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 0.78rem;
}

.anydb-info-label {
  color: var(--text-secondary, #999);
  flex-shrink: 0;
}

.anydb-info-value {
  color: var(--text-color, #e0e0e0);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.anydb-masked {
  cursor: pointer;
  font-family: monospace;
  font-size: 0.72rem;
}

.anydb-info-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.anydb-info-actions .btn {
  flex: 1;
  font-size: 0.7rem;
  padding: 3px 6px;
}

/* ── Tables Section ────────────────────────────────────────────────────── */

.anydb-tables-section {
  flex: 1;
  overflow-y: auto;
  border-bottom: 1px solid var(--border-color, #3c3c3c);
}

.anydb-table-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.anydb-table-count {
  font-size: 0.7rem;
  color: var(--text-secondary, #666);
  flex-shrink: 0;
}

/* ── Table Header Toolbar ──────────────────────────────────────────────── */

.anydb-table-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.anydb-table-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.anydb-filter-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.anydb-filter-input {
  width: 180px;
  font-size: 0.78rem;
  background: var(--bg-color, #1e1e1e) !important;
  color: var(--text-color, #e0e0e0) !important;
  border-color: var(--border-color, #3c3c3c) !important;
}

/* ── Sortable Headers ──────────────────────────────────────────────────── */

.anydb-sortable {
  cursor: pointer;
  user-select: none;
}

.anydb-sortable:hover {
  color: var(--text-color, #e0e0e0);
}

.anydb-sort-icon {
  font-size: 0.6rem;
  margin-left: 4px;
  opacity: 0.4;
}

.anydb-sortable:hover .anydb-sort-icon {
  opacity: 0.8;
}

/* ── Row Actions ───────────────────────────────────────────────────────── */

.anydb-actions-col {
  width: 80px;
  text-align: right;
}

.anydb-row-actions {
  white-space: nowrap;
  text-align: right;
  opacity: 0;
  transition: opacity 0.15s;
}

.anydb-data-table tbody tr:hover .anydb-row-actions {
  opacity: 1;
}

.anydb-row-actions .btn {
  padding: 2px 6px;
  font-size: 0.7rem;
  margin-left: 2px;
}

/* ── Null / JSON values ────────────────────────────────────────────────── */

.anydb-null {
  color: #666;
  font-style: italic;
  font-size: 0.78rem;
}

.anydb-json {
  font-size: 0.72rem;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.08);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ── Schema Modal ──────────────────────────────────────────────────────── */

.anydb-schema-table h6 {
  color: var(--text-color, #e0e0e0);
  margin-bottom: 0.5rem;
}

.anydb-schema-table h6 i {
  margin-right: 6px;
  opacity: 0.6;
}

.anydb-schema-rels code {
  font-size: 0.8rem;
  color: #a5b4fc;
}

/* ── AI Hint Chips ─────────────────────────────────────────────────────── */

.anydb-ai-hints {
  text-align: center;
}

.anydb-hint-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.anydb-hint-chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 16px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  font-size: 0.78rem;
  cursor: default;
}

/* ── Auth Section ──────────────────────────────────────────────────────── */

.anydb-auth-status .btn-success {
  pointer-events: none;
  opacity: 0.8;
}

/* ── Small button variant ──────────────────────────────────────────────── */

.btn-xs {
  padding: 2px 8px;
  font-size: 0.72rem;
  line-height: 1.5;
  border-radius: 4px;
}

.badge-sm {
  font-size: 0.68rem;
  padding: 2px 5px;
}

/* ── Pagination gap ────────────────────────────────────────────────────── */

.anydb-pagination span {
  margin: 0 8px;
}

.anydb-pagination .btn {
  min-width: 32px;
}
