:root {
  --bg-dark: #f8fafc;
  --bg-card: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --border-glass: rgba(245, 158, 11, 0.25);
  --primary: #f59e0b;
  --primary-hover: #d97706;
  --primary-gradient: linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
  --accent-cyan: #0284c7;
  --accent-emerald: #059669;
  --accent-rose: #e11d48;
  --accent-purple: #7c3aed;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-gold: #b45309;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --glow-gold: rgba(245, 158, 11, 0.35);
}

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

[hidden] {
  display: none !important;
}

body {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 45%, #eef2ff 100%);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
}

/* Sidebar Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 270px;
  background: var(--bg-glass);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 2.5rem;
}

.brand-logo {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.25rem;
  color: #070913;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.brand-text h2 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #0f172a;
}

.brand-text span {
  font-size: 0.72rem;
  color: var(--accent-cyan);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.nav-item:hover, .nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-main);
  border-color: rgba(99, 102, 241, 0.3);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* «Домой» — первый пункт меню, аккуратно встроен и отделён от остальных */
.nav-item.home-item {
  color: #b45309;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.10), rgba(99, 102, 241, 0.06));
  border: 1px solid rgba(245, 158, 11, 0.25);
  font-weight: 600;
  margin-bottom: 0.55rem;
}
.nav-item.home-item:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(99, 102, 241, 0.10));
  border-color: rgba(245, 158, 11, 0.45);
  color: #b45309;
}

/* Мобильная кнопка «Домой» — встроена в поток страницы, внизу перед футером */
.mobile-home { display: none; }
@media (max-width: 900px) {
  .mobile-home {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 28px auto 18px;
    padding: 14px 22px;
    max-width: 340px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(99, 102, 241, 0.08));
    border: 1px solid rgba(245, 158, 11, 0.30);
    border-radius: 14px;
    color: #b45309;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  }
  .mobile-home:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(99, 102, 241, 0.10));
  }
  .page-home-link { display: none !important; }
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-bar {
  height: 70px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
}

.top-bar h1 {
  font-size: 1.3rem;
  font-weight: 600;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--accent-emerald);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-badge[data-state="checking"] {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--text-gold);
}

.status-badge[data-state="ready"] {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--accent-emerald);
}

.status-badge[data-state="database-unavailable"],
.status-badge[data-state="offline"] {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-emerald);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse 1.5s infinite;
}

.status-badge[data-state="checking"] .pulse-dot {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}

.status-badge[data-state="database-unavailable"] .pulse-dot,
.status-badge[data-state="offline"] .pulse-dot {
  background: #ef4444;
  box-shadow: none;
  animation: none;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.content-body {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* Cards & Grid Layout */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;

  transition: transform 0.2s ease, border-color 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-3px);
  border-color: rgba(99, 102, 241, 0.4);
}

.metric-title {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.metric-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.metric-sub {
  font-size: 0.75rem;
  color: var(--accent-cyan);
}

/* Form Glass Panels */
.panel {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
  padding: 1.75rem;
  margin-bottom: 2rem;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;

  color: var(--text-main);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  background: #f8fafc;
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s ease;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.5rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  padding: 0.85rem 1rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-glass);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.data-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.pill {
  padding: 0.25rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.pill-success { background: rgba(16, 185, 129, 0.2); color: var(--accent-emerald); }
.pill-warning { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.pill-error { background: rgba(244, 63, 94, 0.2); color: var(--accent-rose); }

/* Live Log Stream */
.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.log-filters {
  display: flex;
  gap: 0.4rem;
}

.log-filter-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.log-filter-btn:hover, .log-filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.log-box {
  background: #f1f5f9;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 1rem;
  font-family: monospace;
  font-size: 0.85rem;
  max-height: 250px;
  overflow-y: auto;
}

.log-line {
  margin-bottom: 0.4rem;
  line-height: 1.4;
}

.log-time { color: var(--text-muted); margin-right: 0.5rem; }
.log-category { color: var(--accent-cyan); margin-right: 0.5rem; }
.log-msg { color: var(--text-main); }

/* Buttons & Action Badges */
.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.3);
}

.actions-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

/* Preset Chips */
.preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.preset-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-chip:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
}

.preset-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* AI Studio Preview Box */
.preview-box {
  background: #f8fafc;
  border: 1px dashed rgba(99, 102, 241, 0.4);
  border-radius: 12px;
  padding: 1.25rem;
  margin-top: 1rem;
}

.preview-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-cyan);
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.preview-content {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.5;
}

/* Ping Badges */
.ping-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
}

.ping-fast { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.ping-med { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.ping-slow { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); }

/* Toast Notifications System */
#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 0.9rem 1.2rem;
  color: var(--text-main);
  font-size: 0.9rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.3s ease forwards;
}

.toast-success { border-left: 4px solid var(--accent-emerald); }
.toast-error { border-left: 4px solid var(--accent-rose); }
.toast-info { border-left: 4px solid var(--accent-cyan); }

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

@keyframes slideOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}

/* ============================================================
   Responsive / Mobile (Telegram WebApp on phones & tablets)
   ============================================================ */
.hamburger {
  display: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  border-radius: 9px;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-main);
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.hamburger:hover {
  background: rgba(255, 255, 255, 0.14);
}

.hamburger svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.hamburger-float {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1001;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.show {
  opacity: 1;
}

/* Tables scroll horizontally inside panels instead of breaking the layout. */
.panel {
  overflow-x: auto;
}

@media (max-width: 1024px) {
  .content-body { padding: 1.25rem; }
  .metrics-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

@media (max-width: 900px) {
  .hamburger { display: flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    width: min(280px, 82vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 42px rgba(0, 0, 0, 0.65);
    overflow-y: auto;
  }

  .sidebar.open { transform: translateX(0); }

  .main-content { width: 100%; }

  .top-bar {
    padding: 0 1rem;
    gap: 0.75rem;
    height: 62px;
  }

  .top-bar h1 {
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .content-body { padding: 1rem; }
  .panel { padding: 1.1rem; }
  .metrics-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }
  .actions-bar { flex-wrap: wrap; }
  .btn { padding: 0.72rem 1rem; }
  .log-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .toast { max-width: calc(100vw - 2rem); min-width: 0; }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .top-bar h1 { font-size: 0.92rem; }
  .status-badge { font-size: 0.68rem; padding: 0.3rem 0.5rem; gap: 0.35rem; }
  .content-body { padding: 0.75rem; }
  .panel { padding: 0.9rem; border-radius: 14px; }
  .form-input, .form-textarea, .form-select { font-size: 16px; } /* avoid iOS zoom */
  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 0.6rem 0.5rem; }
}

/* ============================================================
   Secondary page component classes
   (autoresponder, scheduler, tracker, spambot, welcome_bot, etc.)
   These were referenced by pages but not defined globally.
   ============================================================ */
.card {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  min-width: 0;
}

.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
}

.form-control {
  width: 100%;
  background: #f8fafc;
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.top-header {
  min-height: 70px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 2rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  gap: 1rem;
}

.page-title {
  min-width: 0;
}

.page-title h1 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-main);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
  line-height: 1.5;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.5px;
}

.logo-text span {
  font-size: 0.72rem;
  color: var(--accent-cyan);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
}

a.nav-item {
  text-decoration: none;
}

.back-btn {
  margin-right: 0.5rem;
  flex-shrink: 0;
}

@media (max-width: 900px) {
  /* Collapse inline 2-column grids (e.g. "1fr 1fr") to a single column. */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .top-header {
    padding: 0.6rem 1rem;
    flex-wrap: wrap;
  }
  .page-title h1 {
    font-size: 1.05rem;
  }
  .card {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .form-control { font-size: 16px; } /* avoid iOS zoom */
  .card { padding: 0.9rem; border-radius: 14px; }
}
