/* ─────────────────────────────────────────────────────────────────────────────
   WB Analytics Mini App — Базовые стили
   
   Принципы:
     1. Цвета ТОЛЬКО через CSS-переменные Telegram var(--tg-theme-*)
     2. Размеры в rem (базовый 16px) для масштабируемости
     3. Лейаут через flexbox — поддержка всех платформ
     4. Safe area учтена для fullscreen-режима
     5. Анимации — только transform и opacity (GPU-ускорение)
   ───────────────────────────────────────────────────────────────────────────── */

/* ── CSS Reset ──────────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9375rem; /* 15px — стандарт Telegram */
    line-height: 1.5;
    color: var(--tg-theme-text-color, #000000);
    background-color: var(--tg-theme-bg-color, #ffffff);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: var(--tg-viewport-stable-height, 100vh);
}

a {
    color: var(--tg-theme-link-color, #2678b6);
    text-decoration: none;
}

a:active {
    opacity: 0.7;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
    border: none;
    outline: none;
    background: none;
}

ul, ol {
    list-style: none;
}

/* ── Корневой контейнер SPA ─────────────────────────────────────────────────── */

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: var(--tg-viewport-stable-height, 100vh);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Контейнер страницы (каждый экран) ──────────────────────────────────────── */

.page {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    animation: pageIn 0.2s ease-out;
}

@keyframes pageIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Загрузочный экран ──────────────────────────────────────────────────────── */

.loading-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    min-height: 60vh;
}

.loading-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--tg-theme-secondary-bg-color, #e0e0e0);
    border-top-color: var(--tg-theme-button-color, #2678b6);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 0.875rem;
    color: var(--tg-theme-hint-color, #999999);
}

/* ── Типографика ────────────────────────────────────────────────────────────── */

.page-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--tg-theme-text-color, #000000);
    margin-bottom: 0.25rem;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--tg-theme-hint-color, #999999);
    margin-bottom: 1.25rem;
}

.section-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--tg-theme-hint-color, #999999);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
    margin-top: 1.25rem;
}

.text-hint {
    font-size: 0.8125rem;
    color: var(--tg-theme-hint-color, #999999);
    line-height: 1.4;
}

.text-bold {
    font-weight: 600;
}

.text-center {
    text-align: center;
}

.text-success {
    color: #34c759;
}

.text-danger {
    color: #ff3b30;
}

.text-warning {
    color: #ff9500;
}

/* ── Секции контента ────────────────────────────────────────────────────────── */

.content-section {
    margin-bottom: 1.25rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

/* ── Разделитель ────────────────────────────────────────────────────────────── */

.divider {
    height: 1px;
    background-color: var(--tg-theme-secondary-bg-color, #e0e0e0);
    margin: 1rem 0;
}

/* ── Пустое состояние ───────────────────────────────────────────────────────── */

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem 1rem;
    text-align: center;
}

.empty-state-icon {
    font-size: 3rem;
    line-height: 1;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--tg-theme-text-color, #000000);
}

.empty-state-text {
    font-size: 0.875rem;
    color: var(--tg-theme-hint-color, #999999);
    max-width: 280px;
}

/* ── Сообщения (ошибки, успех, информация) ──────────────────────────────────── */

.message {
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.4;
    margin-bottom: 1rem;
}

.message-error {
    background-color: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
}

.message-success {
    background-color: rgba(52, 199, 89, 0.1);
    color: #34c759;
}

.message-info {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
}

.message-warning {
    background-color: rgba(255, 149, 0, 0.1);
    color: #ff9500;
}

/* ── Скелетон (загрузка данных) ─────────────────────────────────────────────── */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--tg-theme-secondary-bg-color, #e0e0e0) 25%,
        var(--tg-theme-bg-color, #f0f0f0) 50%,
        var(--tg-theme-secondary-bg-color, #e0e0e0) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 0.5rem;
}

.skeleton-text {
    height: 0.875rem;
    margin-bottom: 0.5rem;
    width: 100%;
}

.skeleton-text-short {
    width: 60%;
}

.skeleton-block {
    height: 3.5rem;
    margin-bottom: 0.75rem;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Утилитарные классы ─────────────────────────────────────────────────────── */

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.flex-row {
    display: flex;
    align-items: center;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-1 {
    flex: 1;
}

.hidden {
    display: none !important;
}

.visible {
    display: block;
}

/* ── Скроллбар (тонкий, в стиле Telegram) ──────────────────────────────────── */

::-webkit-scrollbar {
    width: 3px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--tg-theme-hint-color, #cccccc);
    border-radius: 3px;
}

/* ── Выделение текста ───────────────────────────────────────────────────────── */

::selection {
    background-color: var(--tg-theme-button-color, #2678b6);
    color: var(--tg-theme-button-text-color, #ffffff);
}

/* ── Анимация появления элементов ───────────────────────────────────────────── */

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
