/* ─── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg:         #090C14;
  --surface:    #0F1520;
  --surface2:   #161D2E;
  --border:     rgba(255,255,255,.07);
  --border2:    rgba(255,255,255,.13);
  --fg:         #DDE6F8;
  --fg-muted:   #6B7899;
  --fg-dim:     #323B56;
  --accent:     #4F74FF;
  --accent-bg:  rgba(79,116,255,.12);
  --green:      #34C77B;
  --green-bg:   rgba(52,199,123,.12);
  --red:        #F05252;
  --red-bg:     rgba(240,82,82,.12);
  --amber:      #F5A623;
  --amber-bg:   rgba(245,166,35,.12);
  --radius:     9px;
  --sidebar-w:  220px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #EEF1F9;
    --surface:   #FFFFFF;
    --surface2:  #F4F6FC;
    --border:    rgba(0,0,0,.08);
    --border2:   rgba(0,0,0,.15);
    --fg:        #111827;
    --fg-muted:  #6B7280;
    --fg-dim:    #C4C9D4;
    --accent-bg: rgba(79,116,255,.08);
    --green-bg:  rgba(52,199,123,.10);
    --red-bg:    rgba(240,82,82,.10);
    --amber-bg:  rgba(245,166,35,.10);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg:        #EEF1F9;
  --surface:   #FFFFFF;
  --surface2:  #F4F6FC;
  --border:    rgba(0,0,0,.08);
  --border2:   rgba(0,0,0,.15);
  --fg:        #111827;
  --fg-muted:  #6B7280;
  --fg-dim:    #C4C9D4;
  --accent-bg: rgba(79,116,255,.08);
  --green-bg:  rgba(52,199,123,.10);
  --red-bg:    rgba(240,82,82,.10);
  --amber-bg:  rgba(245,166,35,.10);
  color-scheme: light;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }
html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--fg);
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 15px;
  border-radius: 7px;
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none;
  font-family: inherit; line-height: 1;
  transition: filter .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1) }
.btn svg { width: 13px; height: 13px; flex-shrink: 0 }
.btn-primary { background: var(--accent); color: #fff }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--fg-muted);
}
.btn-ghost:hover { background: var(--surface2); color: var(--fg); filter: none }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(240,82,82,.25) }
.btn-danger:hover { background: var(--red); color: #fff; filter: none }
.btn-sm { padding: 5px 10px; font-size: 12px }

.icon-btn {
  width: 29px; height: 29px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface2); color: var(--fg); border-color: var(--border2) }
.icon-btn svg { width: 13px; height: 13px }
.icon-btn.danger:hover { background: var(--red-bg); color: var(--red); border-color: rgba(240,82,82,.3) }

/* ─── Inputs ─────────────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 7px;
  padding: 8px 12px;
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent) }
input::placeholder { color: var(--fg-dim) }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px; font-weight: 500;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-green { background: var(--green-bg); color: var(--green) }
.badge-red   { background: var(--red-bg);   color: var(--red)   }
.badge-amber { background: var(--amber-bg); color: var(--amber) }
.badge-blue  { background: var(--accent-bg); color: var(--accent) }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--border2);
  padding: 11px 18px; border-radius: 8px; font-size: 13px;
  z-index: 999; max-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px) }
  to   { opacity: 1; transform: translateY(0) }
}

/* ════════════════════════════════════════════════════════════════════════════
   LOGIN PAGE
   ════════════════════════════════════════════════════════════════════════════ */
#login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-wrap { width: 100%; max-width: 380px }
.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 32px;
}
.login-logo-icon {
  width: 38px; height: 38px;
  background: var(--accent); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.login-logo-icon svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2 }
.login-logo-name { font-size: 20px; font-weight: 600; letter-spacing: -.02em }
.login-logo-sub  { font-size: 12px; color: var(--fg-muted) }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
}
.login-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 6px }
.login-card > p { font-size: 13px; color: var(--fg-muted); margin-bottom: 24px }
.field { margin-bottom: 14px }
.field label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--fg-muted); margin-bottom: 6px;
}
.login-card .btn-primary {
  width: 100%; justify-content: center;
  padding: 10px; font-size: 13.5px; margin-top: 6px;
}

/* ════════════════════════════════════════════════════════════════════════════
   SHELL
   ════════════════════════════════════════════════════════════════════════════ */
.shell { display: flex; height: 100%; min-height: 100vh }

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.brand-icon {
  width: 30px; height: 30px;
  background: var(--accent); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-icon svg { width: 15px; height: 15px; stroke: #fff; fill: none; stroke-width: 2 }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -.02em }
.brand-sub  { font-size: 10.5px; color: var(--fg-muted) }

.nav { padding: 10px; flex: 1 }
.nav-section {
  font-size: 10px; font-weight: 600;
  color: var(--fg-dim);
  letter-spacing: .08em; text-transform: uppercase;
  padding: 10px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 7px;
  cursor: pointer; color: var(--fg-muted);
  font-size: 13px; font-weight: 500;
  transition: background .12s, color .12s;
  user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--fg) }
.nav-item.active { background: var(--accent-bg); color: var(--accent) }
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; stroke-width: 2 }

.sidebar-footer { padding: 10px; border-top: 1px solid var(--border) }
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--surface2); cursor: default;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 11px; color: #fff; flex-shrink: 0;
  text-transform: uppercase;
}
.user-domain {
  font-size: 12px; font-weight: 500; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
  font-family: 'JetBrains Mono', monospace;
}
.logout-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--fg-dim); padding: 4px;
  display: flex; align-items: center;
  border-radius: 5px; transition: color .12s;
}
.logout-btn:hover { color: var(--red) }
.logout-btn svg { width: 13px; height: 13px }

/* ─── Main ───────────────────────────────────────────────────────────────── */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 14px; font-weight: 600 }
.topbar-actions { display: flex; gap: 8px; align-items: center }

.content {
  padding: 28px;
  display: flex; flex-direction: column; gap: 22px;
}

/* ─── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-body { padding: 20px }
.section-hd {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-hd h2 { font-size: 14px; font-weight: 600 }

/* ─── Stats ──────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-label {
  font-size: 11.5px; color: var(--fg-muted); font-weight: 500;
  margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.stat-label svg { width: 14px; height: 14px; opacity: .5 }
.stat-val {
  font-size: 26px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em; line-height: 1; margin-bottom: 8px;
}
.stat-val span { font-size: 14px; color: var(--fg-muted); font-weight: 400 }
.stat-sub { font-size: 11.5px; color: var(--fg-muted) }
.bar-wrap {
  height: 4px; background: var(--surface2);
  border-radius: 99px; overflow: hidden; margin: 10px 0 6px;
}
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent) }
.bar-fill.warn   { background: var(--amber) }
.bar-fill.danger { background: var(--red) }

/* ─── Table ──────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse }
.table th {
  text-align: left;
  font-size: 11px; font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 11px 18px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
.table tr:last-child td { border-bottom: none }
.table tbody tr:hover td { background: var(--surface2) }
.row-actions { display: flex; gap: 5px; justify-content: flex-end }

.domain-cell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px; font-weight: 500;
}

/* ─── Info grid ──────────────────────────────────────────────────────────── */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px }
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.info-card h3 {
  font-size: 13px; font-weight: 600; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.info-card h3 svg { width: 15px; height: 15px; color: var(--accent) }
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.info-row:last-child { border-bottom: none }
.info-key { color: var(--fg-muted) }
.info-val { font-weight: 500; font-variant-numeric: tabular-nums }
.info-val.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px }
.info-val.green  { color: var(--green) }
.info-val.accent { color: var(--accent) }

/* ─── Tab pages ──────────────────────────────────────────────────────────── */
.tab-page { display: none }
.tab-page.active { display: flex; flex-direction: column; gap: 22px }

/* ─── File manager ───────────────────────────────────────────────────────── */
.file-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-wrap: wrap;
}
.breadcrumb-bar {
  flex: 1; min-width: 120px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--fg-muted);
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}
.breadcrumb-bar .crumb { cursor: pointer; color: var(--accent) }
.breadcrumb-bar .crumb:hover { text-decoration: underline }
.breadcrumb-bar .sep { color: var(--fg-dim); user-select: none }

.file-name-cell { display: flex; align-items: center; gap: 10px }
.file-name-cell .icon { font-size: 15px; flex-shrink: 0 }
.file-name-cell .name { font-size: 13px }
.file-name-cell .name.folder { cursor: pointer }
.file-name-cell .name.folder:hover { color: var(--accent) }
.file-size { color: var(--fg-muted); font-size: 12px; font-variant-numeric: tabular-nums }

.editor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.editor-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.editor-filename {
  font-size: 12.5px; font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
  color: var(--fg);
  display: flex; align-items: center; gap: 8px;
}
.editor-filename svg { width: 13px; height: 13px; color: var(--accent) }
.editor-actions { display: flex; gap: 8px }
textarea.editor {
  width: 100%; height: 400px; resize: vertical;
  background: var(--bg); color: var(--fg-muted);
  border: none; border-radius: 0;
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px; line-height: 1.65;
}
textarea.editor:focus { border-color: transparent }

/* ─── Databases ──────────────────────────────────────────────────────────── */
.create-db-form { display: flex; gap: 10px; align-items: flex-end }
.create-db-form .field { flex: 1; max-width: 280px; margin: 0 }
.create-db-form label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--fg-muted); margin-bottom: 6px;
}
.create-db-form input { margin: 0 }

.creds-box {
  margin-top: 16px; padding: 14px 16px;
  background: rgba(52,199,123,.08);
  border: 1px solid rgba(52,199,123,.2);
  border-radius: 8px;
}
.creds-title {
  font-size: 12px; font-weight: 600; color: var(--green);
  margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}
.creds-title svg { width: 13px; height: 13px }
.creds-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid rgba(52,199,123,.1);
  font-size: 12.5px;
}
.creds-row:last-child { border-bottom: none; padding-bottom: 0 }
.creds-key { color: var(--fg-muted) }
.creds-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px; color: var(--green); font-weight: 500;
}

/* ─── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 56px 20px; gap: 10px; text-align: center;
}
.empty-state svg { color: var(--fg-dim); width: 40px; height: 40px }
.empty-state p { font-size: 13.5px; color: var(--fg-muted) }
.empty-state small { font-size: 12px; color: var(--fg-dim) }

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

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr) }
  .info-grid  { grid-template-columns: 1fr }
}
@media (max-width: 680px) {
  .sidebar { display: none }
  .content { padding: 16px }
  .topbar  { padding: 12px 16px }
  .stats-grid { grid-template-columns: 1fr 1fr }
  .create-db-form { flex-wrap: wrap }
}
@media (max-width: 440px) {
  .stats-grid { grid-template-columns: 1fr }
}
