/* ==================== RESET & VARIABLES ==================== */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #161821;
  --bg-tertiary: #1c1f2b;
  --bg-elevated: #232636;
  --bg-hover: #2a2d3e;
  
  --border: #2a2d3e;
  --border-active: #cd412b;
  
  --text-primary: #e8eaf0;
  --text-secondary: #8b8fa3;
  --text-muted: #5a5e72;
  
  --accent: #cd412b;         /* Rust red */
  --accent-hover: #e04d36;
  --accent-glow: rgba(205, 65, 43, 0.15);
  
  --green: #3dd68c;
  --green-dim: rgba(61, 214, 140, 0.12);
  --red: #f5534f;
  --red-dim: rgba(245, 83, 79, 0.12);
  --yellow: #f0c040;
  --yellow-dim: rgba(240, 192, 64, 0.12);
  --blue: #4da6ff;
  --blue-dim: rgba(77, 166, 255, 0.12);
  
  --sidebar-width: 260px;
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  
  --font-body: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ==================== LAYOUT ==================== */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ==================== SIDEBAR ==================== */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .logo-icon {
  font-size: 28px;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.sidebar-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 1px;
}

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

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.bot-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  position: relative;
}

.bot-nav-item:hover {
  background: var(--bg-hover);
}

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

.bot-nav-item .nav-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.bot-nav-item .nav-info {
  flex: 1;
  min-width: 0;
}

.bot-nav-item .nav-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-nav-item .nav-status {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.bot-nav-item .nav-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.bot-nav-item .nav-status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.bot-nav-item .nav-status-dot.stopped { background: var(--red); }
.bot-nav-item .nav-status-dot.errored { background: var(--yellow); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.user-avatar {
  font-size: 18px;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}

.btn-logout:hover {
  color: var(--red);
  border-color: var(--red);
}

/* ==================== MAIN CONTENT ==================== */

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Welcome screen */
.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.welcome-inner {
  text-align: center;
  opacity: 0.5;
}

.welcome-icon {
  font-size: 64px;
  display: block;
  margin-bottom: 16px;
}

.welcome-inner h2 {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 6px;
}

.welcome-inner p {
  font-size: 14px;
  color: var(--text-muted);
}

/* Bot Detail */
.bot-detail {
  padding: 24px 28px;
  max-width: 1100px;
}

.bot-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.bot-header-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.bot-header-info .bot-icon {
  font-size: 36px;
}

.bot-name {
  font-size: 24px;
  font-weight: 600;
}

.bot-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.bot-status-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.status-badge.online {
  background: var(--green-dim);
  color: var(--green);
}

.status-badge.stopped {
  background: var(--red-dim);
  color: var(--red);
}

.status-badge.errored {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.status-badge.not_found {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.status-badge .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.online .status-dot {
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.bot-stats {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* PM2 Controls */
.pm2-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.btn-pm2 {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-pm2:hover { background: var(--bg-hover); }
.btn-pm2:active { transform: scale(0.97); }

.btn-pm2.btn-restart:hover { border-color: var(--blue); color: var(--blue); }
.btn-pm2.btn-stop:hover { border-color: var(--red); color: var(--red); }
.btn-pm2.btn-start:hover { border-color: var(--green); color: var(--green); }
.btn-pm2.btn-reload:hover { border-color: var(--yellow); color: var(--yellow); }

.btn-pm2:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==================== TABS ==================== */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ==================== CONFIG EDITOR ==================== */

.config-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.config-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}

.config-tab:hover {
  background: var(--bg-hover);
}

.config-tab.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.config-tab.missing {
  opacity: 0.4;
  cursor: not-allowed;
}

.config-editor {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.config-placeholder {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Mode toggle */
.config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.config-header-title {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}

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

.mode-toggle {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.mode-btn {
  padding: 4px 12px;
  font-size: 11px;
  font-family: var(--font-mono);
  border: none;
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.mode-btn.active {
  background: var(--accent);
  color: white;
}

.btn-save {
  padding: 6px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: white;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-save:hover {
  background: var(--accent-hover);
}

.btn-save:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Fields mode */
.config-fields {
  padding: 16px;
}

.config-field {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.config-field:last-child {
  border-bottom: none;
}

.config-field-key {
  min-width: 180px;
  max-width: 220px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  padding-top: 8px;
  word-break: break-all;
  font-weight: 500;
}

.config-field-value {
  flex: 1;
}

.config-field-value input,
.config-field-value textarea {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  transition: border-color var(--transition);
}

.config-field-value input:focus,
.config-field-value textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.config-field-value textarea {
  min-height: 80px;
  resize: vertical;
}

.config-field-type {
  font-size: 10px;
  color: var(--text-muted);
  padding-top: 10px;
  font-family: var(--font-mono);
  min-width: 50px;
}

/* Raw mode */
.config-raw {
  padding: 0;
}

.config-raw textarea {
  width: 100%;
  min-height: 400px;
  padding: 16px;
  background: var(--bg-primary);
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

.config-raw textarea:focus {
  outline: none;
}

/* ==================== LOGS ==================== */

.logs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--accent);
}

.btn-small {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}

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

.logs-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  height: calc(100vh - 340px);
  min-height: 300px;
}

.logs-output {
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-secondary);
  overflow-y: auto;
  height: 100%;
  white-space: pre-wrap;
  word-break: break-all;
}

.logs-output::-webkit-scrollbar {
  width: 6px;
}

.logs-output::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Log line coloring (applied via JS) */
.log-error { color: var(--red); }
.log-warn { color: var(--yellow); }
.log-info { color: var(--blue); }
.log-debug { color: var(--text-muted); }

/* ==================== TOAST ==================== */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast.success {
  background: var(--green);
  color: #0a0a0a;
}

.toast.error {
  background: var(--red);
  color: white;
}

.toast.info {
  background: var(--blue);
  color: white;
}

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

/* ==================== LOGIN PAGE ==================== */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
  background-image: 
    radial-gradient(ellipse at 20% 50%, var(--accent-glow) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(77, 166, 255, 0.05) 0%, transparent 50%);
}

.login-container {
  width: 360px;
  padding: 40px 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

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

.login-logo .logo-icon {
  font-size: 40px;
  display: block;
  margin-bottom: 10px;
}

.login-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.login-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 4px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.input-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color var(--transition);
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.error-message {
  background: var(--red-dim);
  color: var(--red);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.btn-login {
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.btn-login:hover {
  background: var(--accent-hover);
}

/* ==================== LOADING SPINNER ==================== */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ==================== MODAL ==================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 400px;
  max-width: 90vw;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-box h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: color var(--transition);
}

.modal-close:hover {
  color: var(--text-primary);
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
  }
  
  .sidebar-header div,
  .sidebar-subtitle,
  .nav-info,
  .user-name {
    display: none;
  }
  
  .sidebar-header {
    justify-content: center;
    padding: 16px 8px;
  }
  
  .bot-nav-item {
    justify-content: center;
    padding: 10px 8px;
  }
  
  .bot-nav-item .nav-icon {
    width: auto;
  }
  
  .sidebar-footer {
    flex-direction: column;
    gap: 8px;
    padding: 8px;
  }
  
  .bot-detail {
    padding: 16px;
  }
  
  .config-field {
    flex-direction: column;
    gap: 4px;
  }
  
  .config-field-key {
    min-width: auto;
    max-width: none;
  }
}
