/* ==========================================================================
   MySQL Viewer - Modern Sleek Stylesheet
   ========================================================================== */

:root {
  /* Color Palette - Dark Theme (Default) */
  --bg-app: #0b0f19;
  --bg-sidebar: #0f172a;
  --bg-card: #131d33;
  --bg-card-hover: #1e293b;
  --bg-input: #0b1120;
  --bg-modal: #111827;
  
  --border-color: #1e293b;
  --border-subtle: #192338;
  --border-focus: #3b82f6;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-info: #06b6d4;

  --badge-pri: rgba(239, 68, 68, 0.15);
  --badge-pri-text: #f87171;
  --badge-uni: rgba(59, 130, 246, 0.15);
  --badge-uni-text: #60a5fa;
  --badge-mul: rgba(16, 185, 129, 0.15);
  --badge-mul-text: #34d399;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.25);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Monaco, Consolas, monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f8fafc;
  --bg-modal: #ffffff;

  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;
  --border-focus: #3b82f6;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --accent-gradient: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
  --accent-success: #059669;
  --accent-warning: #d97706;
  --accent-danger: #dc2626;
  --accent-info: #0891b2;

  --badge-pri: rgba(220, 38, 38, 0.1);
  --badge-pri-text: #b91c1c;
  --badge-uni: rgba(37, 99, 235, 0.1);
  --badge-uni-text: #1d4ed8;
  --badge-mul: rgba(5, 150, 105, 0.1);
  --badge-mul-text: #047857;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* App Container */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  width: 290px;
  min-width: 290px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  user-select: none;
  z-index: 10;
  transition: width var(--transition-normal);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  text-decoration: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.brand-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  border-radius: var(--radius-full);
}

.sidebar-search-box {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper i {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 12px 7px 32px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.search-input:focus {
  border-color: var(--border-focus);
}

.sidebar-section-title {
  padding: 12px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
}

.db-group {
  margin-bottom: 6px;
}

.db-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.db-item:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-primary);
}

.db-item.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  font-weight: 600;
}

.db-title {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.table-list {
  padding-left: 18px;
  margin-top: 2px;
  display: none;
}

.table-list.expanded {
  display: block;
}

.table-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12.5px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.table-item:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-primary);
}

.table-item.active {
  background-color: var(--accent-primary);
  color: #ffffff;
  font-weight: 500;
}

.table-item.active .table-rows-count {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.table-title {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-rows-count {
  font-size: 10.5px;
  padding: 1px 5px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-sidebar);
}

.server-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent-success);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-success);
}

/* ==========================================================================
   Main Content Area
   ========================================================================== */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-app);
}

/* Header & Top Navbar */
.top-navbar {
  height: 56px;
  min-height: 56px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
}

.breadcrumb-db {
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.breadcrumb-sep {
  color: var(--text-muted);
}

.breadcrumb-table {
  font-weight: 500;
  color: var(--accent-primary);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  outline: none;
  text-decoration: none;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

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

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  opacity: 0.92;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.35);
}

.btn-secondary {
  background-color: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background-color: var(--bg-card-hover);
}

.btn-outline-danger {
  background: transparent;
  border-color: var(--accent-danger);
  color: var(--accent-danger);
}
.btn-outline-danger:hover {
  background: var(--accent-danger);
  color: #ffffff;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* View Tabs Bar */
.tabs-bar {
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  background: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  position: relative;
  transition: color var(--transition-fast);
}

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

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

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-primary);
  border-radius: 2px 2px 0 0;
}

/* Content Container */
.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.tab-panel {
  display: none;
  height: 100%;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   Data Browser Panel & Toolbar
   ========================================================================== */
.data-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-input {
  width: 260px;
  padding: 6px 12px 6px 30px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.filter-input:focus {
  border-color: var(--border-focus);
}

.data-stats-pill {
  font-size: 12px;
  color: var(--text-muted);
}

/* Table Container & Interactive Grid */
.grid-card {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 250px;
  box-shadow: var(--shadow-sm);
}

.table-responsive {
  flex: 1;
  overflow: auto;
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.data-table th {
  background: var(--bg-sidebar);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
}
.data-table th.sortable:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

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

.data-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tbody tr {
  transition: background-color var(--transition-fast);
}

.data-table tbody tr:hover {
  background-color: var(--bg-card-hover);
}

.null-val {
  color: var(--text-muted);
  font-style: italic;
  font-size: 11.5px;
}

.cell-clickable {
  cursor: pointer;
}
.cell-clickable:hover {
  text-decoration: underline;
  color: var(--accent-primary);
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-color);
  font-size: 12.5px;
  color: var(--text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.select-per-page {
  padding: 4px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
}

/* ==========================================================================
   Table Structure & Schema View
   ========================================================================== */
.schema-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.schema-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.badge-pri { background: var(--badge-pri); color: var(--badge-pri-text); }
.badge-uni { background: var(--badge-uni); color: var(--badge-uni-text); }
.badge-mul { background: var(--badge-mul); color: var(--badge-mul-text); }
.badge-default { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }

.code-block-wrapper {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.code-block {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: #38bdf8;
  white-space: pre-wrap;
  word-break: break-word;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* ==========================================================================
   SQL Query Console Panel
   ========================================================================== */
.sql-editor-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.sql-snippets {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.snippet-tag {
  padding: 4px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 11.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.snippet-tag:hover {
  background: var(--bg-card-hover);
  color: var(--accent-primary);
  border-color: var(--border-focus);
}

.sql-textarea {
  width: 100%;
  height: 160px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #38bdf8;
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 12px 14px;
  outline: none;
  resize: vertical;
  line-height: 1.5;
}

.sql-textarea:focus {
  border-color: var(--border-focus);
}

.sql-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sql-tip {
  font-size: 12px;
  color: var(--text-muted);
}

.query-result-card {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

/* ==========================================================================
   Server Overview & Metrics Panel
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.metric-icon.blue { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.metric-icon.green { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.metric-icon.purple { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.metric-icon.amber { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

/* ==========================================================================
   Modal Dialog & Toast Notifications
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-dialog {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 13.5px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 110;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 13px;
  min-width: 260px;
  animation: toastSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast.success { border-left: 4px solid var(--accent-success); }
.toast.error { border-left: 4px solid var(--accent-danger); }
.toast.info { border-left: 4px solid var(--accent-info); }

/* Loading Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 10px;
}

.empty-state i {
  font-size: 42px;
  opacity: 0.5;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -290px;
  }
  .sidebar.mobile-open {
    left: 0;
  }
}
