:root {
  --ink: #14232c;
  --ink-soft: #3d5360;
  --paper: #f3efe6;
  --paper-2: #fffdf8;
  --line: #d7cfc0;
  --teal: #1f6f64;
  --teal-dark: #15564e;
  --amber: #c4841d;
  --danger: #a33b2b;
  --danger-bg: #f8e6e2;
  --ok-bg: #e4f0ea;
  --shadow: 0 18px 50px rgba(20, 35, 44, 0.12);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

body {
  background-image:
    radial-gradient(circle at 12% 10%, rgba(31, 111, 100, 0.08), transparent 32%),
    radial-gradient(circle at 88% 0%, rgba(196, 132, 29, 0.08), transparent 28%);
}

button, input, select, textarea { font: inherit; }

button { cursor: pointer; }

#app { min-height: 100vh; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.login-card {
  width: min(460px, 100%);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 34px 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #1b3a4b;
  color: #e8a838;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 26px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}

.field input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 111, 100, 0.15);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 12px;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 600;
  background: var(--teal);
  color: #fff;
}

.btn:hover { background: var(--teal-dark); }
.btn:disabled { opacity: 0.65; cursor: wait; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost:hover { background: #efe9dc; }

.btn-block { width: 100%; margin-top: 8px; }

[hidden] { display: none !important; }

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
}

/* ---------- Shell ---------- */

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: #1b3a4b;
  color: #f4efe6;
}

.topbar .brand h1 { font-size: 20px; color: #fff; }

.conn-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.pill {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 5px 10px;
  font-family: var(--mono);
}

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

.top-actions .btn { padding: 8px 12px; font-size: 13px; }
.top-actions .btn-ghost { color: #f4efe6; border-color: rgba(255,255,255,0.2); }
.top-actions .btn-ghost:hover { background: rgba(255,255,255,0.08); }

/* ---------- Databases ---------- */

.page {
  padding: 28px 22px 40px;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h2 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 30px;
}

.muted { color: var(--ink-soft); }

.db-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.db-card {
  text-align: left;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(20, 35, 44, 0.05);
}

.db-card:hover { border-color: var(--teal); transform: translateY(-1px); }

.db-card.system { opacity: 0.78; }

.db-name {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 15px;
  margin-bottom: 10px;
  word-break: break-all;
}

.db-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-soft);
}

.section-label {
  margin: 28px 0 12px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

/* ---------- Explorer ---------- */

.explorer {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 60px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #efe9dc;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 14px 14px 8px;
}

.sidebar-head input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.table-list {
  overflow: auto;
  padding: 6px 8px 16px;
}

.table-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.table-item:hover { background: rgba(27, 58, 75, 0.07); }
.table-item.active { background: #1b3a4b; color: #fff; }

.table-item .name {
  font-family: var(--mono);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 11px;
  opacity: 0.75;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}

.tab {
  border: 0;
  background: transparent;
  padding: 10px 14px;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-weight: 600;
}

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--amber);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
}

.toolbar input, .toolbar select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.grow { flex: 1; min-width: 180px; }

.table-wrap {
  overflow: auto;
  padding: 0 16px 24px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper-2);
  font-size: 13px;
}

table.data th, table.data td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.data th {
  background: #e7efe9;
  position: sticky;
  top: 0;
  font-weight: 600;
}

table.data th.sortable { cursor: pointer; }
table.data tr:nth-child(even) td { background: #faf7f0; }
table.data .null { color: #9aa7af; font-style: italic; }

.sql-box {
  width: 100%;
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
}

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-soft);
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

@media (max-width: 800px) {
  .explorer { grid-template-columns: 1fr; }
  .sidebar { max-height: 240px; border-right: 0; border-bottom: 1px solid var(--line); }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
}
