* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; padding: 1rem; background: #f5f5f5; }
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: #fff; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); max-width: 360px; width: 100%; }
.login-box h1 { margin-top: 0; }
.login-box label { display: block; margin-bottom: 1rem; }
.login-box input { width: 100%; padding: 0.5rem; margin-top: 0.25rem; }
.login-box button { width: 100%; padding: 0.6rem; background: #2563eb; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.login-box .error { color: #b91c1c; margin-bottom: 1rem; }
nav { background: #1e293b; color: #fff; padding: 0.75rem 1rem; margin: -1rem -1rem 1rem -1rem; display: flex; gap: 1.5rem; align-items: center; }
nav a { color: #e2e8f0; text-decoration: none; }
nav a:hover { color: #fff; }
nav .user { margin-left: auto; color: #94a3b8; }
.container { max-width: 1200px; margin: 0 auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid #e2e8f0; }
th { background: #f8fafc; font-weight: 600; }
.btn { display: inline-block; padding: 0.5rem 1rem; background: #2563eb; color: #fff; text-decoration: none; border-radius: 6px; border: none; cursor: pointer; font-size: 1rem; }
.btn:hover { background: #1d4ed8; }
.btn-secondary { background: #64748b; }
.btn-danger { background: #b91c1c; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.875rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.5rem; border: 1px solid #cbd5e1; border-radius: 6px; }
.form-group textarea { min-height: 120px; font-family: monospace; }
/* Query page: left sidebar + main editor + results at bottom */
.query-page {
  display: flex;
  gap: 0;
  margin: -1rem -1rem 0 -1rem;
  height: calc(100vh - 52px);
  background: #fff;
  overflow: hidden;
}
.query-sidebar {
  width: 280px;
  min-width: 280px;
  flex-shrink: 0;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-section { margin-bottom: 1.25rem; }
.sidebar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 0.5rem;
  display: block;
}
.sidebar-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 0.9rem;
}
.schema-placeholder {
  font-size: 0.85rem;
  color: #94a3b8;
  padding: 0.5rem 0;
}
.schema-content { margin-top: 0.25rem; }
.schema-table-name {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  font-size: 0.9rem;
  color: #1e293b;
  margin-bottom: 0.5rem;
  padding: 0.25rem 0;
}
.schema-columns {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
}
.schema-columns li {
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  color: #475569;
  border-bottom: 1px solid #f1f5f9;
}
.schema-columns li:hover { background: #f1f5f9; }
.schema-columns li .col-type { color: #94a3b8; font-size: 0.8em; margin-left: 0.35rem; }
.saved-queries-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.saved-queries-list li { margin-bottom: 0.25rem; }
.saved-queries-list .btn-link {
  background: none;
  border: none;
  padding: 0.35rem 0;
  color: #2563eb;
  cursor: pointer;
  font-size: 0.9rem;
  text-align: left;
  width: 100%;
}
.saved-queries-list .btn-link:hover { text-decoration: underline; }
.query-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 1rem;
  overflow: hidden;
}
.query-toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.query-hint { font-size: 0.85rem; color: #64748b; }
.editor-wrap {
  flex: 1;
  min-height: 280px;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
}
.sql-editor {
  width: 100%;
  height: 100%;
  flex: 1;
  min-height: 280px;
  padding: 1rem;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  resize: vertical;
  tab-size: 2;
  display: block;
}
.sql-editor:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.sql-autocomplete-dropdown {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 260px;
  overflow-y: auto;
  padding: 0.25rem 0;
}
.sql-autocomplete-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
}
.sql-autocomplete-item:hover,
.sql-autocomplete-item.active {
  background: #f1f5f9;
}
.sql-autocomplete-item .sql-ac-label {
  font-family: ui-monospace, monospace;
  font-weight: 500;
}
.sql-autocomplete-item .sql-ac-detail {
  font-size: 0.8rem;
  color: #64748b;
}
.results-wrap {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  flex: 0 0 auto;
  max-height: 40vh;
  min-height: 120px;
  display: flex;
  flex-direction: column;
}
.results-header {
  padding: 0.5rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#results-count { font-weight: normal; color: #64748b; font-size: 0.85rem; }
.results-body {
  overflow: auto;
  flex: 1;
  min-height: 80px;
}
.results-loading, .results-empty { padding: 1rem; color: #64748b; }
.schema-columns .schema-error { color: #b91c1c; }
.results-table { overflow-x: auto; }
.results-table table { margin: 0; }
.query-toolbar select { padding: 0.5rem; min-width: 200px; }
.message { padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; }
.message.error { background: #fef2f2; color: #b91c1c; }
.message.success { background: #f0fdf4; color: #166534; }
h1, h2 { margin-top: 0; }
