:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
}
button:hover { background: #eef1f5; }

button#runSqlBtn, button#addRowBtn, button[type="submit"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button#runSqlBtn:hover, button#addRowBtn:hover, button[type="submit"]:hover {
  background: var(--accent-hover);
}

.danger-btn { color: var(--danger); border-color: var(--danger); }
.danger-btn:hover { background: var(--danger); color: #fff; }

/* ---------- Login ---------- */
.login-body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b, #0f172a);
}
.login-card {
  background: var(--panel);
  padding: 32px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .subtitle { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.error-box {
  background: #fee2e2;
  color: var(--danger);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}

/* ---------- App shell ---------- */
.topbar {
  height: 48px;
  background: #111827;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.brand { font-weight: 600; }
.user-info { font-size: 13px; color: #cbd5e1; display: flex; align-items: center; gap: 10px; }
.link-btn {
  background: none;
  border: none;
  color: #93c5fd;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; background: none; }

.layout {
  display: flex;
  height: calc(100vh - 48px);
}

.sidebar {
  width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.icon-btn { padding: 2px 8px; line-height: 1; }

.tree { list-style: none; margin: 0; padding: 0; }
.tree li { }
.db-row, .table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.db-row:hover, .table-row:hover { background: #eef1f5; }
.db-row.active, .table-row.active { background: #dbeafe; color: var(--accent); }
.table-row { padding-left: 28px; color: var(--muted); }
.tree-actions { display: none; gap: 4px; }
.db-row:hover .tree-actions { display: flex; }
.tree-actions button { padding: 0 6px; font-size: 11px; }

.content {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin-top: 80px;
}

.hidden { display: none !important; }

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.tab-btn {
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
}
.tab-btn.active { border-bottom-color: var(--accent); color: var(--accent); }
.spacer { flex: 1; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.table-scroll { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--border); border-radius: 8px; }

table {
  border-collapse: collapse;
  width: 100%;
  background: var(--panel);
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
th { background: #f9fafb; position: sticky; top: 0; }
tbody tr:hover { background: #f9fafb; }

.row-actions button { padding: 2px 6px; font-size: 11px; margin-right: 4px; }

#sqlBox {
  width: 100%;
  min-height: 120px;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 13px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

#sqlResult { margin-top: 10px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-box {
  background: var(--panel);
  border-radius: 10px;
  padding: 20px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal-box h2 { margin-top: 0; font-size: 16px; }
.modal-box label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
  margin-bottom: 10px;
}
.modal-box input, .modal-box select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.col-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.col-row input[type="text"] { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }
