/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
    /* Color Palette */
    --bg-base: #0b0e14;
    --bg-surface: #141923;
    --bg-surface-glass: rgba(20, 25, 35, 0.75);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.16);
    
    --primary: #818cf8; /* Light Indigo */
    --primary-glow: rgba(129, 140, 248, 0.15);
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #3b82f6 100%);
    
    --accent: #2dd4bf; /* Teal */
    --accent-gradient: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);
    
    --trend-up: #34d399; /* Green */
    --trend-down: #fb7185; /* Coral */
    --trend-neutral: #94a3b8;
    
    --text-primary: rgba(255, 255, 255, 0.95);
    --text-secondary: rgba(255, 255, 255, 0.70);
    --text-muted: rgba(255, 255, 255, 0.45);
    
    /* Shadows & Glassmorphism */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);
    --glass-blur: blur(16px);
    --glass-border: 1px solid rgba(255, 255, 255, 0.08);

    /* Animation Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Safe Areas for mobile notch */
    --sab: env(safe-area-inset-bottom, 0px);
    --sat: env(safe-area-inset-top, 0px);
}

/* ==========================================================================
   RESET & SYSTEM STYLES
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

/* Scrollbar Styling */
::-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);
}

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

/* Sidebar (Hidden on Mobile) */
.sidebar {
    display: none;
    flex-direction: column;
    width: 260px;
    background-color: var(--bg-surface);
    border-right: var(--glass-border);
    padding: 24px;
    justify-content: space-between;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 32px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-logo h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: var(--transition-fast);
}

.nav-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.04);
}

.nav-btn.active {
    color: var(--primary);
    background-color: var(--primary-glow);
}

.sidebar-footer {
    border-top: var(--glass-border);
    padding-top: 16px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    color: #fff;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
}

.user-status {
    font-size: 11px;
    color: var(--accent);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main Content Area */
.main-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100%;
    position: relative;
    padding-bottom: calc(64px + var(--sab)); /* Space for mobile nav */
}

/* App Header (Mobile) */
.app-header {
    height: 56px;
    background-color: var(--bg-surface-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 10;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-logo h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 18px;
    font-weight: 600;
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    animation: pulse 2s infinite;
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==========================================================================
   TABS MANAGEMENT
   ========================================================================== */
.tab-content {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    height: calc(100% - 56px);
}

.tab-pane {
    display: none;
    width: 100%;
    height: 100%;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.tab-pane.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================================================
   CHAT SYSTEM
   ========================================================================== */
#chat-tab.active {
    display: flex;
}

.chat-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    align-self: flex-start;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message.user-msg {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.05);
    border: var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.msg-avatar .material-symbols-outlined {
    font-size: 18px;
    color: var(--primary);
}

.message.user-msg .msg-avatar {
    background: var(--accent-gradient);
}

.message.user-msg .msg-avatar .material-symbols-outlined {
    color: #fff;
}

.msg-content {
    background-color: var(--bg-surface);
    border: var(--glass-border);
    padding: 12px 16px;
    border-radius: 4px 18px 18px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.message.user-msg .msg-content {
    background: var(--primary-gradient);
    border: none;
    border-radius: 18px 4px 18px 18px;
    color: #ffffff;
}

.msg-content p {
    font-size: 14.5px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-image {
    max-width: 100%;
    max-height: 240px;
    border-radius: 12px;
    margin-bottom: 4px;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.msg-time {
    font-size: 10px;
    color: var(--text-muted);
    align-self: flex-end;
}

.message.user-msg .msg-time {
    color: rgba(255, 255, 255, 0.7);
}

/* System notifications in chat */
.message.system-msg .msg-content {
    background-color: var(--bg-surface-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

/* Image Preview Above Input */
.image-preview-area {
    padding: 8px 16px 0 16px;
    background-color: transparent;
    display: flex;
    z-index: 5;
}

.preview-card {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--primary);
    box-shadow: var(--shadow-md);
    animation: scaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-preview-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.6);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
}

.remove-preview-btn:hover {
    background-color: rgba(220, 38, 38, 0.9);
}

.remove-preview-btn .material-symbols-outlined {
    font-size: 12px;
    font-weight: 800;
}

/* Input Container */
.chat-input-container {
    padding: 12px 16px;
    background-color: var(--bg-base);
    border-top: var(--glass-border);
    position: relative;
    z-index: 5;
}

.chat-input-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background-color: var(--bg-surface);
    border: var(--glass-border);
    border-radius: 24px;
    padding: 8px 12px 8px 16px;
    transition: var(--transition-fast);
}

.chat-input-form:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.chat-input-form textarea {
    flex-grow: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14.5px;
    resize: none;
    max-height: 120px;
    padding: 6px 0;
    line-height: 1.4;
}

.chat-input-form textarea::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition-fast);
    background: transparent;
    border: none;
    flex-shrink: 0;
}

.icon-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.attach-btn {
    color: var(--text-secondary);
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--primary-gradient);
    border: none;
    color: #fff;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn .material-symbols-outlined {
    font-size: 18px;
    margin-left: 2px;
}

/* Typing Indicator Bubble */
.typing-bubble {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    background-color: var(--bg-surface);
    border: var(--glass-border);
    border-radius: 4px 18px 18px 18px;
    align-self: flex-start;
    box-shadow: var(--shadow-sm);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* ==========================================================================
   BUDGET DASHBOARD
   ========================================================================== */
#budget-tab.active {
    display: block;
    overflow-y: auto;
}

.budget-wrapper {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Fast Info Cards */
.budget-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.budget-card {
    background-color: var(--bg-surface);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: var(--transition-normal);
}

.budget-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.card-icon {
    font-size: 20px;
    color: var(--text-muted);
}

.card-value {
    font-family: 'Outfit', sans-serif;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.card-trend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
}

.card-trend.positive {
    color: var(--trend-up);
}

.card-trend.negative {
    color: var(--trend-down);
}

.card-trend.neutral {
    color: var(--trend-neutral);
}

.card-trend .material-symbols-outlined {
    font-size: 14px;
}

/* Charts Grid */
.budget-charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.chart-container-card {
    background-color: var(--bg-surface);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chart-container-card h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.chart-wrapper-inner {
    position: relative;
    width: 100%;
    height: 260px; /* Фиксированная высота для стабильности Chart.js */
}

/* ==========================================================================
   NAVIGATION
   ========================================================================== */
/* Mobile bottom navigation */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + var(--sab));
    background-color: var(--bg-surface-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: var(--glass-border);
    display: flex;
    padding-bottom: var(--sab);
    z-index: 10;
}

.mobile-nav-btn {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.mobile-nav-btn:hover {
    color: var(--text-primary);
}

.mobile-nav-btn.active {
    color: var(--primary);
}

.mobile-nav-btn .material-symbols-outlined {
    font-size: 22px;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.4);
    }
    70% {
        box-shadow: 0 0 0 6px rgba(45, 212, 191, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(45, 212, 191, 0);
    }
}

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

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes typingBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
        background-color: var(--primary);
    }
}

/* ==========================================================================
   MEDIA QUERIES (DESKTOP INTERFACE)
   ========================================================================== */
@media (min-width: 768px) {
    /* Layout */
    .sidebar {
        display: flex; /* Sidebar becomes visible */
    }

    .app-header {
        display: none; /* Hide mobile top header */
    }

    .mobile-nav {
        display: none; /* Hide bottom mobile navigation */
    }

    .main-content {
        padding-bottom: 0; /* Reset bottom padding */
        height: 100%;
        overflow: hidden;
    }

    .tab-content {
        height: 100%; /* Tab content takes full height */
    }

    /* Message List Space Adjustments */
    .chat-messages {
        padding: 24px;
        gap: 20px;
    }

    .message {
        max-width: 70%;
    }

    .chat-input-container {
        padding: 20px 24px 24px 24px;
    }

    /* Budget Adjustments */
    .budget-wrapper {
        padding: 24px;
        gap: 24px;
    }

    .budget-cards {
        grid-template-columns: repeat(3, 1fr); /* 3 cards inline */
        gap: 16px;
    }

    .budget-charts-grid {
        grid-template-columns: 1fr 1.3fr; /* Side-by-side charts */
        gap: 20px;
    }
    
    .chart-container-card {
        padding: 24px;
    }
}
