/* ============================================
   ФАЗА 8 — PREMIUM DESIGN SYSTEM
   Единые стандарты: glow-эффекты, анимации,
   светлая тема, mobile-first утилиты
   ============================================ */

/* ============================================
   1. PREMIUM ПЕРЕМЕННЫЕ (дополнение к design-system.css)
   ============================================ */
:root {
    /* Glow / Neon эффекты */
    --glow-accent: 0 0 20px rgba(102, 126, 234, 0.25);
    --glow-success: 0 0 20px rgba(16, 185, 129, 0.25);
    --glow-danger: 0 0 20px rgba(239, 68, 68, 0.25);
    --glow-warning: 0 0 20px rgba(245, 158, 11, 0.25);

    /* Функциональные фоны */
    --success-bg: rgba(16, 185, 129, 0.08);
    --warning-bg: rgba(245, 158, 11, 0.08);
    --danger-bg: rgba(239, 68, 68, 0.08);
    --info-bg: rgba(59, 130, 246, 0.08);

    /* Glass-эффект */
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-bg-hover: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-border-hover: rgba(255, 255, 255, 0.12);
    --glass-blur: blur(12px);

    /* Z-index система */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 300;
    --z-popover: 400;
    --z-toast: 500;
}

/* ============================================
   2. GLASS-КАРТОЧКИ (premium стиль)
   ============================================ */
.glass-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl, 16px);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    transition: all var(--transition-base, 200ms ease);
    overflow: hidden;
}

.glass-card:hover {
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg, 0 10px 15px rgba(0,0,0,0.1));
}

.glass-card-glow {
    box-shadow: var(--glow-accent);
}

/* ============================================
   3. КНОПКИ — PREMIUM ВАРИАНТЫ
   ============================================ */
.btn-glow {
    background: var(--grad-brand, linear-gradient(135deg, #667eea, #764ba2));
    color: #fff;
    border: none;
    border-radius: var(--radius-md, 8px);
    padding: var(--space-3, 12px) var(--space-6, 24px);
    font-weight: var(--font-weight-semibold, 600);
    box-shadow: var(--glow-accent);
    transition: all var(--transition-fast, 150ms ease);
}

.btn-glow:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px rgba(102, 126, 234, 0.4);
    color: #fff;
}

.btn-success-glow {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: var(--glow-success);
}

.btn-success-glow:hover {
    box-shadow: 0 0 30px rgba(16, 185, 129, 0.4);
}

.btn-danger-outline {
    background: var(--danger-bg);
    border: 1px solid var(--color-accent-error, #ef4444);
    color: var(--color-accent-error, #ef4444);
    border-radius: var(--radius-md, 8px);
    padding: var(--space-3, 12px) var(--space-6, 24px);
    transition: all var(--transition-fast, 150ms ease);
}

.btn-danger-outline:hover {
    background: var(--color-accent-error, #ef4444);
    color: #fff;
}

.btn-icon-circle {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-circle-sm {
    width: 32px;
    height: 32px;
}

/* ============================================
   4. БЕЙДЖИ И СТАТУСЫ
   ============================================ */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full, 9999px);
    font-size: var(--font-size-xs, 0.75rem);
    font-weight: var(--font-weight-medium, 500);
    line-height: 1;
}

.badge-success {
    background: var(--success-bg);
    color: var(--color-accent-secondary, #10b981);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--color-accent-warning, #f59e0b);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--color-accent-error, #ef4444);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-info {
    background: var(--info-bg);
    color: var(--color-accent-primary, #3b82f6);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge-neutral {
    background: rgba(255, 255, 255, 0.05);
    color: var(--color-text-secondary, #a3a3a3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============================================
   5. АНИМАЦИИ
   ============================================ */

/* Появление снизу */
@keyframes ds-fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Появление сверху */
@keyframes ds-fadeInDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Масштабирование */
@keyframes ds-scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

/* Пульсация (загрузка) */
@keyframes ds-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

/* Вращение (лоадер) */
@keyframes ds-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Shimmer (скелетон) */
@keyframes ds-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Typing dots */
@keyframes ds-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-8px); opacity: 1; }
}

/* Классы анимаций */
.anim-fade-in-up {
    animation: ds-fadeInUp 0.3s ease both;
}

.anim-fade-in-down {
    animation: ds-fadeInDown 0.3s ease both;
}

.anim-scale-in {
    animation: ds-scaleIn 0.25s ease both;
}

.anim-pulse {
    animation: ds-pulse 2s infinite;
}

.anim-spin {
    animation: ds-spin 1s linear infinite;
}

/* Staggered animation для списков */
.anim-stagger > *:nth-child(1)  { animation-delay: 0.03s; }
.anim-stagger > *:nth-child(2)  { animation-delay: 0.06s; }
.anim-stagger > *:nth-child(3)  { animation-delay: 0.09s; }
.anim-stagger > *:nth-child(4)  { animation-delay: 0.12s; }
.anim-stagger > *:nth-child(5)  { animation-delay: 0.15s; }
.anim-stagger > *:nth-child(6)  { animation-delay: 0.18s; }
.anim-stagger > *:nth-child(7)  { animation-delay: 0.21s; }
.anim-stagger > *:nth-child(8)  { animation-delay: 0.24s; }
.anim-stagger > *:nth-child(9)  { animation-delay: 0.27s; }
.anim-stagger > *:nth-child(10) { animation-delay: 0.30s; }

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg,
        var(--color-bg-elevated, #1f1f1f) 25%,
        var(--color-bg-hover, #262626) 50%,
        var(--color-bg-elevated, #1f1f1f) 75%);
    background-size: 200% 100%;
    animation: ds-shimmer 1.5s infinite;
    border-radius: var(--radius-md, 8px);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}

.skeleton-title {
    height: 20px;
    margin-bottom: 12px;
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 12px;
    align-items: center;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--color-text-tertiary, #737373);
    border-radius: 50%;
    animation: ds-typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================
   6. СВЕТЛАЯ ТЕМА
   ============================================ */
html.theme-light {
    /* Фоны */
    --color-bg-primary: #f5f5f7;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #eaeaec;
    --color-bg-elevated: #ffffff;
    --color-bg-hover: #f0f0f2;

    /* Текст */
    --color-text-primary: #1a1a1a;
    --color-text-secondary: #555555;
    --color-text-tertiary: #888888;
    --color-text-disabled: #bbbbbb;

    /* Границы */
    --color-border-subtle: #e0e0e0;
    --color-border-default: #d0d0d0;
    --color-border-strong: #b0b0b0;

    /* Тени — мягче */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 20px rgba(0,0,0,0.08);

    /* Glass */
    --glass-bg: rgba(0, 0, 0, 0.02);
    --glass-bg-hover: rgba(0, 0, 0, 0.04);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-border-hover: rgba(0, 0, 0, 0.12);

    /* Glow — приглушённый */
    --glow-accent: 0 0 15px rgba(102, 126, 234, 0.12);
    --glow-success: 0 0 15px rgba(16, 185, 129, 0.12);
    --glow-danger: 0 0 15px rgba(239, 68, 68, 0.12);

    /* Функциональные фоны */
    --success-bg: rgba(16, 185, 129, 0.06);
    --warning-bg: rgba(245, 158, 11, 0.06);
    --danger-bg: rgba(239, 68, 68, 0.06);
    --info-bg: rgba(59, 130, 246, 0.06);

    /* WAY переменные */
    --way-bg-primary: #f5f5f7;
    --way-bg-secondary: #ffffff;
    --way-bg-tertiary: #eaeaec;
    --way-text-primary: #1a1a1a;
    --way-text-secondary: #555555;
    --way-text-muted: #888888;
    --way-border: #e0e0e0;
    --way-border-hover: #d0d0d0;

    /* style.css переменные */
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eaeaec;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f2;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #888888;
    --border-color: #e0e0e0;
    --border-hover: #d0d0d0;
}

/* Светлая тема — body */
html.theme-light body {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

/* Светлая тема — navbar */
html.theme-light .navbar-modern {
    background: rgba(255, 255, 255, 0.85);
    border-bottom-color: var(--color-border-subtle);
}

/* Светлая тема — карточки */
html.theme-light .modern-card,
html.theme-light .card {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-subtle);
}

/* Светлая тема — модалки */
html.theme-light .modal-content {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-subtle);
    color: var(--color-text-primary);
}

html.theme-light .modal-header {
    border-bottom-color: var(--color-border-subtle);
}

html.theme-light .modal-footer {
    border-top-color: var(--color-border-subtle);
}

/* Светлая тема — формы */
html.theme-light .form-control,
html.theme-light .form-select {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-default);
    color: var(--color-text-primary);
}

/* Светлая тема — dropdown */
html.theme-light .dropdown-menu {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-subtle);
}

html.theme-light .dropdown-item {
    color: var(--color-text-primary);
}

html.theme-light .dropdown-item:hover {
    background: var(--color-bg-hover);
}

/* Светлая тема — sidebar menu */
html.theme-light .navbar-menu-sidebar {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-subtle);
}

html.theme-light .navbar-menu-item {
    color: var(--color-text-secondary);
}

html.theme-light .navbar-menu-item:hover,
html.theme-light .navbar-menu-item.active {
    color: var(--color-text-primary);
    background: var(--color-bg-hover);
}

/* ============================================
   7. MOBILE-FIRST УТИЛИТЫ
   ============================================ */

/* Touch targets — минимум 44px на мобильных */
@media (max-width: 768px) {
    .btn,
    .btn-modern,
    .btn-glow {
        min-height: 44px;
    }

    .btn-icon-circle {
        width: 44px;
        height: 44px;
    }

    /* Скрытие/показ */
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    .show-mobile-flex { display: flex !important; }
    .show-mobile-inline { display: inline-flex !important; }
}

@media (min-width: 769px) {
    .show-mobile,
    .show-mobile-flex,
    .show-mobile-inline { display: none !important; }
    .hide-desktop { display: none !important; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .hide-tablet { display: none !important; }
}

/* Safe area для iPhone с notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .page-container {
        padding-bottom: calc(var(--space-8, 32px) + env(safe-area-inset-bottom));
    }
}

/* ============================================
   8. PROGRESS BAR
   ============================================ */
.progress-bar-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--grad-brand, linear-gradient(135deg, #667eea, #764ba2));
    transition: width 0.6s ease;
}

.progress-bar-fill.success {
    background: linear-gradient(135deg, #10b981, #059669);
}

.progress-bar-fill.warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.progress-bar-fill.danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

html.theme-light .progress-bar-track {
    background: rgba(0, 0, 0, 0.06);
}

/* ============================================
   9. TOAST / УВЕДОМЛЕНИЯ
   ============================================ */
.toast-container {
    position: fixed;
    top: 80px;
    right: 16px;
    z-index: var(--z-toast, 500);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast-item {
    pointer-events: auto;
    background: var(--color-bg-elevated, #1f1f1f);
    border: 1px solid var(--color-border-subtle, #262626);
    border-radius: var(--radius-lg, 12px);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: ds-fadeInDown 0.3s ease both;
    font-size: var(--font-size-sm, 0.875rem);
}

.toast-item.success { border-left: 3px solid var(--color-accent-secondary, #10b981); }
.toast-item.error   { border-left: 3px solid var(--color-accent-error, #ef4444); }
.toast-item.warning { border-left: 3px solid var(--color-accent-warning, #f59e0b); }
.toast-item.info    { border-left: 3px solid var(--color-accent-primary, #3b82f6); }

html.theme-light .toast-item {
    background: #fff;
    border-color: var(--color-border-subtle);
}

/* ============================================
   10. КНОПКА ПЕРЕКЛЮЧЕНИЯ ТЕМЫ
   ============================================ */
.theme-toggle-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--color-border-subtle, #262626);
    background: transparent;
    color: var(--color-text-secondary, #a3a3a3);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 1rem;
    padding: 0;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    background: var(--color-bg-hover, #262626);
    color: var(--color-text-primary, #fff);
    border-color: var(--color-border-default, #2a2a2a);
}

/* Иконки темы */
.theme-toggle-btn .icon-sun  { display: none; }
.theme-toggle-btn .icon-moon { display: inline; }

html.theme-light .theme-toggle-btn .icon-sun  { display: inline; }
html.theme-light .theme-toggle-btn .icon-moon { display: none; }

/* ============================================
   11. SCROLLBAR СТИЛИЗАЦИЯ
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

html.theme-light ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
}

html.theme-light ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* ============================================
   12. PREFERS REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
