:root {
  --bg: #080c18;
  --bg2: #0d1224;
  --bg3: #111827;
  --bg4: #1a2236;
  --border: #1e2d4a;
  --border2: #2a3f60;
  --accent: #3b82f6;
  --accent2: #60a5fa;
  --green: #10b981;
  --green2: #34d399;
  --orange: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HEADER */
.header {
  background: linear-gradient(135deg, #0a1628 0%, #050d1f 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-brand { display: flex; align-items: center; gap: 16px; }
.brand-icon {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}
.brand-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}
.brand-sub {
  font-weight: 400;
  color: var(--accent2);
  font-size: 1rem;
}
.brand-desc { font-size: .78rem; color: var(--text3); margin-top: 2px; font-family: var(--mono); }
.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg3);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text2);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text3);
  transition: background .3s;
  animation: pulse 2s infinite;
}
.status-dot.online { background: var(--green); }
.status-dot.error  { background: var(--red); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* STATS BAR */
.stats-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 32px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}
.stat-item { display: flex; flex-direction: column; }
.stat-val {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent2);
  font-family: var(--mono);
  line-height: 1.2;
}
.stat-lbl { font-size: .7rem; color: var(--text3); margin-top: 1px; }
.btn-refresh {
  padding: 8px 20px;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  transition: all .2s;
  font-family: 'Inter', sans-serif;
}
.btn-refresh:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59,130,246,.4); }
.btn-refresh:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* CONTROLS */
.controls {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
#searchInput {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  width: 320px;
  font-size: .85rem;
  outline: none;
  transition: border-color .2s;
  font-family: 'Inter', sans-serif;
}
#searchInput:focus { border-color: var(--accent); }
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-btn {
  padding: 6px 14px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text2);
  border-radius: 20px;
  cursor: pointer;
  font-size: .75rem;
  transition: all .2s;
  font-family: 'Inter', sans-serif;
}
.filter-btn:hover, .filter-btn.active {
  background: var(--bg4);
  border-color: var(--accent);
  color: var(--accent2);
}

/* MAIN GRID */
.main {
  flex: 1;
  padding: 28px 32px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* LOADING */
.loading-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--text2);
}
.spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-sub { font-size: .75rem; color: var(--text3); margin-top: 8px; font-family: var(--mono); }

/* DOMAIN CARD */
.domain-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.domain-card:hover {
  transform: translateY(-3px);
  border-color: var(--border2);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.domain-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.domain-icon {
  font-size: 1.4rem;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--bg4);
  flex-shrink: 0;
}
.domain-info { flex: 1; min-width: 0; }
.domain-name { font-weight: 700; font-size: .95rem; color: var(--text); }
.domain-subtitle { font-size: .73rem; color: var(--text3); margin-top: 2px; }
.domain-badge {
  background: var(--bg4);
  color: var(--accent2);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.table-list { padding: 8px; }
.table-row {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 3px;
}
.table-row:hover { background: var(--bg4); border-color: var(--border2); }
.table-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--green2);
  font-family: var(--mono);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-count {
  font-size: .7rem;
  color: var(--text3);
  font-family: var(--mono);
  white-space: nowrap;
}
.table-status {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ts-ok    { background: var(--green); }
.ts-warn  { background: var(--orange); }
.ts-empty { background: var(--text3); }
.ts-error { background: var(--red); }

/* DETAIL PANEL */
.detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
.detail-overlay.open { opacity: 1; pointer-events: all; }
.detail-panel {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(680px, 95vw);
  background: var(--bg2);
  border-left: 1px solid var(--border2);
  z-index: 201;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
}
.detail-panel.open { transform: translateX(0); }
.detail-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  align-items: flex-start;
  position: sticky;
  top: 0;
  background: var(--bg2);
}
.detail-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .7rem;
  font-weight: 600;
  background: var(--bg4);
  color: var(--accent2);
  margin-bottom: 6px;
}
.detail-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green2);
  font-family: var(--mono);
}
.detail-desc { font-size: .82rem; color: var(--text2); margin-top: 6px; line-height: 1.5; }
.detail-close {
  background: var(--bg4);
  border: 1px solid var(--border);
  color: var(--text2);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.detail-meta {
  padding: 16px 24px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-key { font-size: .68rem; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; }
.meta-val { font-size: .85rem; font-weight: 600; color: var(--text); font-family: var(--mono); }
.detail-section { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.detail-section h3 { font-size: .85rem; font-weight: 600; color: var(--text2); margin-bottom: 14px; letter-spacing: .05em; text-transform: uppercase; }

/* DATA TABLE */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: .75rem; }
.data-table th {
  background: var(--bg4);
  color: var(--text3);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  font-family: var(--mono);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg4); }

/* SCHEMA */
.schema-row {
  display: grid;
  grid-template-columns: 1fr 120px 80px;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  border-bottom: 1px solid var(--border);
  font-size: .78rem;
}
.schema-row:last-child { border-bottom: none; }
.schema-row:hover { background: var(--bg3); }
.schema-field { font-family: var(--mono); color: var(--green2); }
.schema-type  { font-family: var(--mono); color: var(--purple); font-size: .72rem; }
.schema-null  { color: var(--text3); font-size: .72rem; }
.schema-header {
  display: grid;
  grid-template-columns: 1fr 120px 80px;
  gap: 12px;
  padding: 6px 12px;
  font-size: .68rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* ERROR / EMPTY STATES */
.error-state, .empty-state {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  color: var(--text2);
  grid-column: 1 / -1;
}
.error-state { border-color: rgba(239,68,68,.3); }
.error-icon { font-size: 2rem; margin-bottom: 12px; }
.error-msg { font-size: .85rem; }
.error-sub { font-size: .75rem; color: var(--text3); margin-top: 8px; font-family: var(--mono); }

/* FOOTER */
.footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .72rem;
  color: var(--text3);
  flex-wrap: wrap;
  gap: 8px;
}
.footer code { font-family: var(--mono); color: var(--accent2); }

/* HIDDEN */
.hidden { display: none !important; }

/* ════════════════════════════════════════
   AUTH OVERLAY & LOGIN CARD
════════════════════════════════════════ */
.auth-overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 30% 40%, #0d1f3c 0%, #050810 60%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.auth-card {
  background: rgba(13,18,36,.9);
  border: 1px solid var(--border2);
  border-radius: 24px;
  padding: 48px 40px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  backdrop-filter: blur(20px);
  box-shadow: 0 24px 80px rgba(0,0,0,.6), 0 0 0 1px rgba(59,130,246,.1);
  animation: cardIn .4s cubic-bezier(.4,0,.2,1);
}
@keyframes cardIn {
  from { opacity:0; transform:translateY(20px) scale(.97); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.auth-logo {
  font-size: 3rem;
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 20px;
  display: block;
  line-height: 1;
}
.auth-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.03em;
  line-height: 1.2;
  margin-bottom: 12px;
}
.auth-title span {
  background: linear-gradient(135deg, var(--accent2), var(--green2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 400;
  font-size: 1rem;
  display: block;
  letter-spacing: 0;
}
.auth-subtitle {
  font-size: .88rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 32px;
}
.btn-ms-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 14px 24px;
  background: #fff;
  color: #1a1a2e;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  transition: all .2s;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.btn-ms-login:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.btn-ms-login:disabled {
  opacity: .7;
  cursor: not-allowed;
  transform: none;
}
.auth-note {
  font-size: .72rem;
  color: var(--text3);
  margin-top: 20px;
  font-family: var(--mono);
  line-height: 1.6;
}
.auth-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

/* ════════════════════════════════════════
   USER MENU (header)
════════════════════════════════════════ */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  position: relative;
  transition: border-color .2s;
}
.user-menu:hover { border-color: var(--border2); }
.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.user-name  { font-size: .8rem;  font-weight: 600; color: var(--text);  max-width: 140px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.user-email { font-size: .7rem;  color: var(--text3); max-width: 140px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-family: var(--mono); }
.chevron    { font-size: .7rem; color: var(--text3); transition: transform .2s; }
.user-menu.open .chevron { transform: rotate(180deg); }
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 6px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: none;
  z-index: 300;
}
.user-menu.open .user-dropdown { display: block; }
.dropdown-item {
  padding: 9px 14px;
  border-radius: 8px;
  font-size: .82rem;
  color: var(--text2);
  cursor: pointer;
  transition: background .15s;
}
.dropdown-item:hover { background: var(--bg4); color: var(--text); }

/* ── Nav Tabs ─────────────────────────────────────────────── */
.nav-tab {
  padding: 5px 14px;
  border-radius: 7px;
  border: 1px solid var(--border2);
  background: var(--bg4);
  color: var(--text2);
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .02em;
}
.nav-tab:hover { background: var(--bg3); color: var(--text); }
.nav-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── ERD ──────────────────────────────────────────────────── */
#erdContainer { user-select: none; }
.erd-table-box:hover {
  background: rgba(96,165,250,.18) !important;
  border-color: #60a5fa !important;
  transform: translateX(2px);
  transition: all .12s;
}

/* ── Schema comment & distinct values ────────────────────── */
.schema-desc {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.schema-comment {
  font-size: .7rem;
  color: var(--text2);
  font-style: italic;
  line-height: 1.4;
}
.distinct-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.distinct-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: .62rem;
  font-family: var(--mono);
  background: rgba(96,165,250,.12);
  border: 1px solid rgba(96,165,250,.25);
  color: var(--accent2);
  white-space: nowrap;
}

/* ── Preview row hover ────────────────────────────────────── */
.preview-row:hover td { background: rgba(96,165,250,.07); }
.preview-row:active td { background: rgba(96,165,250,.14); }

/* ── Last Altered badge ───────────────────────────────────── */
.table-last-altered {
  font-size: .62rem;
  font-family: var(--mono);
  padding: 1px 7px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 6px;
  font-weight: 600;
  letter-spacing: .02em;
}
.la-today   { background: rgba(52,211,153,.18); color: #34d399; border: 1px solid rgba(52,211,153,.35); }
.la-week    { background: rgba(96,165,250,.15); color: #60a5fa; border: 1px solid rgba(96,165,250,.3);  }
.la-month   { background: rgba(251,191,36,.13); color: #fbbf24; border: 1px solid rgba(251,191,36,.3);  }
.la-old     { background: rgba(100,116,139,.12); color: #64748b; border: 1px solid rgba(100,116,139,.2);}
.la-unknown { background: transparent; color: var(--text3); border: none; }

/* ── Environment Switcher ─────────────────────────────────── */
.env-switcher {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border1);
  background: var(--bg2);
}
.env-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border: 1px solid var(--border1);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  position: relative;
  bottom: -1px;
  transition: background .15s, color .15s;
}
.env-tab:hover { background: var(--bg4); color: var(--text1); }
.env-tab.active {
  background: var(--bg1);
  color: var(--text1);
  border-color: var(--accent);
  border-bottom-color: var(--bg1);
  font-weight: 700;
}
.env-tab-sub {
  font-size: .62rem;
  font-family: var(--mono);
  color: var(--text3);
  background: var(--bg4);
  padding: 1px 6px;
  border-radius: 4px;
}
.env-tab.active .env-tab-sub { color: var(--accent2); background: rgba(96,165,250,.1); }
