
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --radius: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* Навигация */
.nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
  height: 64px;
}
.nav a, .nav button {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: 8px;
  transition: var(--transition);
}
.nav a:hover, .nav button:hover {
  color: var(--primary);
  background: rgba(37,99,235,0.08);
}
.nav .brand {
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
  position: relative;
}
.nav .brand:hover {
  transform: scale(1.05);
  filter: drop-shadow(0 0 8px rgba(37,99,235,0.4));
}
.nav .brand:active {
  transform: scale(0.98);
}
.nav .brand::after {
  content: "❓";
  position: absolute;
  right: -20px;
  top: -4px;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.3s;
}
.nav .brand:hover::after {
  opacity: 1;
}

/* Логотип анимация */
.logo-svg {
  transition: var(--transition);
  cursor: pointer;
}
.logo-svg:hover {
  transform: scale(1.08) rotate(-2deg);
  filter: drop-shadow(0 0 12px rgba(37,99,235,0.5));
}
.logo-svg:active {
  transform: scale(0.95);
}

/* Drawer / Выдвижное меню */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  backdrop-filter: blur(4px);
}
.drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  background: var(--card);
  box-shadow: -10px 0 40px rgba(0,0,0,0.2);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.drawer.open {
  transform: translateX(0);
}
.drawer-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}
.drawer-header h2 { font-size: 1.25rem; font-weight: 700; }
.drawer-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.drawer-close:hover {
  background: var(--border);
  color: var(--text);
}
.drawer-body {
  padding: 24px;
  flex: 1;
}
.drawer-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--primary);
}
.drawer-body h3:first-child { margin-top: 0; }
.drawer-body p, .drawer-body li {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 8px;
}
.drawer-body ol { padding-left: 20px; }
.drawer-body code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}
.drawer-body .step {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: flex-start;
}
.drawer-body .step-num {
  width: 28px;
  height: 28px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}
.drawer-body .step-content {
  flex: 1;
}
.drawer-body .step-content strong {
  color: var(--text);
  font-weight: 600;
}

/* Карточки */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: fadeInUp 0.5s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }
.card h2 { margin-bottom: 20px; font-size: 1.3rem; font-weight: 700; }

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

/* Формы */
input, select, button.btn, textarea {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  width: 100%;
  margin-bottom: 14px;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
button.btn {
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}
button.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
button.btn.danger { background: var(--danger); }
button.btn.success { background: var(--success); }
button.btn.warning { background: var(--warning); color: #000; }
button.btn.small { width: auto; padding: 8px 14px; font-size: 0.85rem; }
button.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* API Key блок */
.key-block {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg) 100%);
  border: 2px dashed var(--primary);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  margin: 16px 0;
  animation: pulseBorder 2s infinite;
}
@keyframes pulseBorder {
  0%, 100% { border-color: var(--primary); }
  50% { border-color: var(--primary-dark); }
}
.key-value {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-dark);
  word-break: break-all;
  margin: 12px 0;
  user-select: all;
}

/* Dropdown */
.dropdown {
  position: relative;
  display: inline-block;
  width: 100%;
}
.dropdown-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  max-height: 250px;
  overflow-y: auto;
}
.dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.dropdown-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--primary-light); }
.dropdown-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.dropdown-item .key-preview { font-family: monospace; color: var(--text-secondary); }
.dropdown-empty { padding: 16px; text-align: center; color: var(--text-secondary); font-size: 0.9rem; }

/* Тосты */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.toast {
  background: var(--card);
  border-left: 4px solid var(--primary);
  padding: 16px 20px;
  border-radius: 10px;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.2);
  min-width: 300px;
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateX(100%); }
}

/* Лоадер */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-loader {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  backdrop-filter: blur(4px);
}

/* Drag & Drop */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
  color: var(--text-secondary);
  transition: all 0.3s;
  background: rgba(37,99,235,0.02);
  cursor: pointer;
}
.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(37,99,235,0.08);
  color: var(--primary);
  transform: scale(1.02);
}

/* Таблица */
table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 16px; }
th, td { text-align: left; padding: 14px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
tr:hover td { background: rgba(37,99,235,0.03); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.badge.queued { background: #fef3c7; color: #92400e; }
.badge.processing { background: #dbeafe; color: #1e40af; }
.badge.completed { background: #d1fae5; color: #065f46; }
.badge.error { background: #fee2e2; color: #991b1b; }

/* JSON */
pre.json {
  background: #0f172a;
  color: #e2e8f0;
  padding: 20px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* Сетка */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }

/* Утилиты */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.flex { display: flex; gap: 12px; align-items: center; }
.flex-col { flex-direction: column; align-items: stretch; }
.grow { flex-grow: 1; }
.text-sm { font-size: 0.875rem; color: var(--text-secondary); }
.text-red { color: var(--danger); }
.text-green { color: var(--success); }
.text-center { text-align: center; }

/* Тема переключатель */
.theme-toggle {
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  background: var(--border);
  border: none;
  font-size: 1.2rem;
  transition: var(--transition);
}
.theme-toggle:hover {
  transform: rotate(15deg) scale(1.1);
}

@media (max-width: 768px) {
  .container { padding: 16px; }
  .nav { padding: 0 16px; gap: 12px; height: 56px; }
  .nav a, .nav button { font-size: 0.85rem; padding: 6px 8px; }
  table { font-size: 0.85rem; }
  th, td { padding: 10px; }
  .grid { grid-template-columns: 1fr; }
  .drawer { max-width: 100%; }
}
