/* ==========================================================================
   main.css — базовая оболочка приложения (Telegram dark)
   Требование: перед этим файлом подключите theme-tg.css с дизайн-токенами.
   ========================================================================== */

:root { color-scheme: dark; }
body {
  background: var(--background-color) !important;
  color: var(--text-primary) !important;
}


/* База */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--background-color);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==========================================================================
   ШАПКА
   ========================================================================== */
.header {
  position: fixed;
  inset-inline: 0;
  top: 0;
  height: 60px;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 20px;
  z-index: 1000;
}

.logo {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Бейдж токенов (кнопка) */
button#tokensBtn.tokens-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 46px;
  height: 36px;
  padding: 0 14px;
  background: var(--surface-color);
  border: none;
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background .2s ease;
  position: relative;
}

button#tokensBtn.tokens-badge:hover {
  background: var(--surface-hover);
}

button#tokensBtn.tokens-badge.low-balance::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: var(--danger-color);
  border-radius: 50%;
}

button#tokensBtn.tokens-badge > #tokenBalance {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
}

/* Аватар */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-color);
  color: var(--primary-color-contrast, #0b0f1a);
  font-weight: 700;
  cursor: pointer;
  position: relative;
}

.header .avatar #avatarInitial {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-color);
  color: var(--primary-color-contrast, #0b0f1a);
  font-weight: 700;
}

/* Дропдаун аватара */
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 10px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px;
  min-width: 200px;
  display: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.dropdown-menu.active { display: block; }

.dropdown-item {
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 14px;
  color: var(--text-primary);
}

.dropdown-item:hover { background: var(--surface-hover); }
.dropdown-item.active {
  background: color-mix(in oklab, var(--primary-color) 16%, transparent);
  color: var(--text-primary);
  font-weight: 600;
}

/* ==========================================================================
   КОНТЕЙНЕР КОНТЕНТА
   ========================================================================== */
.main-container {
  padding: 80px 20px 20px; /* отступ под фикс-шапку */
  max-width: 1200px;
  margin: 0 auto;
}

/* ==========================================================================
   СЕЛЕКТОР ПРОЕКТА (дропдаун + счётчик + кнопка)
   ========================================================================== */
.project-selector {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 30px;
}

.project-dropdown {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 12px 16px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  transition: background 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.project-dropdown:hover {
  background: var(--surface-hover);
  border-color: var(--border-color);
}

.project-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.project-count {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Кнопка создания анализа */
.create-analysis-btn,
#createAnalysisBtn,
#createNewBtn {
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 15px;
  transition: transform 0.18s ease, filter 0.18s ease, opacity 0.18s ease;
  width: 100%;
}

.create-analysis-btn:hover:not(:disabled),
#createAnalysisBtn:hover:not(:disabled),
#createNewBtn:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.create-analysis-btn:disabled,
#createAnalysisBtn:disabled,
#createNewBtn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* Список завершённых проектов (выпадашка) */
.projects-list {
  display: none;
  position: absolute;
  top: 100%;
  inset-inline: 0;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  margin-top: 10px;
  padding: 10px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
}

.projects-list.active { display: block; }

.project-item {
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-primary);
}

.project-item:hover { background: var(--surface-hover); }

.project-date {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ==========================================================================
   СЕТКА КАРТОЧЕК (главные действия)
   ========================================================================== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
  overflow: hidden;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  opacity: 0; /* для анимации появления */
  animation: fadeIn 0.5s ease-out forwards;
}

.card:hover:not(.disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px color-mix(in oklab, var(--primary-color) 22%, transparent);
  border-color: var(--primary-color);
}

.card.disabled {
  opacity: .5;
  cursor: not-allowed;
}

.card.primary {
  border: 1px solid var(--primary-color);
}

.card-icon {
  width: 60px;
  height: 60px;
  margin-bottom: 15px;
  display: grid;
  place-items: center;
  font-size: 30px;
  color: var(--text-primary);
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.card-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Тултип над заблокированной карточкой */
.tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  translate: -50% 0;
  background: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  margin-bottom: 10px;
}

.card.disabled:hover .tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   FAQ (низ страницы)
   ========================================================================== */
.faq-section {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ==========================================================================
   Плейсхолдер-страницы (зарезервировано/в разработке)
   ========================================================================== */
.placeholder-page {
  max-width: 600px;
  margin: 80px auto;
  padding: 40px;
  text-align: center;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  opacity: 0.85;
}

.placeholder-page h1 {
  font-size: 2rem;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.placeholder-page p {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.6;
}

.coming-features {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  margin: 32px 0;
  text-align: left;
}

.coming-features h3 {
  color: var(--text-primary);
  margin-bottom: 16px;
  font-size: 1.2rem;
}

.coming-features ul { list-style: none; padding: 0; margin: 0; }
.coming-features li {
  padding: 8px 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-color);
}
.coming-features li:last-child { border-bottom: none; }

.current-balance {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  margin: 32px 0;
}

.current-balance h3 {
  color: var(--text-primary);
  margin-bottom: 16px;
  font-size: 1.2rem;
}

.balance-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.balance-amount {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
}

.balance-label {
  font-size: 1rem;
  color: var(--text-secondary);
}

.note {
  background: color-mix(in oklab, var(--primary-color) 10%, transparent);
  border: 1px solid var(--primary-color);
  border-radius: 8px;
  padding: 16px;
  margin: 24px 0;
}

.note p {
  color: var(--primary-color);
  margin: 0;
  font-size: 0.92rem;
}

/* ==========================================================================
   АДАПТИВНОСТЬ
   ========================================================================== */
@media (max-width: 1024px) {
  .main-container { padding: 76px 16px 16px; }
}

@media (max-width: 768px) {
  .cards-grid { grid-template-columns: 1fr; }
  .main-container { padding: 70px 15px 15px; }
  .placeholder-page { margin: 40px 20px; padding: 24px; }
  .placeholder-icon { font-size: 3rem; }
  .placeholder-page h1 { font-size: 1.5rem; }
  .balance-amount { font-size: 1.5rem; }
  .dropdown-menu { right: 8px; }
}

/* ==========================================================================
   АНИМАЦИИ
   ========================================================================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Карточки появляются с небольшими задержками */
.card:nth-child(1) { animation-delay: .08s; }
.card:nth-child(2) { animation-delay: .16s; }
.card:nth-child(3) { animation-delay: .24s; }
.card:nth-child(4) { animation-delay: .32s; }
.card:nth-child(5) { animation-delay: .40s; }
.card:nth-child(6) { animation-delay: .48s; }

/* ==========================================================================
   УТИЛИТЫ/МИКСИНЫ ДЛЯ СБОРКИ (минимум, без дублей из theme-tg.css)
   ========================================================================== */

/* Кнопки-ссылки серого тона (вдруг нужны локально) */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  transition: background .2s ease, color .2s ease;
}
.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
/* серые контролы на главной */
.is-disabled,
.is-disabled .btn,
button.is-disabled {
  opacity: 0.6;
  filter: grayscale(18%);
  cursor: not-allowed !important;
  pointer-events: none;
}

.project-label {
  margin: 4px 0 6px;
  font-size: 12px;
  color: var(--muted-foreground, #8b92a0);
}

