@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Space+Grotesk:wght@400;600&display=swap');

:root {
  --bg: #0b1020;
  --panel: #151b2d;
  --panel-glow: rgba(96, 166, 255, 0.18);
  --text: #eef2ff;
  --muted: #a2adc9;
  --primary: #47d7b2;
  --accent: #ffb347;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 20px 50px rgba(7, 12, 26, 0.65);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  min-height: 100vh;
  position: relative;
  padding: 28px 28px 40px;
}

.page-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(71, 215, 178, 0.18), transparent 55%),
              radial-gradient(circle at 80% 0%, rgba(255, 179, 71, 0.2), transparent 45%),
              radial-gradient(circle at 70% 80%, rgba(96, 166, 255, 0.2), transparent 55%);
  opacity: 0.9;
  pointer-events: none;
}

.site-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #47d7b2, #60a6ff);
  color: #0b1020;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  display: grid;
  place-items: center;
  letter-spacing: 0.1em;
}

.brand-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
}

.brand-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
}

.nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-link {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
}

.nav-link.active {
  color: var(--text);
  border-color: var(--border);
  background: rgba(71, 215, 178, 0.12);
}

.nav-form {
  margin: 0;
}

.content {
  position: relative;
  z-index: 1;
  margin-top: 28px;
}

.grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.panel {
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.panel.warning {
  border-color: rgba(255, 107, 107, 0.4);
  box-shadow: 0 20px 50px rgba(255, 107, 107, 0.15);
}

.panel-header h1,
.panel-header h2 {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', sans-serif;
}

.panel-header p {
  margin: 0;
  color: var(--muted);
}

.table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table-wrap th,
.table-wrap td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.table-wrap th {
  color: var(--muted);
  font-weight: 600;
}

.link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select {
  background: rgba(11, 16, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

button.primary {
  background: linear-gradient(135deg, #47d7b2, #60a6ff);
  color: #0b1020;
}

button.danger {
  background: linear-gradient(135deg, #ff6b6b, #ffb347);
  color: #1c0b0b;
}

button.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

button.ghost.danger {
  color: var(--danger);
}

.flash {
  margin: 16px 0 0;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(71, 215, 178, 0.12);
  border: 1px solid rgba(71, 215, 178, 0.3);
}

.flash.error {
  background: rgba(255, 107, 107, 0.15);
  border-color: rgba(255, 107, 107, 0.35);
}

.flash.success {
  background: rgba(71, 215, 178, 0.15);
  border-color: rgba(71, 215, 178, 0.35);
}

.checks {
  display: grid;
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.info-card {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.info-card .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.info-card .value {
  font-size: 1rem;
  font-weight: 600;
}

.pager {
  margin-top: 16px;
  display: flex;
  gap: 12px;
}

.login {
  display: grid;
  place-items: center;
  min-height: 70vh;
}

.site-footer {
  margin-top: 32px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
  position: relative;
  z-index: 1;
}

/* Query Editor Styles */
.query-section {
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr 300px;
}

.query-section > .panel:first-child,
.query-section > .panel:nth-child(2) {
  grid-column: 1;
}

.query-section > .panel:last-child {
  grid-column: 2;
  grid-row: 1 / 3;
}

.query-panel {
  min-height: 300px;
}

.query-editor-wrap {
  margin-top: 16px;
}

.query-editor {
  width: 100%;
  min-height: 200px;
  background: rgba(11, 16, 32, 0.8);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  color: var(--text);
  font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}

.query-actions {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.query-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: auto;
}

.results-panel {
  min-height: 200px;
}

.results-wrap {
  margin-top: 16px;
  max-height: 400px;
  overflow: auto;
}

.results-empty,
.results-error,
.results-success {
  padding: 24px;
  text-align: center;
  border-radius: 12px;
}

.results-empty {
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.results-error {
  background: rgba(255, 107, 107, 0.15);
  color: var(--danger);
  text-align: left;
  font-family: monospace;
  white-space: pre-wrap;
}

.results-success {
  background: rgba(71, 215, 178, 0.15);
  color: var(--primary);
}

.table-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 500px;
  overflow-y: auto;
}

.table-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.table-item:hover {
  background: rgba(71, 215, 178, 0.1);
}

.table-schema {
  color: var(--muted);
}

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

.null {
  color: var(--muted);
  font-style: italic;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  font-weight: 500;
}

.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.tab.active {
  color: var(--primary);
  background: rgba(71, 215, 178, 0.1);
}

.tab-content {
  display: none;
  margin-top: 16px;
}

.tab-content.active {
  display: block;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.stat-card {
  background: rgba(11, 16, 32, 0.5);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
  font-family: 'Space Grotesk', sans-serif;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-success {
  background: rgba(71, 215, 178, 0.2);
  color: var(--primary);
}

.badge-warning {
  background: rgba(255, 179, 71, 0.2);
  color: var(--accent);
}

.badge-muted {
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
}

.badge-danger {
  background: rgba(255, 107, 107, 0.2);
  color: var(--danger);
}

/* Query cell */
.query-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

/* Full width panel */
.full-width {
  grid-column: 1 / -1;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 16, 32, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--panel);
  border-radius: 20px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
}

/* Data controls */
.data-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.data-info {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Inline form */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.inline-form label {
  flex: 1;
  min-width: 150px;
}

.inline-form button {
  align-self: flex-end;
}

/* Panel section */
.panel-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.panel-section h3 {
  margin: 0 0 16px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
}

/* Small button */
button.small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* Danger actions */
.danger-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.inline {
  display: inline-block;
}

/* Column builder */
.columns-section {
  margin-top: 16px;
}

.columns-section h3 {
  margin: 0 0 12px;
  font-family: 'Space Grotesk', sans-serif;
}

.columns-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.column-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px;
  background: rgba(11, 16, 32, 0.5);
  border-radius: 8px;
}

.column-row input[type="text"] {
  width: 150px;
}

.column-row select {
  width: 140px;
}

.column-row .small-input {
  width: 100px;
}

.check.compact {
  flex-direction: row;
  gap: 4px;
  min-width: auto;
}

.check.compact span {
  font-size: 0.8rem;
}

/* Form row */
.form-row {
  display: flex;
  gap: 16px;
}

.form-row label {
  flex: 1;
}

/* SQL Preview */
.sql-preview {
  background: rgba(11, 16, 32, 0.8);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
  font-family: 'Fira Code', 'Monaco', monospace;
  font-size: 0.9rem;
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--primary);
}

/* Template buttons */
.template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

/* Row actions */
.row-actions {
  white-space: nowrap;
}

/* Code styling */
code {
  background: rgba(71, 215, 178, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', 'Monaco', monospace;
  font-size: 0.9em;
}

/* Muted text */
.muted {
  color: var(--muted);
}

/* Quick actions / DB actions */
.quick-actions,
.db-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-actions {
  margin-top: 16px;
}

.quick-actions a,
.db-actions a {
  text-decoration: none;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
}

.db-actions a.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

.db-actions a.primary {
  background: linear-gradient(135deg, #47d7b2, #60a6ff);
  color: #0b1020;
}

/* Button as link */
a.ghost,
a.primary {
  display: inline-block;
}

/* Textarea */
textarea {
  background: rgba(11, 16, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  width: 100%;
}

/* File input */
input[type="file"] {
  background: rgba(11, 16, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  width: 100%;
}

input[type="file"]::file-selector-button {
  background: rgba(71, 215, 178, 0.2);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--primary);
  cursor: pointer;
  margin-right: 12px;
}

@media (max-width: 720px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .nav {
    flex-wrap: wrap;
  }

  .site-footer {
    flex-direction: column;
    gap: 8px;
  }

  .query-section {
    grid-template-columns: 1fr;
  }

  .query-section > .panel:last-child {
    grid-column: 1;
    grid-row: auto;
  }

  .column-row {
    flex-direction: column;
    align-items: stretch;
  }

  .column-row input,
  .column-row select {
    width: 100%;
  }
}
