/* ============================================================
   SEOADVANCED — Telegram AI Digest
   Дизайн в стиле godly.design/markopolo, акцент — violet.
   ============================================================ */

:root {
  /* Background layers */
  --bg-base:       #0a0a0f;
  --bg-elevated:   #11111a;
  --bg-surface:    rgba(255, 255, 255, 0.03);
  --bg-surface-2:  rgba(255, 255, 255, 0.05);
  --bg-hover:      rgba(255, 255, 255, 0.07);

  /* Violet accent (Tailwind violet-500 / 600 / 400) */
  --violet-400:    #a78bfa;
  --violet-500:    #8b5cf6;
  --violet-600:    #7c3aed;
  --violet-700:    #6d28d9;
  --violet-glow:   rgba(139, 92, 246, 0.35);
  --violet-soft:   rgba(139, 92, 246, 0.12);

  /* Text */
  --text-primary:   #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted:     #71717a;

  /* Lines */
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* Status */
  --success: #34d399;
  --warning: #fbbf24;
  --danger:  #f87171;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;
}

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

html, body { min-height: 100%; }

body {
  font-family: 'Inter', 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  background-image:
    radial-gradient(1100px 600px at 12% -10%, rgba(124, 58, 237, 0.22), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(139, 92, 246, 0.16), transparent 65%),
    radial-gradient(800px 500px at 50% 120%, rgba(109, 40, 217, 0.18), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  overflow-x: hidden;
}

/* Decorative grid / noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 35%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 30%, #000 35%, transparent 75%);
  z-index: 0;
}

/* ============= Site header ============= */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 64px;
  background: rgba(10, 10, 15, 0.65);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 36px;
}

.site-logo {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-decoration: none;
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.site-logo::before {
  content: '';
  width: 22px; height: 22px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 30% 30%, #c4b5fd, transparent 55%),
    linear-gradient(135deg, var(--violet-500), var(--violet-700));
  box-shadow: 0 0 18px var(--violet-glow), inset 0 0 0 1px rgba(255,255,255,0.15);
}

.site-nav { flex: 1; }

.nav-root {
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
}

.nav-item { position: relative; }

.nav-link {
  display: inline-flex;
  align-items: center;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.01em;
  text-transform: none;
  padding: 9px 16px;
  border-radius: 999px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color .18s ease, background .18s ease;
  cursor: pointer;
}

.nav-link:hover { color: var(--text-primary); background: var(--bg-hover); }

.nav-link.active {
  color: var(--text-primary);
  background: var(--violet-soft);
  box-shadow: inset 0 0 0 1px rgba(139,92,246,0.35);
}

/* Dropdown */
.nav-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 230px;
  margin: 0;
  padding: 8px;
  list-style: none;
  background: rgba(17, 17, 26, 0.92);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    0 4px 12px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255,255,255,0.05);

  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .18s ease, transform .18s ease, visibility .18s;
}

.nav-item.has-dropdown:hover > .nav-dropdown,
.nav-item.has-dropdown:focus-within > .nav-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-dropdown li a {
  display: block;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  transition: color .12s, background .12s;
}

.nav-dropdown li a:hover {
  color: var(--text-primary);
  background: var(--violet-soft);
}

.has-dropdown > .nav-link::after {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  opacity: 0.55;
}

@media (max-width: 720px) {
  .site-header { padding: 0 16px; gap: 14px; height: 56px; }
  .nav-link { padding: 7px 12px; font-size: 12px; }
  .nav-dropdown { min-width: 190px; }
}

/* ============= Layout ============= */
.container {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 44px 24px 64px;
}

h1 {
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: clamp(28px, 4.2vw, 44px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.035em;
  margin-bottom: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #c4b5fd 60%, #8b5cf6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

h1::after {
  content: '';
  display: block;
  width: 56px; height: 3px;
  margin-top: 18px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--violet-500), transparent);
}

h2 {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

h3 {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ============= Cards (glassmorphism) ============= */
.card {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.015));
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.04) inset,
    0 30px 60px -30px rgba(0, 0, 0, 0.6);
  transition: border-color .25s ease, transform .25s ease, box-shadow .25s ease;
}

.card:hover {
  border-color: var(--border-strong);
}

/* subtle gradient ring on hover */
.card::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(139,92,246,0.45), transparent 40%, transparent 60%, rgba(139,92,246,0.25));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.card:hover::after { opacity: 1; }

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

/* ============= Table ============= */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
thead th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--border-strong);
  background: rgba(255,255,255,0.015);
}
thead th:first-child { border-top-left-radius: var(--r-sm); }
thead th:last-child  { border-top-right-radius: var(--r-sm); }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(139, 92, 246, 0.05); }
tbody tr:last-child td { border-bottom: none; }

/* ============= Buttons ============= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.005em;
  transition: background .18s, border-color .18s, transform .12s, box-shadow .2s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: rgba(255,255,255,0.22); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, var(--violet-500), var(--violet-600));
  border-color: transparent;
  color: #ffffff;
  box-shadow:
    0 6px 16px -4px var(--violet-glow),
    inset 0 1px 0 rgba(255,255,255,0.22);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #9b73f9, var(--violet-500));
  box-shadow:
    0 10px 24px -6px var(--violet-glow),
    inset 0 1px 0 rgba(255,255,255,0.28);
}

.btn-success {
  background: linear-gradient(180deg, var(--violet-500), var(--violet-700));
  border-color: transparent;
  color: #ffffff;
  box-shadow:
    0 8px 22px -6px var(--violet-glow),
    inset 0 1px 0 rgba(255,255,255,0.22);
  padding: 8px 18px;
  font-weight: 600;
}
.btn-success:hover {
  filter: brightness(1.08);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }

/* ============= Modal ============= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 10, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn .18s ease;
}
.modal.hidden { display: none; }

.modal-box {
  background: linear-gradient(180deg, rgba(28,28,40,0.96), rgba(17,17,26,0.96));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  padding: 28px;
  width: 420px;
  box-shadow:
    0 30px 80px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.06);
  animation: rise .22s cubic-bezier(.2,.7,.2,1);
}
.modal-box h3 { margin-bottom: 18px; }

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

/* ============= Forms ============= */
label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

label input[type=text],
label input[type=password],
label input[type=date] {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
label input[type=text]:focus,
label input[type=password]:focus,
label input[type=date]:focus {
  outline: none;
  border-color: var(--violet-500);
  background: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 4px var(--violet-soft);
}

.checkbox-label {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  cursor: pointer;
}
.checkbox-label input[type=checkbox] {
  width: 16px; height: 16px;
  accent-color: var(--violet-500);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  justify-content: flex-end;
}

/* ============= Run row ============= */
.run-row {
  display: flex;
  gap: 18px;
  align-items: flex-end;
  margin-top: 14px;
  flex-wrap: wrap;
}
.run-row label { margin-bottom: 0; min-width: 160px; }

/* ============= Log output ============= */
#log-output {
  font-family: 'JetBrains Mono', 'Cascadia Code', ui-monospace, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  max-height: 360px;
  overflow-y: auto;
  padding: 16px 18px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-top: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
#log-output::-webkit-scrollbar { width: 8px; }
#log-output::-webkit-scrollbar-thumb { background: var(--violet-soft); border-radius: 4px; }

.log-fetch   { color: #93c5fd; }
.log-cluster { color: var(--violet-400); }
.log-write   { color: #6ee7b7; }
.log-error   { color: #fca5a5; }
.log-done    { color: #fcd34d; font-weight: 600; }

/* ============= Badges =============
   JS вешает классы badge-active / badge-inactive прямо на <td>,
   поэтому сбрасываем фон ячейки и рисуем inline-бейдж через ::before.
   Исходный текст ячейки (✓ / ✗) скрываем через font-size: 0. */
td.badge-active,
td.badge-inactive {
  font-size: 0;            /* прячем символ ✓/✗ из JS */
  background: transparent !important;
  box-shadow: none !important;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}
td.badge-active::before,
td.badge-inactive::before {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0;
}
td.badge-active::before {
  content: '● Активен';
  color: #a7f3d0;
  background: rgba(52, 211, 153, 0.12);
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.32);
}
td.badge-inactive::before {
  content: '○ Неактивен';
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  box-shadow: inset 0 0 0 1px var(--border);
}

/* ============= Scrollbars ============= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.25);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.45); }

/* ============= Login screen ============= */
.login-shell {
  min-height: calc(100vh - 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  position: relative;
  z-index: 1;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 36px 32px 32px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow:
    0 40px 90px -20px rgba(0,0,0,0.6),
    0 0 0 1px rgba(139,92,246,0.08),
    inset 0 1px 0 rgba(255,255,255,0.06);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 220px; height: 220px;
  background: radial-gradient(circle, var(--violet-glow), transparent 70%);
  pointer-events: none;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 12px;
  color: var(--text-secondary);
}
.login-brand::before {
  content: '';
  width: 22px; height: 22px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 30% 30%, #c4b5fd, transparent 55%),
    linear-gradient(135deg, var(--violet-500), var(--violet-700));
  box-shadow: 0 0 18px var(--violet-glow), inset 0 0 0 1px rgba(255,255,255,0.15);
}

.login-title {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 4px 0 22px;
  background: linear-gradient(180deg, #fff, #c4b5fd);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-error {
  margin-bottom: 14px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fecaca;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 10px;
}

/* ============= Animations on load ============= */
.container > * {
  animation: fadeUp .5s cubic-bezier(.2,.7,.2,1) backwards;
}
.container > *:nth-child(1) { animation-delay: 0.02s; }
.container > *:nth-child(2) { animation-delay: 0.08s; }
.container > *:nth-child(3) { animation-delay: 0.14s; }
.container > *:nth-child(4) { animation-delay: 0.20s; }
.container > *:nth-child(5) { animation-delay: 0.26s; }

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

/* ============= Logout button ============= */
.nav-logout {
  margin-left: auto;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.nav-logout:hover {
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

/* ============= Admin nav link ============= */
.nav-link-admin {
  color: var(--violet-400);
}
.nav-link-admin:hover { color: var(--violet-400); }
.nav-link-admin.active {
  color: var(--violet-400);
  background: var(--violet-soft);
}

/* ============= Home dashboard ============= */
.home-dashboard {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.widgets-row {
  display: flex;
  flex-direction: row;
  gap: 16px;
  flex-wrap: wrap;
}

.home-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  opacity: 0.35;
  text-align: center;
}
.home-placeholder-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}
.home-placeholder-sub {
  font-size: 15px;
  color: var(--text-secondary);
}

/* ============= OpenRouter balance card ============= */
.balance-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(135deg, rgba(139,92,246,0.08), rgba(17,17,26,0.6));
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: var(--r-lg);
  padding: 20px 24px;
  max-width: 420px;
  position: relative;
  overflow: hidden;
}
.balance-card::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 140px; height: 140px;
  background: radial-gradient(circle, rgba(139,92,246,0.18), transparent 70%);
  pointer-events: none;
}
.balance-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.balance-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.balance-remaining {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}
.balance-currency {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}
.balance-status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}
.balance-status.ok {
  background: rgba(52, 211, 153, 0.1);
  color: #6ee7b7;
  box-shadow: inset 0 0 0 1px rgba(52,211,153,0.2);
}
.balance-status.error {
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
  box-shadow: inset 0 0 0 1px rgba(248,113,113,0.2);
}
.balance-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.balance-key-info {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  opacity: 0.65;
}

/* ============= Utility ============= */
.text-muted { color: var(--text-muted); font-size: 12px; }
.link { color: var(--violet-400); text-decoration: none; }
.link:hover { text-decoration: underline; }

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 6px;
}

.actions-cell { white-space: nowrap; }
.services-cell { max-width: 300px; }

.badge-violet {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--violet-soft);
  color: var(--violet-400);
  box-shadow: inset 0 0 0 1px rgba(139,92,246,0.3);
  margin: 2px 3px 2px 0;
}

.form-group {
  margin-bottom: 14px;
}
.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.checkboxes-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
