@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg:          #0B0B12;
  --sidebar-bg:  #10101C;
  --card-bg:     #17172A;
  --card-hover:  #1E1E34;
  --border:      #252540;
  --accent:      #7C6FFF;
  --accent-dim:  rgba(124, 111, 255, 0.12);
  --accent-glow: rgba(124, 111, 255, 0.3);
  --cyan:        #00CFFF;
  --cyan-dim:    rgba(0, 207, 255, 0.1);
  --text:        #E2E2F0;
  --muted:       #6B6B8A;
  --success:     #10B981;
  --danger:      #EF4444;
  --warning:     #F59E0B;
  --sidebar-w:   240px;
}

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

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; font-size: 14px; line-height: 1.6; }

a { color: inherit; text-decoration: none; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  font-size: 24px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 20px 20px 8px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--card-bg); color: var(--text); }

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  position: relative;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); }

.logout-btn {
  color: var(--muted);
  font-size: 16px;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--danger); }

/* ── Main ─────────────────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 32px 0;
}

.main-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.main-content { padding: 24px 32px 40px; }

/* ── Flash messages ───────────────────────────────────────────────────────────── */
.flash-messages { padding: 16px 32px 0; }

.flash {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.flash-success { background: rgba(16, 185, 129, 0.12); border: 1px solid rgba(16, 185, 129, 0.3); color: var(--success); }
.flash-error   { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.3); color: var(--danger); }
.flash-info    { background: var(--accent-dim); border: 1px solid var(--accent-glow); color: var(--accent); }

/* ── Cards ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

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

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.stat-value.accent { color: var(--accent); }
.stat-value.cyan   { color: var(--cyan); }
.stat-value.success { color: var(--success); }

/* ── Grid layouts ─────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

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

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Buttons ──────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #6a5ee0; box-shadow: 0 0 20px var(--accent-glow); }

.btn-secondary {
  background: var(--card-hover);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #252540; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--card-bg); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.85; }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.1); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; font-weight: 600; }

.btn-generate {
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 32px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}
.btn-generate:hover { box-shadow: 0 0 30px var(--accent-glow); transform: translateY(-1px); }
.btn-generate:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ── Forms ────────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.form-label .required { color: var(--danger); margin-left: 2px; }

input[type=text], input[type=email], input[type=password], input[type=url],
textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
select option { background: var(--card-bg); }

/* ── Badges ───────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-muted   { background: rgba(107,107,138,0.15); color: var(--muted); }
.badge-accent  { background: var(--accent-dim); color: var(--accent); }
.badge-warning { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-danger  { background: rgba(239,68,68,0.12); color: var(--danger); }
.badge-cyan    { background: var(--cyan-dim); color: var(--cyan); }

/* ── Builder page ─────────────────────────────────────────────────────────────── */
.builder-input-area {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 24px;
}

.builder-input-area textarea {
  font-size: 15px;
  padding: 14px 16px;
  min-height: 120px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.builder-result {
  display: none;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 28px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.result-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.result-icon { font-size: 36px; }
.result-name { font-size: 18px; font-weight: 700; }
.result-cat  { font-size: 12px; color: var(--muted); margin-top: 2px; }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }

.result-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 8px;
}

.loading-overlay {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Agent cards ──────────────────────────────────────────────────────────────── */
.agent-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.15s;
  cursor: pointer;
}

.agent-card:hover {
  border-color: var(--accent);
  background: var(--card-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.agent-icon { font-size: 28px; margin-bottom: 12px; }
.agent-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.agent-desc { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 12px; }

/* ── Agents grid ─────────────────────────────────────────────────────────────── */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* ── Empty state ──────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 8px; }
.empty-state p  { font-size: 13px; margin-bottom: 20px; }

/* ── Login page ───────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(124,111,255,0.08) 0%, transparent 70%),
              var(--bg);
}

.login-box {
  width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.login-logo h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.login-logo p  { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Execution log ───────────────────────────────────────────────────────────── */
.exec-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

/* ── Section separator ───────────────────────────────────────────────────────── */
.section { margin-bottom: 28px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
}

/* ── Chip list ───────────────────────────────────────────────────────────────── */
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--muted);
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 440px;
  max-width: 90vw;
  animation: fadeIn 0.2s ease;
}

.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Output modal ────────────────────────────────────────────────────────────── */
.output-modal .exec-output { max-height: 300px; font-size: 13px; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.font-mono { font-family: 'Courier New', monospace; }
.w-full { width: 100%; }
