:root {
  --bg: #0b1020;
  --bg-card: #121a2f;
  --bg-elev: #19233d;
  --border: #253252;
  --text: #e6edf7;
  --muted: #8ea0c0;
  --primary: #4f7cff;
  --primary-hover: #3c69ec;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mb { margin-bottom: 12px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.gap { gap: 8px; }
.flex-1 { flex: 1; }
code { background: #1e2945; padding: 2px 6px; border-radius: 5px; font-size: 12px; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #18254a 0%, #0b1020 65%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand-badge {
  display: inline-block;
  align-self: flex-start;
  background: rgba(79,124,255,0.16);
  color: #8ab0ff;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 999px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  background: #0d1426;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: #fff;
  transition: .15s;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-elev); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #233154; }
.btn-danger { background: rgba(239,68,68,0.16); border-color: rgba(239,68,68,0.4); color: #fca5a5; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg-elev); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}
.sidebar-header { padding: 4px 10px 18px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.logo { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active { background: rgba(79,124,255,0.18); color: #fff; font-weight: 600; }
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.main { flex: 1; padding: 24px 28px; overflow-x: hidden; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.section-title { font-size: 14px; color: var(--muted); margin: 20px 0 10px; text-transform: uppercase; letter-spacing: .6px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.narrow { max-width: 440px; display: flex; flex-direction: column; gap: 12px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 14px; }
.project-actions { justify-content: flex-start; }

.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }

.metric-val { font-size: 24px; font-weight: 700; margin: 6px 0; }
.bar { height: 7px; background: #1e2945; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--primary); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-ok { background: rgba(34,197,94,0.18); color: #86efac; }
.badge-warn { background: rgba(245,158,11,0.18); color: #fcd34d; }
.badge-err { background: rgba(239,68,68,0.18); color: #fca5a5; }
.badge-info { background: rgba(79,124,255,0.18); color: #93c5fd; }

.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; background: rgba(255,255,255,0.02); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.02); }
.link { color: #8ab0ff; cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Terminal */
.terminal-wrap {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  height: calc(100vh - 155px);
  min-height: 420px;
}
#xterm-container { width: 100%; height: 100%; }

/* Editors & Logs */
.code-area {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
}
.log-box {
  background: #070b16;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  height: 360px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.68);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
}
.modal-card {
  width: 100%; max-width: 720px; max-height: 90vh;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; display: flex; flex-direction: column;
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.alert-error { background: rgba(239,68,68,0.16); border: 1px solid rgba(239,68,68,0.4); color: #fca5a5; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text); padding: 11px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); }

.db-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 260px; overflow-y: auto; }
.db-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: #0d1426; border-radius: 6px; font-size: 12.5px; }

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; overflow-x: auto; }
}
