/* ===== TELEGRAM PANEL — Design System ===== */
:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #16161e;
  --bg-card: #1c1c27;
  --bg-card-hover: #22222f;
  --bg-input: #12121a;
  --border: #2a2a3a;
  --border-focus: #5b6eea;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --accent: #5b6eea;
  --accent-hover: #6e7ff0;
  --accent-light: rgba(91,110,234,0.12);
  --success: #34c77b;
  --success-light: rgba(52,199,123,0.12);
  --warning: #f0a030;
  --warning-light: rgba(240,160,48,0.12);
  --danger: #e84057;
  --danger-light: rgba(232,64,87,0.12);
  --info: #38b6f1;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: 0.2s ease;
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: transform var(--transition);
}

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

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header h1 .icon { font-size: 22px; }

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: var(--accent-light); color: var(--accent); }
.nav-item .icon { font-size: 18px; width: 22px; text-align: center; }

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

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

.page-header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-content { padding: 28px 32px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: #111; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 8px; min-width: 34px; justify-content: center; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition);
}

.card:hover { border-color: #353548; }

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

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

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

.stat-card .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-card .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Table ===== */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

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

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

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
}

.badge-active { background: var(--success-light); color: var(--success); }
.badge-active::before { background: var(--success); }
.badge-error { background: var(--danger-light); color: var(--danger); }
.badge-error::before { background: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-warning::before { background: var(--warning); }
.badge-inactive { background: rgba(136,136,160,0.1); color: var(--text-secondary); }
.badge-inactive::before { background: var(--text-secondary); }
.badge-running { background: var(--accent-light); color: var(--accent); }
.badge-running::before { background: var(--accent); animation: pulse 1.5s infinite; }

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

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238888a0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

textarea.form-control { resize: vertical; min-height: 80px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

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

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  transition: transform var(--transition);
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; padding: 4px;
}

.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Chat / Dialog View ===== */
.chat-layout { display: flex; height: calc(100vh - 73px); }

.chat-list {
  width: 300px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg-secondary);
}

.chat-list-item {
  display: flex;
  position: relative;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.chat-list-item:hover { background: var(--bg-card); }
.chat-list-item.active { background: var(--accent-light); }

.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.chat-preview { flex: 1; min-width: 0; }
.chat-preview .name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview .last-msg { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview .time { font-size: 11px; color: var(--text-muted); }
.chat-time { flex-shrink: 0; align-self: flex-start; padding-top: 2px; }
.chat-time .time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.chat-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.chat-delete {
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--text-muted); cursor: pointer; flex-shrink: 0;
}
.chat-delete:hover { color: var(--danger); background: rgba(239,68,68,.12); }
.chat-list-item .chat-delete {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  opacity: 0; background: var(--bg-card);
}
.chat-list-item:hover .chat-delete, .chat-list-item.active .chat-delete,
.chat-delete:focus-visible { opacity: 1; }
.chat-header-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.live-status {
  display: inline-flex;
  align-items: center;
  min-width: 132px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.live-status.online { color: var(--success); }
.live-status.connecting { color: var(--warning); }
.live-status.offline { color: var(--text-muted); }

.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-messages-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  background: var(--bg-secondary);
}

.chat-messages-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-bubble {
  max-width: 70%;
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-bubble.sent {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-bubble.received {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  margin-top: 4px;
  text-align: right;
}

.message-bubble.received .message-time { color: var(--text-muted); }

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Login ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 22px;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

/* ===== Scenario Steps Editor ===== */
.steps-list { display: flex; flex-direction: column; gap: 8px; }

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.step-number {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-content { flex: 1; min-width: 0; }
.step-sender { font-size: 11px; font-weight: 600; color: var(--accent); text-transform: uppercase; margin-bottom: 4px; }
.step-text { font-size: 13px; color: var(--text-primary); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ===== Log Entries ===== */
.log-entry {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.log-time { color: var(--text-muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.log-level { font-weight: 600; min-width: 60px; }
.log-level.info { color: var(--info); }
.log-level.warning { color: var(--warning); }
.log-level.error { color: var(--danger); }
.log-message { flex: 1; }
.log-category { color: var(--text-muted); font-size: 11px; }

/* ===== Utility ===== */
.flex { display: flex; }
.flex-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.hidden { display: none !important; }

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .page-content { padding: 16px; }
  .chat-list { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Auth Tabs ===== */
.auth-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.auth-tab {
  padding: 10px 14px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-secondary); font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all var(--transition);
}
.auth-tab:hover { color: var(--text-primary); }
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-content { min-height: 120px; }

/* ===== Scenario type toggle ===== */
.type-toggle { display: flex; gap: 10px; }
.type-opt {
  flex: 1; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: all var(--transition);
  background: var(--bg-input);
}
.type-opt:hover { border-color: #3a3a4e; }
.type-opt.active { border-color: var(--accent); background: var(--accent-light); }
.type-opt-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.type-opt-desc { font-size: 11px; color: var(--text-muted); }

/* ===== Day checkboxes ===== */
.day-checks { display: flex; gap: 10px; flex-wrap: wrap; }
.day-check {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  font-weight: 500; color: var(--text-primary); cursor: pointer;
  text-transform: none; letter-spacing: normal;
}
.day-check input { accent-color: var(--accent); }

.chat-messages-header { display: flex; align-items: center; justify-content: space-between; }

/* ===== Chat compose bar ===== */
.chat-compose {
  display: flex; gap: 10px; padding: 14px 20px;
  border-top: 1px solid var(--border); background: var(--bg-secondary);
}
.chat-compose .form-control { flex: 1; }

/* ===== Toast Notification ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }

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

/* ===== Spammer tabs ===== */
.spammer-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.spam-tab {
  background: none; border: none; color: var(--text-secondary); font-size: 14px; font-weight: 500;
  padding: 10px 18px; cursor: pointer; border-bottom: 2px solid transparent; transition: var(--transition);
}
.spam-tab:hover { color: var(--text-primary); }
.spam-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
