﻿/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ee;
  --border-strong: #d5d8e0;
  --text: #1c2333;
  --text-soft: #5b6577;
  --text-faint: #8a93a6;

  --accent: #5b5bd6;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(91, 91, 214, 0.09);

  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.12);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.1);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --blue: #2563eb;
  --blue-soft: rgba(37, 99, 235, 0.11);
  --slate: #64748b;
  --slate-soft: rgba(100, 116, 139, 0.12);

  --sidebar: #10162a;
  --sidebar-2: #171f3a;
  --sidebar-text: #aab3cc;
  --sidebar-hover: rgba(255, 255, 255, 0.06);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 22, 42, 0.05), 0 4px 16px rgba(16, 22, 42, 0.06);
  --shadow-lg: 0 10px 40px rgba(16, 22, 42, 0.22);
  --ring: 0 0 0 3px rgba(91, 91, 214, 0.22);
}

* { box-sizing: border-box; }
/* hidden attribute must always hide the element - prevents overlay blocking clicks */
[hidden] { display: none !important; }


html, body { height: 100%; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  overflow: hidden;
}

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

svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
  shape-rendering: geometricPrecision;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: 258px; min-width: 258px;
  background: linear-gradient(180deg, var(--sidebar), #0c1122);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 18px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(91, 91, 214, 0.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 15px; letter-spacing: 0.2px; }
.brand-text span { font-size: 11.5px; color: #7d86a3; }

.features { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  background: transparent; border: 0; border-radius: 9px;
  color: var(--sidebar-text); text-align: left; font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-btn:hover { background: var(--sidebar-hover); color: #fff; }
.nav-btn.active { background: var(--accent-soft); color: #fff; }
.nav-btn.active svg { color: var(--accent-2); }

.dbs-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.7px; color: #79819d;
}

.db-tree { flex: 1; display: flex; flex-direction: column; gap: 2px; padding-bottom: 12px; }
.db-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 10px;
  background: transparent; border: 0; border-radius: 9px;
  color: var(--sidebar-text); text-align: left; font-size: 13px;
  transition: background 0.12s ease, color 0.12s ease;
}
.db-item:hover { background: var(--sidebar-hover); color: #fff; }
.db-item.active { background: var(--accent-soft); color: #fff; }
.db-item .db-ico { color: var(--accent-2); }
.db-item .db-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-item .db-meta { margin-left: auto; font-size: 11px; color: #6d7590; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-dot.up { background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
.status-dot.down { background: #f87171; box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18); }

.sidebar-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 8px 2px; font-size: 12px; color: #7d86a3;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.pulse-dot.ok { background: #34d399; }
.pulse-dot.err { background: #f87171; }

.icon-btn {
  display: grid; place-items: center; width: 26px; height: 26px;
  border: 0; border-radius: 7px; background: transparent; color: #7d86a3;
}
.icon-btn:hover { background: var(--sidebar-hover); color: #fff; }
.icon-btn:disabled { opacity: 0.45; cursor: default; }
.icon-btn svg { width: 14px; height: 14px; }

/* ── Main ─────────────────────────────────────────────────── */
#main { flex: 1; overflow-y: auto; padding: 26px 30px 60px; }

.loader-wrap {
  height: 100%; display: grid; place-content: center; place-items: center; gap: 12px;
  color: var(--text-faint);
}
.loader {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page { max-width: 1180px; margin: 0 auto; animation: fadeUp 0.18s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.2px; }
.page-sub { margin: 4px 0 0; color: var(--text-soft); font-size: 13px; }

.crumb { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--text-soft); }
.crumb button { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; }
.crumb button:hover { text-decoration: underline; }
.crumb .sep { color: var(--text-faint); }
.crumb .here { color: var(--text); font-weight: 600; }

/* ── Stat hero ────────────────────────────────────────────── */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.5px; }
.stat .v.green { color: var(--green); }
.stat .v.red { color: var(--red); }
.stat .v.accent { color: var(--accent); }

/* ── Cards & grids ────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.db-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.db-card {
  position: relative; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 16px 14px; box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.db-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.db-card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.db-card .db-ico {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.db-card h4 { margin: 0; font-size: 15px; }
.db-card .sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.db-card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; font-size: 12px; color: var(--text-soft); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
}
.pill.up { background: var(--green-soft); color: var(--green); }
.pill.down { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.slate { background: var(--slate-soft); color: var(--slate); }
.pill.violet { background: var(--accent-soft); color: var(--accent); }

/* ── Toolbar ──────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .count { font-size: 12.5px; color: var(--text-faint); }

.input, .select {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px;
  padding: 8px 12px; color: var(--text); outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: var(--ring); }
.input.wide { min-width: 240px; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-faint); }
.search-box .input { padding-left: 32px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}
.btn:hover { border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0; color: #fff; box-shadow: 0 3px 10px rgba(91, 91, 214, 0.3);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { border-color: transparent; background: var(--red-soft); color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity 0.12s ease; }
tr:hover .row-actions, .row-actions.visible { opacity: 1; }

/* ── Tables ───────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.tbl { border-collapse: collapse; width: 100%; min-width: 640px; }
.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-faint); padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  vertical-align: middle; font-size: 13px;
}
.tbl tbody tr { transition: background 0.1s ease; }
.tbl tbody tr:hover { background: #f8f8fd; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl .muted { color: var(--text-faint); }
.cell-null { color: var(--text-faint); font-style: italic; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 13px; letter-spacing: 0.5px;
}
.id-cell { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: 12px; }
.id-cell .clip { color: var(--text-faint); cursor: pointer; }
.id-cell .clip:hover { color: var(--accent); }
.trunc { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-cell { display: flex; align-items: center; gap: 11px; min-width: 200px; }
.user-cell .u-name { font-weight: 600; color: var(--text); }
.user-cell .u-email { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 7px; font-size: 11px; font-weight: 600;
  background: var(--slate-soft); color: var(--slate); white-space: nowrap;
}
.badge.yes { background: var(--green-soft); color: var(--green); }
.badge.no { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.violet { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }

/* ── Table browser ────────────────────────────────────────── */
.browse-wrap { overflow: auto; max-height: calc(100vh - 250px); border-radius: var(--radius-sm); }
.grid-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.json-cell { font-family: monospace; font-size: 11.5px; color: var(--blue); }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 12px; color: var(--text-soft); font-size: 13px; }
.pager .pg-btns { display: flex; gap: 6px; }
.pager .total { font-weight: 600; color: var(--text); }

/* ── List (tables list under a db) ────────────────────────── */
.tbl-list { display: flex; flex-direction: column; }
.tbl-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); font-size: 13.5px;
  transition: background 0.1s ease;
}
.tbl-row:last-child { border-bottom: 0; }
.tbl-row:hover { background: #f8f8fd; }
.tbl-row .tbl-ico { color: var(--accent); }
.tbl-row .est { margin-left: auto; color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── Book covers ──────────────────────────────────────────── */
.cover {
  width: 40px; height: 52px; border-radius: 8px; flex: none;
  display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 14px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
}
.book-cell { display: flex; align-items: center; gap: 12px; min-width: 210px; }
.book-cell .b-name { font-weight: 600; }
.book-cell .b-slug { font-size: 12px; color: var(--text-faint); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }

/* ── Section ──────────────────────────────────────────────── */
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-faint); margin: 0 0 10px;
}
.subtitle { color: var(--text-soft); font-size: 13px; }

/* ── Modals ───────────────────────────────────────────────── */
.modal-root {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgba(12, 17, 34, 0.45); backdrop-filter: blur(4px);
  animation: fadeIn 0.16s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 440px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 22px; animation: popIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes popIn { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal .modal-sub { color: var(--text-soft); font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.modal .modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.field .hint { font-size: 11.5px; color: var(--text-faint); }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }
.modal .user-preview { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.modal .user-preview .u-name { font-weight: 600; }
.modal .user-preview .u-email { font-size: 12px; color: var(--text-faint); }

/* ── Toasts ───────────────────────────────────────────────── */
.toast-root {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 9px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 11px; padding: 11px 15px; box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 500; max-width: 360px;
  animation: toastIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateX(20px); transition: all 0.25s ease; }

/* ── Empty / error states ─────────────────────────────────── */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text-faint);
}
.empty svg { width: 42px; height: 42px; stroke-width: 1.5; opacity: 0.5; margin-bottom: 12px; }
.empty h3 { margin: 8px 0 4px; color: var(--text-soft); }
.error-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--red-soft); color: var(--red); border: 1px solid rgba(220,38,38,0.18);
  padding: 12px 16px; border-radius: 11px; margin-bottom: 16px; font-size: 13px;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cdd1dc; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b4b9c8; background-clip: content-box; }

@media (max-width: 900px) {
  #sidebar { width: 218px; min-width: 218px; }
  #main { padding: 20px 16px 50px; }
  body { overflow: auto; }
}

/* ── SQL Query console ──────────────────────────────────── */
.sql-page { max-width: 1280px; }
.sql-card { padding: 0; }
.sql-editor-row { display: flex; flex-direction: column; }
.sql-input {
  width: 100%; min-height: 120px; max-height: 320px;
  resize: vertical; padding: 14px 16px; margin: 0;
  background: var(--surface-2); border: 0; border-bottom: 1px solid var(--border);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", Consolas, "Courier New", monospace;
  font-size: 13px; line-height: 1.65; color: var(--text);
  outline: none; tab-size: 2;
}
.sql-input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.sql-editor-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface-2); border-top: 1px solid var(--border);
}
.sql-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding: 0 2px; font-size: 12.5px; color: var(--text-soft); font-weight: 500;
}
.sql-wrap { margin-bottom: 16px; }
.sql-wrap .tbl thead th {
  position: sticky; top: 0; background: var(--surface-2);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.col-type {
  display: inline-block; margin-left: 6px; font-weight: 400; font-size: 11px;
  color: var(--text-faint); vertical-align: middle;
}
.sql-db { min-width: 200px; }
.json-cell {
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 12px; color: var(--text-soft);
}
.cell-null { color: var(--text-faint); font-style: italic; }

/* ── Redis viewer ─────────────────────────────────────────── */
.redis-page { max-width: 1280px; }
.redis-cols {
  display: grid; grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 16px; margin-bottom: 8px;
}
.redis-col { min-width: 0; }
.redis-col .section-label { margin-top: 4px; }
.kvs { display: flex; flex-direction: column; padding: 6px 0; margin-bottom: 14px; }
.kv {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; font-size: 13px; border-bottom: 1px solid var(--border);
}
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--text-soft); }
.kv strong { color: var(--text); font-variant-numeric: tabular-nums; }
.log-card {
  max-height: 520px; overflow-y: auto;
  border-radius: var(--radius-sm); padding: 6px 0;
}
.log-card.dark {
  background: #0d1117; border-color: #1f2633;
}
.log-line {
  display: flex; align-items: baseline; gap: 10px;
  padding: 5px 14px; font-size: 12px; line-height: 1.55;
  border-bottom: 1px solid rgba(230,232,238,0.5);
  font-family: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.log-card.dark .log-line {
  border-bottom: 1px solid rgba(255,255,255,0.06); color: #c9d1d9;
}
.log-card.dark .log-line.muted { color: #6e7681; }
.log-card.dark .log-line.err { color: #f85149; }
.log-line .log-time { color: var(--text-faint); white-space: nowrap; font-size: 11px; }
.log-line .log-dur { color: var(--amber); font-weight: 600; white-space: nowrap; }
.log-line .log-msg { color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-line .log-text { color: #c9d1d9; }
.log-line code { color: var(--accent); font-family: inherit; }
@media (max-width: 1100px) {
  .redis-cols { grid-template-columns: 1fr; }
}