/* === MAGIC.CSS ===
 * /assets/css/magic.css
 * НАЗНАЧЕНИЕ: Magic Stack 2026 улучшения — View Transitions, content-visibility, focus-visible
 * СВЯЗИ: index.php, всё SPA
 * РАЗМЕР: ~120 строк
 */

/* ============================================
 * 1. View Transitions API — плавные переходы между вкладками
 * ============================================ */

@view-transition {
    navigation: auto;
}

::view-transition-old(root) {
    animation: vt-fade-out 180ms cubic-bezier(0.4, 0, 1, 1);
}

::view-transition-new(root) {
    animation: vt-fade-in 220ms cubic-bezier(0, 0, 0.2, 1);
}

@keyframes vt-fade-out {
    to { opacity: 0; transform: translateY(-4px); }
}

@keyframes vt-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Fallback анимация для браузеров без View Transitions */
.page-content.active {
    animation: page-enter 240ms cubic-bezier(0, 0, 0.2, 1);
}

@keyframes page-enter {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
 * 2. content-visibility для длинных списков
 * ============================================ */

.feature-card,
.course-step,
.card-item,
.lesson-card,
.meditation-card,
.sutra-card,
.habit-card {
    content-visibility: auto;
    contain-intrinsic-size: auto 200px;
}

/* ============================================
 * 3. Accessibility: focus-visible (keyboard only)
 * ============================================ */

*:focus-visible {
    outline: 2px solid oklch(0.85 0.15 85);
    outline-offset: 3px;
    border-radius: 4px;
}

button:focus,
a:focus,
input:focus,
textarea:focus,
select:focus {
    outline: none;
}

button:focus-visible,
a:focus-visible {
    box-shadow: 0 0 0 3px oklch(0.85 0.15 85 / 0.4);
}

/* ============================================
 * 4. prefers-reduced-motion — accessibility
 * ============================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

html {
    scroll-behavior: smooth;
}

/* ============================================
 * 5. Native <dialog> базовая стилизация
 * ============================================ */

dialog.aci-dialog {
    border: 1px solid oklch(1 0 0 / 0.12);
    border-radius: 16px;
    padding: 32px;
    max-width: 480px;
    width: calc(100% - 40px);
    background: oklch(0.16 0.02 270);
    color: oklch(0.96 0.01 80);
    box-shadow: 0 30px 80px oklch(0 0 0 / 0.6);

    /* Анимация появления */
    opacity: 1;
    transform: scale(1);
    transition:
        opacity 0.25s ease,
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        overlay 0.25s allow-discrete,
        display 0.25s allow-discrete;
}

@starting-style {
    dialog.aci-dialog[open] {
        opacity: 0;
        transform: scale(0.94);
    }
}

dialog.aci-dialog::backdrop {
    background: oklch(0.05 0.01 270 / 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition:
        background 0.25s ease,
        backdrop-filter 0.25s ease,
        overlay 0.25s allow-discrete,
        display 0.25s allow-discrete;
}

@starting-style {
    dialog.aci-dialog[open]::backdrop {
        background: transparent;
        backdrop-filter: blur(0);
    }
}

dialog.aci-dialog h2 {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 500;
    font-size: 28px;
    margin-bottom: 12px;
    color: oklch(0.85 0.15 85);
}

dialog.aci-dialog p {
    font-size: 16px;
    line-height: 1.6;
    color: oklch(0.85 0.02 80);
    margin-bottom: 24px;
}

dialog.aci-dialog form {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

dialog.aci-dialog button {
    padding: 12px 24px;
    border-radius: 999px;
    border: 1px solid oklch(1 0 0 / 0.15);
    background: transparent;
    color: oklch(0.85 0.02 80);
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s ease;
}

dialog.aci-dialog button:hover {
    background: oklch(1 0 0 / 0.06);
    border-color: oklch(1 0 0 / 0.25);
}

dialog.aci-dialog button.primary {
    background: linear-gradient(135deg, oklch(0.85 0.15 85), oklch(0.72 0.16 55));
    color: oklch(0.15 0.02 270);
    border-color: transparent;
    font-weight: 600;
}

dialog.aci-dialog button.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 30px oklch(0.85 0.15 85 / 0.3);
}

dialog.aci-dialog button.danger {
    background: linear-gradient(135deg, oklch(0.65 0.20 25), oklch(0.55 0.22 25));
    color: white;
    border-color: transparent;
    font-weight: 600;
}

/* ============================================
 * 6. LOGO WHEEL в navbar — магическое мини-колесо для всех страниц
 * ============================================ */

.navbar-brand {
    display: inline-flex !important;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.navbar-brand .logo-icon { display: none !important; }

.logo-wheel {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px oklch(0.85 0.18 70 / 0.45));
    transition: filter 0.4s ease, transform 0.4s ease;
}

.logo-wheel-rotate {
    transform-origin: center;
    animation: logo-wheel-spin 30s linear infinite;
}

.navbar-brand:hover .logo-wheel {
    filter: drop-shadow(0 0 14px oklch(0.85 0.20 70 / 0.75));
    transform: scale(1.08);
}

.navbar-brand:hover .logo-wheel-rotate {
    animation-duration: 6s;
}

@keyframes logo-wheel-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .logo-wheel-rotate { animation: none; }
}


/* ============================================
 * 7. ЕДИНЫЙ СТИЛЬ ВСЕГО КАБИНЕТА
 * ============================================ */

/* Заголовки — Cormorant Garamond */
.page-title,
.page-content h1,
.page-content h2,
.page-content h3,
.section-title,
.card-title {
    font-family: 'Cormorant Garamond', Georgia, serif !important;
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* Текст — Crimson Text */
body,
.page-content,
.page-description,
.card-body,
.habit-meta,
.text-muted,
p {
    font-family: 'Crimson Text', Georgia, serif;
}

/* UI — sans-serif */
.btn,
button,
.filter-btn,
.badge,
.chip,
.stat-mini,
input,
textarea,
select,
.form-input,
.form-textarea,
.nav-link {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Брендовое название = серифом */
.navbar-brand .logo-text {
    font-family: 'Cormorant Garamond', Georgia, serif !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    letter-spacing: -0.01em !important;
    white-space: nowrap !important;
    color: var(--text-primary, #E8E8E8) !important;
    line-height: 1.2 !important;
    display: inline !important;
}

/* На гостевом лендинге navbar всегда тёмный — фиксируем светлый логотип
   независимо от light/dark темы, поскольку фон лендинга всегда тёмный */
body:not(.authenticated) .navbar-brand .logo-text {
    color: oklch(0.96 0.01 80) !important;
}

/* Скрываем переключатель темы на гостевом лендинге — на нём всегда
   художественный тёмный фон, переключение вводит в заблуждение */
body:not(.authenticated) #aci-theme-toggle,
body:not(.authenticated) .aci-theme-btn {
    display: none !important;
}

/* ============================================
 * АРТ-КАРТА JOURNEY — всегда тёмный фон, светлый текст
 * Работает в обеих темах. Космос с золотом — фиксированный стиль.
 * ============================================ */

.journey-map-container,
.journey-map-container.style-night {
    color: #E8E8E8;
}

.journey-map-container .stat-value,
.journey-stats-panel .stat-value {
    color: #FFD54A !important;
}

.journey-map-container .stat-label,
.journey-stats-panel .stat-label,
.journey-map-container .stats-label,
.journey-stats-panel .stats-label {
    color: rgba(255, 255, 255, 0.7) !important;
}

.journey-map-container .stats-value,
.journey-stats-panel .stats-value {
    color: #FFD54A !important;
}

/* Заголовок карты "Путь Бодхисаттвы" */
.journey-map-container .journey-title,
.journey-map-container h1,
.journey-map-container h2,
.journey-map-container h3 {
    color: #FFFFFF !important;
}

.journey-map-container .journey-subtitle,
.journey-map-container .subtitle {
    color: rgba(255, 255, 255, 0.75) !important;
}

/* Метки ACI-1...ACI-18 на станциях */
.journey-map-container .aci-label,
.journey-map-container .station-label,
.journey-map-container .location-label {
    color: #FFD54A !important;
    background: rgba(0, 0, 0, 0.6) !important;
}

@media (max-width: 768px) {
    .navbar-brand .logo-text { font-size: 16px !important; }
    .logo-wheel { width: 26px !important; height: 26px !important; }
}

/* ============================================
 * 8. NAVBAR — flex с гарантией непересечения
 * ============================================ */

body.authenticated .navbar {
    padding: 8px 0;
    position: relative;
    z-index: 100;
    overflow: visible;
}

body.authenticated .navbar .container {
    max-width: 100% !important;
    padding: 0 16px !important;
}

body.authenticated .navbar-content {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    width: 100%;
    flex-wrap: nowrap !important;
}

/* === LOGO (brand) === */
body.authenticated .navbar-brand {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
    max-width: 200px;
    overflow: hidden;
}

body.authenticated .navbar-brand .logo-text {
    font-size: 16px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap !important;
}

/* === MENU — растягивается, может сжиматься === */
body.authenticated .nav-menu[data-auth="user"] {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    display: flex !important;
    align-items: center;
    flex-wrap: nowrap !important;
    gap: 1px;
    justify-content: flex-start;
    overflow: hidden !important;
}

body.authenticated .nav-link {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    padding: 7px 8px !important;
    border-radius: 8px;
    font-size: 13px !important;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap !important;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease;
    background: transparent;
    border: none !important;
    line-height: 1;
}

body.authenticated .nav-link span {
    white-space: nowrap !important;
}

body.authenticated .nav-link:hover {
    color: var(--text-primary);
    background: oklch(1 0 0 / 0.05);
}

html.light-theme body.authenticated .nav-link:hover {
    background: oklch(0 0 0 / 0.04);
}

body.authenticated .nav-link.active {
    color: oklch(0.85 0.15 85) !important;
    background: oklch(0.85 0.15 85 / 0.10);
}

body.authenticated .nav-link .icon {
    width: 15px !important;
    height: 15px !important;
    flex-shrink: 0;
}

/* AI кнопка в .mobile-only внутри nav-menu — скрываем на desktop (есть отдельная) */
body.authenticated .nav-link.mobile-only {
    display: none !important;
}

/* === THEME TOGGLE — фиксированный === */
body.authenticated #aci-theme-toggle,
body.authenticated .aci-theme-btn {
    flex: 0 0 32px !important;
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* === USER MENU — фиксированный === */
body.authenticated .user-menu {
    flex: 0 0 auto !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

body.authenticated .user-menu .nav-link {
    display: inline-flex !important;
}

body.authenticated .user-dropdown {
    flex-shrink: 0;
}

body.authenticated .user-dropdown-toggle {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 4px 8px !important;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    border-radius: 8px;
    transition: background 0.2s ease;
}

body.authenticated .user-dropdown-toggle:hover {
    background: oklch(1 0 0 / 0.06);
}

html.light-theme body.authenticated .user-dropdown-toggle:hover {
    background: oklch(0 0 0 / 0.04);
}

body.authenticated .user-avatar img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: block;
}

body.authenticated .user-name {
    font-size: 13px !important;
    white-space: nowrap;
    color: var(--text-primary);
}

body.authenticated .subscription-badge {
    font-size: 9px !important;
    padding: 2px 6px !important;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

body.authenticated .subscription-badge.premium {
    background: oklch(0.85 0.15 85);
    color: oklch(0.15 0.02 270);
}

body.authenticated .subscription-badge.free {
    background: oklch(0.5 0 0 / 0.2);
    color: var(--text-secondary);
}

/* === ADAPTIVE — скрываем подписи кроме топ-6 пунктов === */

/* Базово: Brain, Транскрипты, Помощь, Учителя, Вдохновение — всегда иконки */
body.authenticated .nav-link[data-page="brain"] span,
body.authenticated .nav-link[data-page="transcripts"] span,
body.authenticated .nav-link[data-page="charity"] span,
body.authenticated .nav-link[data-page="teachers"] span,
body.authenticated .nav-link[data-page="inspiration"] span {
    display: none;
}

@media (max-width: 1500px) {
    body.authenticated .nav-link[data-page="journey"] span,
    body.authenticated .nav-link[data-page="sutras"] span,
    body.authenticated .nav-link[data-page="glossary"] span {
        display: none;
    }
}

@media (max-width: 1180px) {
    body.authenticated .nav-link[data-page="meditation"] span {
        display: none;
    }
    body.authenticated .user-name,
    body.authenticated .subscription-badge {
        display: none !important;
    }
}

@media (max-width: 1080px) {
    body.authenticated .nav-link[data-page="habits"] span {
        display: none;
    }
    body.authenticated .navbar-brand .logo-text {
        display: none !important;
    }
}

@media (max-width: 980px) {
    body.authenticated .nav-link span {
        display: none;
    }
    body.authenticated .nav-link {
        padding: 8px 9px !important;
    }
    body.authenticated .nav-link .icon {
        width: 17px !important;
        height: 17px !important;
    }
}

/* Mobile <768px: меню переходит на 2 строку */
@media (max-width: 768px) {
    body.authenticated .navbar-content {
        flex-wrap: wrap !important;
        gap: 8px;
    }
    body.authenticated .nav-menu[data-auth="user"] {
        order: 99;
        flex: 1 1 100% !important;
        padding: 6px 0;
        margin-top: 6px;
        border-top: 1px solid var(--border-color);
        overflow-x: auto !important;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        justify-content: flex-start;
    }
    body.authenticated .nav-menu[data-auth="user"]::-webkit-scrollbar {
        display: none;
    }
    body.authenticated .navbar-brand .logo-text {
        display: inline !important;
    }
}

/* === FIX: loading placeholder на тёмном фоне === */
body.authenticated .loading-placeholder,
body.authenticated #teachers-content,
body.authenticated #charity-content,
body.authenticated #glossary-content,
body.authenticated #journey-content,
body.authenticated #inspiration-content {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary);
}

body.authenticated .loading-placeholder p {
    color: var(--text-muted) !important;
}

/* === FIX: глобальный #loader не должен мигать белым на dark === */
html:not(.light-theme) #loader,
html:not(.light-theme) .loader {
    background: rgba(15, 15, 15, 0.92) !important;
}

html:not(.light-theme) #loader .loader-spinner,
html:not(.light-theme) .loader .loader-spinner {
    border-color: rgba(255, 255, 255, 0.1);
    border-top-color: var(--color-gold, #FFD54A);
}

/* ============================================
 * 9. TELEGRAM BANNER — тёмный в dark теме
 * ============================================ */

html:not(.light-theme) .telegram-banner,
html:not(.light-theme) .telegram-connect-banner,
html:not(.light-theme) [class*="telegram"] {
    background: linear-gradient(135deg, oklch(0.18 0.02 270), oklch(0.14 0.02 265)) !important;
    border: 1px solid oklch(0.55 0.15 250 / 0.3) !important;
    color: var(--text-primary) !important;
}

html:not(.light-theme) .telegram-banner *,
html:not(.light-theme) .telegram-connect-banner * {
    color: var(--text-primary);
}

html:not(.light-theme) .telegram-banner .btn,
html:not(.light-theme) .telegram-connect-banner .btn {
    background: oklch(0.55 0.15 250) !important;
    color: white !important;
    border: none !important;
}