:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --text: #e8eaf6;
  --text-muted: #6b7280;
  --blue: #4f87ff;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --purple: #a855f7;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 22px; }

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

.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,135,255,0.15); color: var(--blue); }

/* ── Admin section toggle ─────────────────────────── */
.nav-section { margin-top: 4px; }

.nav-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.nav-toggle:hover { background: var(--surface2); color: var(--text); }
.nav-toggle.open { color: var(--blue); }

.toggle-arrow {
  font-size: 10px;
  transition: transform 0.2s;
  display: inline-block;
}
.nav-toggle.open .toggle-arrow { transform: rotate(90deg); }

.nav-sub {
  display: none;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
  padding-left: 8px;
}
.nav-sub.open { display: flex; }

.nav-sub-item {
  padding: 8px 12px;
  font-size: 13px;
}

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
}

/* ── Main ────────────────────────────────────────── */
.main {
  margin-left: 220px;
  flex: 1;
  padding: 32px;
  max-width: 1100px;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}
.view-header h1 { font-size: 22px; font-weight: 700; }
.subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

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

.bots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.bot-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s;
}
.bot-card:hover { border-color: var(--blue); }
.bot-card.running { border-left: 3px solid var(--green); }
.bot-card.stopped { border-left: 3px solid var(--red); }

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

.bot-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.bot-path {
  color: var(--text-muted);
  font-size: 11px;
  font-family: monospace;
  margin-bottom: 14px;
  word-break: break-all;
}

.bot-actions {
  display: flex;
  gap: 8px;
}

/* ── Badges ──────────────────────────────────────── */
.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-running { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-stopped { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-unknown { background: rgba(107,114,128,0.15); color: var(--text-muted); }
.badge-ok { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--red); }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #3a70e8; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Form ────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-muted); font-size: 13px; }

.input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--blue); }
.textarea { resize: vertical; min-height: 160px; }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.provision-card { max-width: 640px; }

.prov-result {
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}
.prov-result.success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--green); }
.prov-result.error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--red); }

/* ── Modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 760px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 18px; padding: 2px 6px;
}
.modal-close:hover { color: var(--text); }

.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 8px 14px; font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all 0.15s;
}
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.log-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #9ca3af;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Misc ────────────────────────────────────────── */
.loading { color: var(--text-muted); padding: 40px 0; text-align: center; }
.hidden { display: none !important; }

/* ── Login error ─────────────────────────────────── */
.login-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  margin: 0;
}

.hamburger {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 149;
}
.sidebar-overlay.visible { display: block; }

@media (max-width: 768px) {
  .hamburger { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0;
    padding: 64px 16px 24px;
  }

  .bots-grid {
    grid-template-columns: 1fr;
  }

  .provision-card { max-width: 100%; }

  .view-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
}
