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

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

:root {
  --bg-void: #06070a;
  --bg-base: #0a0b10;
  --bg-surface: #10111a;
  --bg-raised: #161824;
  --bg-hover: #1c1e2e;
  --bg-active: #222438;
  --border-dim: #1a1c2e;
  --border-mid: #252840;
  --border-bright: #3a3d5c;
  --text-primary: #e8eaf0;
  --text-secondary: #8b8ea8;
  --text-tertiary: #5a5d78;
  --text-ghost: #3a3d52;
  --accent: #7c5bf5;
  --accent-dim: #6347cc;
  --accent-glow: rgba(124,91,245,0.15);
  --accent-strong: #9678ff;
  --green: #3dd68c;
  --green-dim: rgba(61,214,140,0.12);
  --red: #f5555d;
  --red-dim: rgba(245,85,93,0.12);
  --amber: #f5a623;
  --amber-dim: rgba(245,166,35,0.12);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html { font-size: 15px; }

body {
  font-family: var(--font-display);
  background: var(--bg-void);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* === NOISE OVERLAY === */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* === LOGIN === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-void);
  position: relative;
}

.login-screen::after {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124,91,245,0.08) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.login-box {
  position: relative;
  z-index: 1;
  width: 380px;
  max-width: 90vw;
  text-align: center;
}

.login-logo {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.3rem;
}

.login-sub {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 2.5rem;
}

.login-field {
  position: relative;
  margin-bottom: 1.2rem;
}

.login-field input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  outline: none;
  transition: var(--transition);
}

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-field input::placeholder {
  color: var(--text-ghost);
  letter-spacing: 0.05em;
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.login-btn:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 8px 30px rgba(124,91,245,0.25);
}

.login-btn:active { transform: translateY(0); }

.login-error {
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 0.8rem;
  opacity: 0;
  transition: var(--transition);
}

.login-error.show { opacity: 1; }

/* === LAYOUT === */
.app { display: none; min-height: 100vh; }
.app.active { display: flex; }

/* === SIDEBAR === */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--bg-base);
  border-right: 1px solid var(--border-dim);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 50;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border-dim);
}

.sidebar-brand {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-label {
  font-size: 0.7rem;
  color: var(--text-ghost);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  font-size: 0.68rem;
  color: var(--text-ghost);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 16px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
  font-weight: 450;
  user-select: none;
}

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

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent-strong);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-active);
  color: var(--text-tertiary);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-dim);
  font-size: 0.75rem;
  color: var(--text-ghost);
  font-family: var(--font-mono);
}

/* === MAIN === */
.main {
  flex: 1;
  margin-left: 240px;
  min-height: 100vh;
}

.topbar {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-base);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(12px);
}

.topbar-title {
  font-size: 1.15rem;
  font-weight: 600;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.content {
  padding: 28px 32px;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-strong);
  box-shadow: 0 4px 20px rgba(124,91,245,0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-mid);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-bright);
}

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(245,85,93,0.2);
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon svg { width: 18px; height: 18px; }

/* === BOT CARDS === */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.bot-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.bot-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0;
  transition: var(--transition);
}

.bot-card:hover {
  border-color: var(--border-mid);
  transform: translateY(-2px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}

.bot-card:hover::before { opacity: 1; }

.bot-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.bot-card-info { display: flex; align-items: center; gap: 10px; }

.bot-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bot-status.running {
  background: var(--green);
  box-shadow: 0 0 8px rgba(61,214,140,0.5);
  animation: pulse-green 2s ease-in-out infinite;
}

.bot-status.stopped { background: var(--text-ghost); }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 8px rgba(61,214,140,0.5); }
  50% { box-shadow: 0 0 16px rgba(61,214,140,0.8); }
}

.bot-name {
  font-size: 1rem;
  font-weight: 600;
}

.bot-card-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: var(--transition);
}

.bot-card:hover .bot-card-actions { opacity: 1; }

.bot-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.bot-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg-active);
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.bot-badge.model {
  background: var(--accent-glow);
  color: var(--accent-strong);
}

.bot-prompt {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-style: italic;
}

.bot-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-ghost);
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-dim);
}

/* === EMPTY STATE === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.empty-icon svg { width: 28px; height: 28px; color: var(--text-ghost); }

.empty-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.empty-desc {
  color: var(--text-tertiary);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,7,10,0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-xl);
  width: 500px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 40px 100px rgba(0,0,0,0.5);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

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

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 650;
}

.modal-body { padding: 20px 28px 28px; }

.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 550;
  color: var(--text-secondary);
  margin-bottom: 7px;
  letter-spacing: 0.03em;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.88rem;
  outline: none;
  transition: var(--transition);
}

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

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-ghost);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%235a5d78' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-select option { background: var(--bg-raised); }

.form-textarea {
  min-height: 110px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
}

.modal-footer {
  padding: 0 28px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* === TOAST === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  animation: toastIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.toast svg { width: 16px; height: 16px; flex-shrink: 0; }

.toast-success {
  background: var(--green-dim);
  border: 1px solid rgba(61,214,140,0.2);
  color: var(--green);
}

.toast-error {
  background: var(--red-dim);
  border: 1px solid rgba(245,85,93,0.2);
  color: var(--red);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* === PLACEHOLDER PAGES === */
.placeholder-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 120px 20px;
  text-align: center;
}

.placeholder-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: var(--bg-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  border: 1px solid var(--border-dim);
}

.placeholder-icon svg { width: 32px; height: 32px; color: var(--text-ghost); }

.placeholder-title {
  font-size: 1.2rem;
  font-weight: 650;
  margin-bottom: 8px;
}

.placeholder-desc {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  max-width: 320px;
}

/* === MOBILE === */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mobile-toggle { display: flex; }
  .content { padding: 20px 16px; }
  .topbar { padding: 16px; padding-left: 52px; }
  .bot-grid { grid-template-columns: 1fr; }
  .bot-card-actions { opacity: 1; }
}

/* === LOADING === */
.loading-dots {
  display: inline-flex;
  gap: 4px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: dotPulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* === PAGE TRANSITIONS === */
.page { display: none; animation: pageIn 0.25s ease; }
.page.active { display: block; }

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

/* === TOGGLE SWITCH === */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  user-select: none;
}

.toggle input { display: none; }

.toggle-track {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg-active);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-ghost);
  top: 2px;
  left: 2px;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--accent-glow);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent);
}

.toggle-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent-strong);
}

.toggle-desc {
  color: var(--text-tertiary);
  font-size: 0.82rem;
}

/* === SETTINGS PANELS === */
.s-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.s-panel-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-raised);
}

.s-panel-head h3 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.s-panel-body { padding: 16px 20px; }

.s-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.s-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-ghost);
  font-weight: 500;
  border-bottom: 1px solid var(--border-dim);
}

.s-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(26,28,46,0.5);
}

.s-table tr:hover td { background: var(--bg-hover); }
.s-table tr:last-child td { border-bottom: none; }

/* === FORM SECTIONS === */
.form-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-dim);
}

.form-section:last-of-type { border-bottom: none; }

.form-section-title {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-ghost);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-dim);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 520px) {
  .form-row { grid-template-columns: 1fr; }
}

/* === SEGMENTED CONTROL === */
.seg-control {
  display: inline-flex;
  background: var(--bg-raised);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg-btn {
  padding: 7px 16px;
  font-size: 0.78rem;
  font-weight: 550;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  border-right: 1px solid var(--border-dim);
}

.seg-btn:last-child { border-right: none; }
.seg-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.seg-btn.active {
  background: var(--accent-glow);
  color: var(--accent-strong);
}

/* === TOOL TOGGLE ROW === */
.tool-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(26,28,46,0.4);
}

.tool-row:last-child { border-bottom: none; }

/* === INLINE ADD FORM === */
.inline-add {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding-top: 12px;
  border-top: 1px solid var(--border-dim);
  margin-top: 12px;
}

.inline-add .form-group { margin-bottom: 0; }
.inline-add .form-input { font-size: 0.82rem; }
