:root {
  --bg: #0f1412;
  --bg-elev: #171e1b;
  --bg-panel: #1c2420;
  --line: #2a3530;
  --text: #e7eee9;
  --muted: #8fa099;
  --accent: #3dba8a;
  --accent-dim: #2a7f5e;
  --danger: #e07070;
  --warn: #d4b15a;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a3a2e 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #243028 0%, transparent 50%),
    var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0.5rem 0 0; }
code, .mono { font-family: var(--mono); }

.brand {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.login-gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem 1.4rem 1.3rem;
}
.login-panel h1 {
  margin: 0.35rem 0 0.4rem;
  font-size: 1.45rem;
  font-weight: 600;
}
.login-panel label {
  display: block;
  margin: 1rem 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.login-panel input,
.sidebar select,
.sidebar input,
#max-rows,
#sql-editor {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
}
.login-panel button,
button.primary,
button.ghost {
  margin-top: 1rem;
  border: 0;
  border-radius: 8px;
  padding: 0.65rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.login-panel button,
button.primary {
  background: var(--accent);
  color: #052116;
}
button.ghost {
  margin-top: 0;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "top top"
    "side main";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 18, 0.85);
  backdrop-filter: blur(8px);
}
.brand-block { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.sep { color: var(--line); }
.badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}
.top-actions { display: flex; align-items: center; gap: 0.5rem; }
.status-pill {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.status-pill.ok { color: var(--accent); border-color: var(--accent-dim); }
.status-pill.bad { color: var(--danger); border-color: #6a3030; }

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.9rem;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  min-height: 0;
}
.side-section.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-section label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.side-head input { width: 55%; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.table-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  flex: 1;
}
.table-list li button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}
.table-list li:last-child button { border-bottom: 0; }
.table-list li button:hover,
.table-list li button.active {
  background: #223029;
  color: var(--accent);
}

.main {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem 1rem;
}
.tabs { display: flex; gap: 0.35rem; margin-bottom: 0.75rem; }
.tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  cursor: pointer;
}
.tab.active {
  color: var(--text);
  border-color: var(--accent-dim);
  background: #1b2b24;
}
.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
}
.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.panel-toolbar h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.toolbar-right { display: flex; align-items: center; gap: 0.65rem; }
.inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}
#max-rows { width: 5.5rem; padding: 0.4rem 0.5rem; }
#sql-editor {
  min-height: 160px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.45;
}
.meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.1em;
}
.result-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
table.result {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-family: var(--mono);
  font-size: 0.78rem;
}
table.result th,
table.result td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.4rem 0.55rem;
  text-align: left;
  vertical-align: top;
  white-space: pre-wrap;
  max-width: 420px;
}
table.result th {
  position: sticky;
  top: 0;
  background: #1a2420;
  color: var(--accent);
  font-weight: 600;
  z-index: 1;
}
table.result tr:hover td { background: #1a2420; }
.empty {
  padding: 1.2rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "top"
      "side"
      "main";
    height: auto;
    min-height: 100%;
  }
  .sidebar { max-height: 280px; }
  .table-list { max-height: 180px; }
}
