/* db_rust — white/light theme inspired by Vercel/Next.js */
:root {
  --bg: #ffffff;
  --panel: #f8fafc;
  --panel-hover: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --brand: #3b82f6;
  --brand-hover: #2563eb;
  --ok: #22c55e;
  --err: #ef4444;
  --ring: rgba(59, 130, 246, 0.5);
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
}

/* ---------- Layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.navbar {
  height: 64px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.brand .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.2);
}

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

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.875rem;
  color: var(--muted);
}

.dot-on {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.3);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: all 0.2s;
}
.btn-ghost:hover {
  background: var(--panel-hover);
  border-color: var(--muted);
}

.btn-brand {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s;
}
.btn-brand:hover { background: var(--brand-hover); }
.btn-brand:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 40px 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

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

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.page-sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.card-body { padding: 24px; }

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.card-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

/* ---------- Path bar ---------- */
.path-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 24px;
}
.path-seg { color: var(--text); font-weight: 600; cursor: pointer; }
.path-seg:hover { color: var(--brand); text-decoration: underline; }
.path-sep { color: var(--muted); }

/* ---------- Query form ---------- */
.query-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 24px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--ring);
}
.input::placeholder { color: var(--muted); }

.row-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  color: var(--text);
}

tr:nth-child(even) td { background: rgba(30,41,59,0.05); }
tr:hover td { background: var(--panel-hover); }

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

.cell-val {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre-wrap;
}

.cell-key {
  color: var(--brand);
  font-weight: 500;
}

/* ---------- Empty / loading ---------- */
.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--muted);
}

.empty h3 { color: var(--text); margin-bottom: 8px; font-size: 1.1rem; }

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 24px;
  color: var(--muted);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Alert ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); color: var(--err); }
.alert-ok { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.2); color: var(--ok); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.05), 0 10px 10px -5px rgba(0,0,0,0.02);
  text-align: center;
}

.login-card .logo {
  width: 36px; height: 32px;
  margin: 0 auto 24px;
  display: block;
}

.login-card h1.title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.login-card p.sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

#gis-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

#error.error {
  color: var(--err);
  font-size: 0.85rem;
  min-height: 20px;
  margin-bottom: 12px;
}

#roleHint.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 20px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.divider::before, .divider::after { content: ""; flex: 1; border-bottom: 1px solid var(--border); }

.error-text {
  color: var(--err);
  font-size: 0.85rem;
  margin-top: 10px;
  min-height: 20px;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .main { padding: 24px 16px; }
  .query-form { grid-template-columns: 1fr; }
  .navbar { padding: 0 16px; }
}

/* ---------- JSON view ---------- */
.json-wrap {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
}
.json-wrap pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
}
.json-wrap code {
  color: var(--text);
}
