/* ========================================
   MONEYTRACKER - Critical CSS
   Стили для первого рендера (above the fold)
   ======================================== */

/* CSS Variables - Theme System */
:root {
    /* Dark theme (default) */
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-card: rgba(20, 20, 20, 0.8);
    --bg-card-hover: rgba(30, 30, 30, 0.9);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.4);

    --accent-primary: #c8ff00;
    --accent-secondary: #00d4ff;
    --accent-tertiary: #ff00aa;

    --income-color: #00ff88;
    --expense-color: #ff4466;
    --balance-positive: #00ff88;
    --balance-negative: #ff4466;

    --border-color: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);

    --shadow-glow: 0 0 40px rgba(200, 255, 0, 0.15);
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);

    --noise-opacity: 0.04;

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-medium: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light theme - Grainy & Soft 2026 */
[data-theme="light"] {
    --bg-primary: #F2F3F5;
    --bg-secondary: #FEFEFE;
    --bg-card: rgba(254, 254, 254, 0.7);
    --bg-card-hover: rgba(254, 254, 254, 0.85);

    --text-primary: #1a1a1a;
    --text-secondary: rgba(26, 26, 26, 0.7);
    --text-muted: rgba(26, 26, 26, 0.45);

    --accent-primary: #5c4dff;
    --accent-secondary: #0077cc;
    --accent-tertiary: #e6005c;

    --income-color: #00875a;
    --expense-color: #b8495a;

    --border-color: rgba(0, 0, 0, 0.08);
    --glass-bg: rgba(254, 254, 254, 0.64);
    --glass-border: rgba(0, 0, 0, 0.06);

    --shadow-glow: 0 0 60px rgba(92, 77, 255, 0.12);
    --shadow-card: 0 8px 40px rgba(0, 0, 0, 0.06);

    --noise-opacity: 0.12;
}

/* ========================================
   Base Reset & Typography
   ======================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background var(--transition-medium), color var(--transition-medium);
}

::selection {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

/* ========================================
   Theme Toggle (in header)
   ======================================== */

.theme-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    border-color: var(--accent-primary);
    background: var(--glass-bg);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .moon-icon {
    display: none;
}

/* ========================================
   Login Section
   ======================================== */

.login-section {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 500px;
    text-align: center;
}

.logo-wrapper {
    margin-bottom: 60px;
}

.logo {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 10px;
}

.logo .accent {
    color: var(--accent-primary);
    text-shadow: 0 0 30px var(--accent-primary);
}

.tagline {
    font-size: 0.875rem;
    letter-spacing: 0.3em;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Login Form */
.login-form {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 50px 40px;
    margin-bottom: 40px;
}

/* Telegram Login Widget */
.telegram-login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50px;
    position: relative;
    z-index: 10;
}

.telegram-login-wrapper iframe {
    position: relative;
    z-index: 10;
}

.input-wrapper {
    position: relative;
    margin-bottom: 40px;
}

.input-field {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border-color);
    padding: 20px 0 10px;
    font-family: inherit;
    font-size: 1.125rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.input-field:focus {
    border-color: var(--accent-primary);
}

.input-label {
    position: absolute;
    left: 0;
    top: 20px;
    font-size: 0.875rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    pointer-events: none;
    transition: all var(--transition-fast);
}

.input-field:focus + .input-label,
.input-field:not(:placeholder-shown) + .input-label {
    top: 0;
    font-size: 0.75rem;
    color: var(--accent-primary);
}

.input-line {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--accent-primary);
    transition: width var(--transition-medium);
}

.input-field:focus ~ .input-line {
    width: 100%;
}

/* Primary Button */
.btn-primary {
    position: relative;
    width: 100%;
    padding: 20px 40px;
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    cursor: pointer;
    overflow: hidden;
    transition: all var(--transition-fast);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 40px rgba(200, 255, 0, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary.loading .btn-text {
    opacity: 0;
}

.btn-primary.loading .btn-loader {
    opacity: 1;
}

.btn-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 3px solid transparent;
    border-top-color: var(--bg-primary);
    border-radius: 50%;
    opacity: 0;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.error-message {
    margin-top: 20px;
    color: var(--expense-color);
    font-size: 0.875rem;
    min-height: 20px;
    opacity: 0;
    transform: translateY(-10px);
    transition: all var(--transition-fast);
}

.error-message.visible {
    opacity: 1;
    transform: translateY(0);
}

.login-footer {
    color: var(--text-muted);
    font-size: 0.875rem;
    letter-spacing: 0.05em;
}

/* ========================================
   Dashboard Section
   ======================================== */

.dashboard-section {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 20px;
    padding-top: 100px;
    max-width: 1400px;
    margin: 0 auto;
}

.dashboard-section.hidden {
    display: none;
}

/* Dashboard Header */
.dashboard-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 30px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
}

/* Light theme header - white with 64% opacity over gray */
[data-theme="light"] .dashboard-header {
    background: rgba(254, 254, 254, 0.64);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
}

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

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.user-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-logout svg {
    width: 16px;
    height: 16px;
}

.btn-logout:hover {
    border-color: var(--expense-color);
    color: var(--expense-color);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 25px;
    display: flex;
    align-items: flex-start;
    gap: 15px;
    transition: all var(--transition-fast);
    cursor: default;
    opacity: 1 !important;
    pointer-events: auto;
}

.stat-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-5px);
    box-shadow: var(--shadow-card);
}

/* Paper texture and shadows for light theme cards */
[data-theme="light"] .stat-card,
[data-theme="light"] .chart-card,
[data-theme="light"] .transactions-section,
[data-theme="light"] .login-form {
    background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='paper'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='5'/%3E%3CfeDiffuseLighting in='noise' lighting-color='%23fff' surfaceScale='2'%3E%3CfeDistantLight azimuth='45' elevation='60'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paper)'/%3E%3C/svg%3E");
    background-blend-mode: soft-light;
    background-size: 200px 200px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .stat-card:hover,
[data-theme="light"] .chart-card:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.card-balance .stat-icon {
    background: rgba(200, 255, 0, 0.1);
    color: var(--accent-primary);
}

.card-income .stat-icon {
    background: rgba(0, 255, 136, 0.1);
    color: var(--income-color);
}

.card-expense .stat-icon {
    background: rgba(255, 68, 102, 0.1);
    color: var(--expense-color);
}

.card-total .stat-icon {
    background: rgba(0, 212, 255, 0.1);
    color: var(--accent-secondary);
}

.stat-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-value.positive {
    color: var(--income-color);
}

.stat-value.negative {
    color: var(--expense-color);
}

.stat-period {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* ========================================
   Responsive Adjustments (Critical)
   ======================================== */

@media (max-width: 768px) {
    .dashboard-header {
        padding: 15px 20px;
    }

    .theme-toggle {
        top: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
    }

    .login-form {
        padding: 40px 25px;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stats-grid {
        gap: 12px;
        margin-bottom: 16px;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 2rem;
    }

    .dashboard-section {
        padding: 10px;
        padding-top: 80px;
    }

    .btn-logout span {
        display: none;
    }

    .btn-logout {
        padding: 10px;
    }

    .stats-grid {
        gap: 8px;
        margin-bottom: 12px;
    }

    .stat-card {
        padding: 12px;
        border-radius: 14px;
    }
}
