/* === Общие стили для страницы аналитики === */
.analytics-page {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: #f0f2f5;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

.analytics-container {
    background-color: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    width: 100%;
    max-width: 1200px;
    margin: 20px auto;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px);
}

/* === Заголовок === */
.analytics-header {
    background-color: #007bff;
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    flex-wrap: wrap;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
}

.header-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    transition: all 0.2s;
    text-decoration: none;
    z-index: 10;
    color: #fff;
    padding: 0;
}

.header-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    text-decoration: none;
    color: #fff;
}

.header-title {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
    text-align: center;
    position: absolute;
    left: 0;
    right: 0;
    margin: auto;
    z-index: 2;
    width: 60%;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}

/* === Основное содержимое === */
.analytics-body {
    flex: 1;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    position: relative;
    background-color: #f0f2f5;
}

/* === Селектор периодов === */
.period-selector {
    background: white;
    border-radius: 16px;
    border: 1px solid #e0e6ed;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.period-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 6px;
    justify-content: center;
}

.period-tab {
    padding: 8px 6px;
    border-radius: 10px;
    border: 1px solid #e0e6ed;
    background: #f8f9fa;
    color: #6c757d;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.period-tab:hover {
    background: #e9ecef;
    color: #495057;
    transform: translateY(-1px);
}

.period-tab.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.2);
}

/* === Карточки статистики === */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.stat-card {
    background: white;
    border-radius: 16px;
    border: 1px solid #e0e6ed;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.stat-card.income .stat-icon {
    background: linear-gradient(135deg, #4CAF50, #8BC34A);
    color: white;
}

.stat-card.expense .stat-icon {
    background: linear-gradient(135deg, #f44336, #FF5722);
    color: white;
}

.stat-card.balance .stat-icon {
    background: linear-gradient(135deg, #2196F3, #03A9F4);
    color: white;
}

.stat-content {
    flex: 1;
}

.stat-label {
    color: #6c757d;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 5px;
}

.stat-value {
    color: #333;
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* === График === */
.chart-container {
    background: white;
    border-radius: 16px;
    border: 1px solid #e0e6ed;
    padding: 25px;
    flex: 1;
    min-height: 400px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.chart-title {
    color: #333;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
}

.chart-legend {
    display: flex;
    gap: 20px;
    align-items: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6c757d;
    font-size: 0.9rem;
    font-weight: 500;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-color.income {
    background: #4CAF50;
}

.legend-color.expense {
    background: #f44336;
}

.chart-wrapper {
    position: relative;
    height: 350px;
    background: #f8f9fa;
    border-radius: 12px;
    padding: 15px;
}

/* === Загрузка === */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    border-radius: 16px;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    font-size: 2rem;
    color: white;
}

.loading-text {
    color: white;
    font-size: 1rem;
    font-weight: 500;
}

/* === Чат с ИИ === */
.ai-chat-container {
    background: white;
    border-radius: 16px;
    border: 1px solid #e0e6ed;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative; /* для позиционирования плавающей кнопки */
}

.ai-chat-header {
    background: #007bff;
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.ai-chat-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.collapse-chat-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
}

.collapse-chat-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.collapse-chat-btn.collapsed {
    transform: rotate(180deg);
}

.collapse-chat-btn.collapsed:hover {
    transform: rotate(180deg) scale(1.1);
}

.ai-chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
}

.ai-chat-title i {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.ai-chat-title span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.start-chat-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 7px 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.start-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.start-chat-btn i {
    font-size: 0.9rem;
}

/* На маленьких экранах заголовок смещается наверх */
@media (max-width: 768px) {
    .ai-chat-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .ai-chat-title {
        justify-content: center;
        order: 1;
    }
    
    .ai-chat-controls {
        justify-content: center;
        order: 2;
    }
}

.ai-chat-content {
    display: flex;
    flex-direction: column;
    height: 400px;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    transform: translateY(0);
}

.ai-chat-content.collapsed {
    height: 0;
    opacity: 0;
    transform: translateY(-10px);
    margin: 0;
    padding: 0;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #f8f9fa;
}

.chat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    position: relative;
    animation: messageSlide 0.3s ease-out;
}

.chat-message.user {
    background: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

.chat-message.ai {
    background: white;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    border: 1px solid #e0e6ed;
}

.chat-message.ai .typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
}

.chat-message.ai .typing-indicator span {
    width: 8px;
    height: 8px;
    background: #007bff;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.chat-message.ai .typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-message.ai .typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Стили для форматированного текста в чате */
.chat-message.ai h2 {
    font-size: 1.3rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 8px 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #007bff;
}

.chat-message.ai h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #34495e;
    margin: 6px 0 10px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid #e0e6ed;
}

.chat-message.ai strong {
    font-weight: 600;
    color: #2c3e50;
}

.chat-message.ai br {
    margin: 4px 0;
}

.chat-input-container {
    padding: 15px 20px;
    border-top: 1px solid #e0e6ed;
    background: white;
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

#chatInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e6ed;
    border-radius: 25px;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

#chatInput:focus {
    border-color: #007bff;
}

#sendMessageBtn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #007bff;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

#sendMessageBtn:hover:not(:disabled) {
    background: #0056b3;
    transform: scale(1.05);
}

#sendMessageBtn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

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

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

.ai-chat-content {
    animation: chatSlideIn 0.4s ease-out;
}



/* === Стили для кнопки назад === */
.analytics-header .back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    transition: all 0.2s;
    margin-right: 0;
    text-decoration: none;
    z-index: 10;
    color: #fff;
    padding: 0;
}

.analytics-header .back-button:hover, 
.analytics-header .back-button:focus {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    text-decoration: none;
    color: #fff;
}

.analytics-header .back-button i {
    color: #fff;
    font-size: 1.3rem;
}

.analytics-header .back-button:hover i {
    color: #fff;
}

/* === Стили для летающих иконок === */
#floating-icons-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.floating-icon {
    position: absolute;
    width: 24px;
    height: 24px;
    opacity: 0.15;
    filter: invert(1) brightness(1.8);
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.floating-icon:hover {
    opacity: 0.3;
}

/* === Плавающая кнопка прокрутки чата === */
.chat-scroll-btn {
    position: absolute;
    right: 18px;
    bottom: 80px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #007bff;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 123, 255, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    z-index: 10;
}

.chat-scroll-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(0, 123, 255, 0.4);
    background: #0056b3;
}

.chat-scroll-btn i {
    font-size: 14px;
}

/* На мобильных прижимаем чуть выше поля ввода */
@media (max-width: 768px) {
    .chat-scroll-btn {
        bottom: 95px;
        right: 14px;
    }
}

/* Анимация смены иконки при клике */
@keyframes btnSwap {
    0% { transform: scale(1) rotate(0); }
    50% { transform: scale(0.75) rotate(90deg); }
    100% { transform: scale(1) rotate(180deg); }
}

.chat-scroll-btn.animating {
    animation: btnSwap 0.28s ease;
}

/* Стили скроллбара в чате */
.chat-messages {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: rgba(0,123,255,0.5) rgba(0,0,0,0.05);
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(0,123,255,0.65), rgba(0,86,179,0.85));
    border-radius: 8px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(0,123,255,0.85), rgba(0,86,179,1));
}