:root {
  --bg: #0b0c10;
  --surface: #12141a;
  --surface-2: #1a1d27;
  --surface-3: #212433;
  --border: #252836;
  --border-2: #2e3346;
  --text: #e2e5f0;
  --text-muted: #7b8194;
  --text-dim: #4a5066;
  --primary: #6366f1;
  --primary-hover: #4f52d8;
  --primary-glow: rgba(99,102,241,.25);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #38bdf8;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,.45);
  --transition: .15s ease;
  --sidebar-w: 220px;
}

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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem;   font-weight: 600; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

/* ── Login ──────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at 60% 30%, rgba(99,102,241,.12) 0%, transparent 65%),
              radial-gradient(ellipse at 20% 80%, rgba(139,92,246,.08) 0%, transparent 60%),
              var(--bg);
}

.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(99,102,241,.08);
  animation: slideUp .3s ease;
}

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

.login-logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}

.login-logo-text { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.login-logo-text span { color: var(--text-muted); font-weight: 400; font-size: .85rem; display: block; }

.login-card h2 { margin-bottom: 4px; }
.login-card p  { color: var(--text-muted); margin-bottom: 28px; font-size: .875rem; }

.login-error {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: .85rem;
  display: none;
}

/* ── Forms ──────────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; letter-spacing: .03em; }

input[type=text], input[type=password], input[type=email], input[type=number], input[type=url], select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
input::placeholder { color: var(--text-dim); }
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
select option { background: var(--surface-2); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  font-family: inherit;
  line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 0 0 3px var(--primary-glow); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.25); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-success { background: rgba(34,197,94,.15); color: #86efac; border: 1px solid rgba(34,197,94,.25); }
.btn-success:hover { background: rgba(34,197,94,.25); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-icon { padding: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: .95rem; }

/* ── App Layout ─────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-logo-label { font-size: .95rem; font-weight: 700; }
.sidebar-logo-sub   { font-size: .7rem; color: var(--text-muted); margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }

.nav-section-label {
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 8px 8px 4px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: .875rem;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.nav-item:hover  { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); font-weight: 500; }
.nav-item.active .nav-icon { color: var(--primary); }
.nav-icon { flex-shrink: 0; display: inline-flex; }
.svg-icon { width: 1em; height: 1em; display: inline-block; flex-shrink: 0; }
.btn .svg-icon { width: 1rem; height: 1rem; }
.login-logo-icon .svg-icon { width: 22px; height: 22px; }
.sidebar-logo-icon .svg-icon { width: 18px; height: 18px; }
.nav-icon .svg-icon { width: 16px; height: 16px; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-name  { font-size: .825rem; font-weight: 500; }
.user-role  { font-size: .7rem; color: var(--text-muted); }

/* ── Main content ───────────────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  flex-shrink: 0;
}
.topbar-title { font-size: 1rem; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }

.content { padding: 24px 28px; flex: 1; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: .95rem; font-weight: 600; }
.card-body  { padding: 20px; }

/* ── Stats grid ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-label  { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.stat-value  { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-sub    { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }
.stat-icon   { float: right; opacity: .6; margin-top: -4px; }
.stat-icon .svg-icon { width: 1.5rem; height: 1.5rem; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-admin   { background: rgba(99,102,241,.18); color: #a5b4fc; }
.badge-user    { background: rgba(107,114,128,.18); color: #9ca3af; }
.badge-success { background: rgba(34,197,94,.15);  color: #86efac; }
.badge-danger  { background: rgba(239,68,68,.15);  color: #fca5a5; }
.badge-warning { background: rgba(245,158,11,.15); color: #fcd34d; }
.badge-info    { background: rgba(56,189,248,.15); color: #7dd3fc; }

/* ── Toggle switch ──────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 99px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-track::before {
  content: "";
  position: absolute;
  left: 3px; top: 3px;
  width: 14px; height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.toggle input:checked + .toggle-track { background: rgba(99,102,241,.3); border-color: var(--primary); }
.toggle input:checked + .toggle-track::before { transform: translateX(16px); background: var(--primary); }

/* ── Access grid ────────────────────────────────────────────────────────── */
.access-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.access-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}
.access-item.enabled { border-color: rgba(99,102,241,.35); }
.access-name { font-size: .825rem; font-weight: 500; }
.access-icon { display: inline-flex; margin-right: 8px; color: var(--primary); }
.access-icon .svg-icon { width: 1.1rem; height: 1.1rem; }

/* ── Config form ────────────────────────────────────────────────────────── */
.config-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.config-tab {
  padding: 8px 14px;
  font-size: .825rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  margin-bottom: -1px;
}
.config-tab:hover  { color: var(--text); }
.config-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.config-tab.enabled::after { content: "●"; font-size: .5rem; color: var(--success); margin-left: 5px; vertical-align: middle; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 460px;
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body   { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1.2rem; padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 200;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  min-width: 240px;
  max-width: 360px;
  box-shadow: var(--shadow);
  animation: slideLeft .2s ease;
  border-left: 3px solid;
}
.toast-success { background: var(--surface-2); border-color: var(--success); }
.toast-error   { background: var(--surface-2); border-color: var(--danger); }
.toast-info    { background: var(--surface-2); border-color: var(--primary); }

/* ── Code / monospace ───────────────────────────────────────────────────── */
.mono {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  font-size: .8rem;
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--info);
}
.key-reveal {
  display: flex; gap: 8px; align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.key-value {
  flex: 1;
  font-family: 'JetBrains Mono', monospace;
  font-size: .78rem;
  color: var(--success);
  word-break: break-all;
}
.copy-box {
  font-family: 'JetBrains Mono', monospace;
  font-size: .78rem;
  white-space: pre;
}

/* ── Activity ───────────────────────────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 1px; }
.activity-row {
  display: flex; align-items: baseline; gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: .825rem;
  transition: background var(--transition);
}
.activity-row:hover { background: var(--surface-2); }
.activity-time { font-size: .72rem; color: var(--text-dim); white-space: nowrap; min-width: 80px; }
.activity-actor { font-weight: 600; color: var(--primary); white-space: nowrap; }
.activity-action { color: var(--text-muted); }
.activity-detail { color: var(--text-dim); font-size: .78rem; }

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.empty-icon { margin-bottom: 12px; opacity: .5; display: flex; justify-content: center; }
.empty-icon .svg-icon { width: 2.5rem; height: 2.5rem; }
.empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.empty-sub { font-size: .825rem; }

/* ── DB Connections UI ──────────────────────────────────────────────────── */
.conn-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.conn-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.conn-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.conn-badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
}
.conn-badge-mysql    { background: rgba(56,189,248,.15); color: #7dd3fc; }
.conn-badge-postgres { background: rgba(99,102,241,.15); color: #a5b4fc; }
.conn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ── Gateway status ─────────────────────────────────────────────────────── */
.gw-process {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: .8rem;
}
.gw-pulse {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

/* ── User detail tabs ───────────────────────────────────────────────────── */
.user-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 20px;
  width: fit-content;
}
.user-tab {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: .825rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.user-tab:hover  { color: var(--text); }
.user-tab.active { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* ── Server config sections ─────────────────────────────────────────────── */
.server-config-section {
  margin-bottom: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.server-config-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.server-config-header:hover { background: var(--surface-3); }
.server-config-name { font-size: .875rem; font-weight: 600; }
.server-config-icon, .cfg-arrow { display: inline-flex; color: var(--primary); }
.server-config-icon .svg-icon { width: 1.2rem; height: 1.2rem; }
.cfg-arrow .svg-icon { width: 1rem; height: 1rem; }
.server-config-body { padding: 16px; border-top: 1px solid var(--border); }
.server-config-body.hidden { display: none; }

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px) } to { opacity: 1; transform: none } }
@keyframes slideLeft { from { opacity: 0; transform: translateX(20px) } to { opacity: 1; transform: none } }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .4 } }
@keyframes spin { from { transform: rotate(0) } to { transform: rotate(360deg) } }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
