/* ============================================================
   BotPanel — Cyberpunk Dark Theme
   Palette: #0a0a0f bg, #7b2fff violet, #00e5ff cyan, #ff3a6e red
   Font: Rajdhani (UI) + Share Tech Mono (code/terminal)
   ============================================================ */

:root {
  --bg:        #0a0a0f;
  --bg-card:   #0f0f1a;
  --bg-input:  #090912;
  --border:    #1e1e35;
  --border-hi: #2e2e52;

  --violet:    #7b2fff;
  --violet-lo: #3d1880;
  --violet-glow: rgba(123, 47, 255, 0.35);

  --cyan:      #00e5ff;
  --cyan-lo:   #006a7a;
  --cyan-glow: rgba(0, 229, 255, 0.3);

  --red:       #ff3a6e;
  --green:     #39ff8a;
  --yellow:    #ffd600;
  --dim:       #4a4a72;

  --text:      #c8c8e8;
  --text-hi:   #eeeeff;
  --text-dim:  #5a5a88;

  --radius:    4px;
  --radius-lg: 8px;

  --font-ui:   'Rajdhani', sans-serif;
  --font-mono: 'Share Tech Mono', monospace;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 500;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scanlines overlay ── */
.scanlines {
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.04) 2px,
    rgba(0,0,0,0.04) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ── Typography ── */
h1, h2, h3 { font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-hi); }
.accent { color: var(--cyan); }
.dim { color: var(--text-dim); font-size: 0.85em; }

a { color: var(--cyan); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--text-hi); }

/* ── Navbar ── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,0.5);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-ui);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.brand-icon {
  color: var(--violet);
  font-size: 1.4rem;
  filter: drop-shadow(0 0 6px var(--violet-glow));
  animation: pulse-violet 3s ease-in-out infinite;
}

@keyframes pulse-violet {
  0%, 100% { filter: drop-shadow(0 0 6px var(--violet-glow)); }
  50% { filter: drop-shadow(0 0 14px var(--violet)); }
}

.nav-right { display: flex; align-items: center; gap: 1rem; }
.nav-user { font-family: var(--font-mono); font-size: 0.8rem; color: var(--cyan); }

/* ── Main content ── */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* Editor page overrides main-content padding — needs full viewport height */
.main-content:has(.editor-page) {
  padding: 0;
  max-width: 100%;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--violet);
  border-color: var(--violet);
  color: #fff;
  box-shadow: 0 0 12px var(--violet-glow);
}
.btn-primary:hover {
  background: #9b4fff;
  box-shadow: 0 0 22px var(--violet);
  color: #fff;
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-hi);
  color: var(--text-dim);
}
.btn-ghost:hover { border-color: var(--cyan); color: var(--cyan); }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-action {
  background: transparent;
  font-size: 0.8rem;
}

.btn-start {
  border-color: var(--green);
  color: var(--green);
}
.btn-start:hover { background: rgba(57,255,138,0.1); box-shadow: 0 0 10px rgba(57,255,138,0.3); }

.btn-stop {
  border-color: var(--red);
  color: var(--red);
}
.btn-stop:hover { background: rgba(255,58,110,0.1); box-shadow: 0 0 10px rgba(255,58,110,0.3); }

.btn-restart {
  border-color: var(--yellow);
  color: var(--yellow);
}
.btn-restart:hover { background: rgba(255,214,0,0.1); }

.btn-edit {
  border-color: var(--cyan);
  color: var(--cyan);
}
.btn-edit:hover { background: rgba(0,229,255,0.1); box-shadow: 0 0 10px var(--cyan-glow); }

.btn-arrow { margin-left: auto; }
.btn-icon { font-size: 1rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1.2rem; }

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--cyan);
  margin-bottom: 0.4rem;
  letter-spacing: 0.05em;
}

.form-input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  color: var(--text-hi);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.form-input:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 2px var(--violet-glow);
}
.form-input::placeholder { color: var(--dim); }
.form-error { display: block; color: var(--red); font-size: 0.8rem; margin-top: 0.3rem; }
.form-hint { display: block; color: var(--text-dim); font-size: 0.78rem; margin-top: 0.3rem; font-family: var(--font-mono); }

/* ── Alerts ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  border-left: 3px solid;
}
.alert-error { background: rgba(255,58,110,0.1); border-color: var(--red); color: var(--red); }
.alert-success { background: rgba(57,255,138,0.1); border-color: var(--green); color: var(--green); }

/* ── Login Page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.login-bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(123,47,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123,47,255,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: 0;
}

.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: 0 0 60px rgba(123,47,255,0.15), 0 0 120px rgba(0,0,0,0.8);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo {
  font-size: 3rem;
  color: var(--violet);
  filter: drop-shadow(0 0 20px var(--violet));
  margin-bottom: 0.5rem;
}

.login-header h1 {
  font-size: 2rem;
  letter-spacing: 0.15em;
}

.login-sub {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  margin-top: 0.4rem;
}

.terminal-line {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 1.2rem;
  padding: 0.5rem;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius);
  border-left: 2px solid var(--violet);
}

.term-prompt { color: var(--cyan); }

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.blink { animation: blink 1s step-end infinite; }

.login-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

/* ── Dashboard ── */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.4rem;
  color: var(--cyan);
  margin-bottom: 0.25rem;
}

.page-sub {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.2rem;
}

.bot-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

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

.bot-card:hover {
  border-color: var(--border-hi);
  box-shadow: 0 4px 30px rgba(0,0,0,0.4);
}

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

.bot-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.5rem;
  min-width: 0;
}

.bot-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.bot-info-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.bot-icon {
  font-size: 1.5rem;
  color: var(--violet);
  filter: drop-shadow(0 0 4px var(--violet-glow));
  flex-shrink: 0;
}

.bot-name {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-hi);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-pid {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

.bot-header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn-delete {
  border-color: transparent;
  color: var(--text-dim);
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  opacity: 0.4;
  transition: all 0.18s;
}
.btn-delete:hover {
  border-color: var(--red);
  color: var(--red);
  opacity: 1;
  background: rgba(255,58,110,0.1);
}

/* ── Status badge ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  white-space: nowrap;
  border: 1px solid;
}

.status-running {
  color: var(--green);
  border-color: var(--green);
  background: rgba(57,255,138,0.08);
}

.status-stopped {
  color: var(--dim);
  border-color: var(--border);
  background: rgba(0,0,0,0.3);
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.status-running .status-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-stopped .status-dot { background: var(--dim); }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 4px var(--green); }
  50% { box-shadow: 0 0 10px var(--green); }
}

.bot-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.bot-log-preview {
  margin-top: 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  max-height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
  color: var(--text-dim);
}
.empty-icon { font-size: 4rem; color: var(--border-hi); margin-bottom: 1rem; }

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  padding: 1.8rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 0 60px rgba(123,47,255,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-header h3 { color: var(--cyan); font-size: 1rem; }

.modal-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 1rem; padding: 0.2rem 0.4rem;
  transition: color 0.2s;
}
.modal-close:hover { color: var(--red); }

.modal-actions {
  display: flex;
  gap: 0.7rem;
  justify-content: flex-end;
  margin-top: 1.2rem;
}

/* ── Editor layout ── */

/* Key insight: editor page uses its own full-height layout */
.editor-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px); /* subtract navbar */
  gap: 0;
  padding: 1rem;
  box-sizing: border-box;
}

.editor-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  flex: 1;
  min-height: 0; /* critical for nested flex/grid shrinking */
}

@media (max-width: 900px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

/* editor-panel is a flex column — header + form(flex-col) + toolbar are fixed height,
   code-editor-wrap takes all remaining space */
.editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.editor-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

.editor-title .accent {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link { color: var(--text-dim); white-space: nowrap; }
.back-link:hover { color: var(--cyan); }
.separator { color: var(--border-hi); flex-shrink: 0; }

/* The form itself is a flex column filling the panel */
.editor-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* The textarea + line numbers wrapper fills all available space */
.code-editor-wrap {
  flex: 1;
  display: flex;
  min-height: 0; /* allow shrinking */
  overflow: hidden;
  position: relative;
}

/* ── Line numbers ── */
/* Uses same font/size/padding/line-height as textarea — they stay in sync via scrollTop */
.line-numbers {
  width: 48px;
  flex-shrink: 0;
  padding: 0.75rem 0.5rem 0.75rem 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;   /* MUST match .code-editor */
  line-height: 1.6;      /* MUST match .code-editor */
  color: var(--dim);
  text-align: right;
  user-select: none;
  background: rgba(0,0,0,0.25);
  border-right: 1px solid var(--border);
  overflow: hidden;      /* JS syncs scrollTop, no scrollbar needed */
  box-sizing: border-box;
}

.line-numbers span {
  display: block;
}

/* ── Code textarea ── */
.code-editor {
  flex: 1;
  padding: 0.75rem 0.75rem 0.75rem 0.75rem;
  background: #06060f;
  border: none;
  color: var(--text-hi);
  font-family: var(--font-mono);
  font-size: 0.875rem;   /* MUST match .line-numbers */
  line-height: 1.6;      /* MUST match .line-numbers */
  resize: none;
  outline: none;
  overflow: auto;        /* both axes — handles wide lines without breaking layout */
  tab-size: 4;
  white-space: pre;      /* preserve indentation, allow horizontal scroll */
  word-wrap: normal;     /* no word wrap — proper code editor behaviour */
  box-sizing: border-box;
  width: 100%;
}

/* ── Toolbar — always visible at bottom ── */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  flex-shrink: 0;        /* never squish — always visible */
  flex-wrap: wrap;
  gap: 0.4rem;
}

.editor-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.editor-meta { display: flex; gap: 1rem; font-family: var(--font-mono); font-size: 0.72rem; align-items: center; }

/* ── Log panel ── */
.log-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0; /* allow shrinking in grid */
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--cyan);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.log-output {
  flex: 1;
  padding: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-dim);
  overflow-y: auto;
  background: #04040d;
  min-height: 200px;
}

.log-line {
  padding: 0.1rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.02);
  word-break: break-all;
}

.log-line:last-child { border: none; }
.log-empty { color: var(--dim); font-style: italic; }

.log-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.8rem;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  border-left: 3px solid;
  background: var(--bg-card);
  max-width: 300px;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.toast-ok { border-color: var(--green); color: var(--green); }
.toast-err { border-color: var(--red); color: var(--red); }
.toast-info { border-color: var(--cyan); color: var(--cyan); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

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

/* ── Delete / danger button ── */
.btn-danger {
  background: rgba(255,58,110,0.15);
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover {
  background: rgba(255,58,110,0.3);
  box-shadow: 0 0 16px rgba(255,58,110,0.4);
  color: var(--red);
}

.danger-title { color: var(--red) !important; }

.modal-card-sm { max-width: 360px; }

.modal-text {
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
