/* ============================================================================
   CostControl - Mobile-First Dashboard Styles
   ============================================================================ */

/* CSS Custom Properties */
:root {
    /* Colors - Dark Theme (Primary) */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-dark: #4f46e5;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --border: #334155;
    --border-light: #475569;

    /* Chart Colors */
    --chart-1: #6366f1;
    --chart-2: #8b5cf6;
    --chart-3: #06b6d4;
    --chart-4: #10b981;
    --chart-5: #f59e0b;
    --chart-6: #94a3b8;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-2xl: 32px;

    /* Touch Targets */
    --touch-target: 44px;

    /* Layout */
    --header-height: 56px;
    --filter-height: 56px;
    --tabs-height: 56px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================================================
   LOGIN PAGE
   ============================================================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: var(--space-xl);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.login-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto var(--space-md);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    color: white;
}

.login-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-sm);
}

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    height: var(--touch-target);
    padding: 0 var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-size-md);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

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

.password-field {
    position: relative;
}

.password-toggle {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: var(--touch-target);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-btn {
    width: 100%;
    height: var(--touch-target);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-btn:active {
    transform: scale(0.98);
}

.login-footer {
    margin-top: var(--space-xl);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.telegram-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
    color: #0088cc;
    text-decoration: none;
    font-weight: 500;
}

/* ============================================================================
   APP LAYOUT
   ============================================================================ */

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-logo {
    color: var(--accent);
    font-size: 20px;
}

.header-title {
    font-weight: 600;
    font-size: var(--font-size-lg);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.header-user {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.header-logout {
    width: var(--touch-target);
    height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.header-logout:active {
    background: var(--bg-tertiary);
}

/* Filter Bar */
.filter-bar {
    position: sticky;
    top: var(--header-height);
    z-index: 90;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: var(--space-sm) var(--space-md);
}

.filter-row {
    display: flex;
    gap: var(--space-sm);
}

.filter-group {
    flex: 1;
}

.filter-select {
    width: 100%;
    height: var(--touch-target);
    padding: 0 var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%2394a3b8' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 24px;
    padding-right: 36px;
}

.date-range-row {
    margin-top: var(--space-sm);
}

.date-range-input {
    flex: 1;
    height: var(--touch-target);
    padding: 0 var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.filter-btn {
    width: var(--touch-target);
    height: var(--touch-target);
    border: none;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s;
}

.filter-btn:active {
    opacity: 0.8;
}

.filter-btn-apply {
    background: var(--accent);
    color: white;
}

.filter-btn-reset {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* Tabs */
.tabs {
    position: sticky;
    top: calc(var(--header-height) + var(--filter-height));
    z-index: 80;
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    height: var(--tabs-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: color 0.2s;
    position: relative;
}

.tab i {
    font-size: 18px;
}

.tab.active {
    color: var(--accent);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
}

/* Content */
.content {
    flex: 1;
    padding: var(--space-md);
    overflow-y: auto;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================================================
   KPI CARDS
   ============================================================================ */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.kpi-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 1px solid var(--border);
}

.kpi-icon {
    width: 36px;
    height: 36px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: var(--space-sm);
}

.kpi-value {
    font-size: var(--font-size-lg);
    font-weight: 700;
    margin-bottom: 2px;
    word-break: break-word;
}

.kpi-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* ============================================================================
   CHARTS
   ============================================================================ */

.charts-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
}

.chart-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-weight: 500;
    font-size: var(--font-size-sm);
}

.chart-header i {
    color: var(--accent);
}

.chart-body {
    padding: var(--space-md);
    height: 200px;
    position: relative;
}

.chart-body-large {
    height: 280px;
}

.chart-legend {
    padding: var(--space-sm) var(--space-md) var(--space-md);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* ============================================================================
   SECTIONS & LISTS
   ============================================================================ */

.section {
    margin-bottom: var(--space-lg);
}

.section-header {
    margin-bottom: var(--space-md);
}

.section-header h2 {
    font-size: var(--font-size-md);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.section-header h2 i {
    color: var(--accent);
}

/* Transactions */
.transactions-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.transaction-item {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 60px;
}

.transaction-category {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.transaction-icon {
    font-size: 20px;
}

.transaction-name {
    font-weight: 500;
    font-size: var(--font-size-sm);
}

.transaction-details {
    text-align: right;
}

.transaction-date {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.transaction-amount {
    font-weight: 600;
    font-size: var(--font-size-sm);
}

/* Categories */
.categories-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.category-item {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    cursor: pointer;
    min-height: var(--touch-target);
    transition: border-color 0.2s;
}

.category-item:active {
    border-color: var(--accent);
}

.category-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
}

.category-icon {
    font-size: 24px;
}

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

.category-name {
    font-weight: 500;
    font-size: var(--font-size-sm);
}

.category-count {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.category-right {
    text-align: right;
}

.category-amount {
    font-weight: 600;
    font-size: var(--font-size-sm);
}

.category-percent {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.category-arrow {
    color: var(--text-muted);
    font-size: 12px;
}

/* Load More */
.load-more-btn {
    width: 100%;
    height: var(--touch-target);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-md);
    transition: background 0.2s;
}

.load-more-btn:active {
    background: var(--bg-card);
}

/* Back Button */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    margin-bottom: var(--space-md);
}

.category-detail-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    font-size: var(--font-size-xl);
    font-weight: 600;
}

.category-detail-icon {
    font-size: 32px;
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: var(--space-xl);
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto var(--space-md);
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--text-muted);
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.empty-state-text {
    color: var(--text-muted);
    margin-bottom: var(--space-lg);
}

.empty-state-cta {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    background: #0088cc;
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

/* ============================================================================
   SKELETON LOADING
   ============================================================================ */

.skeleton {
    position: relative;
    overflow: hidden;
}

.skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(255, 255, 255, 0.05) 50%,
            transparent 100%);
    animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.skeleton .kpi-value,
.skeleton .kpi-label,
.skeleton .kpi-icon {
    opacity: 0.3;
}

/* ============================================================================
   FLATPICKR CUSTOMIZATION
   ============================================================================ */

.flatpickr-calendar {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-lg) !important;
}

.flatpickr-day {
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
}

.flatpickr-day:hover {
    background: var(--bg-tertiary) !important;
    border-color: var(--bg-tertiary) !important;
}

.flatpickr-day.selected {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}

.flatpickr-day.inRange {
    background: rgba(99, 102, 241, 0.2) !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.flatpickr-weekday {
    color: var(--text-muted) !important;
    background: var(--bg-secondary) !important;
}

/* ============================================================================
   TABLET BREAKPOINT (768px+)
   ============================================================================ */

@media (min-width: 768px) {
    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .charts-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .content {
        padding: var(--space-lg);
        max-width: 1200px;
        margin: 0 auto;
    }

    .kpi-value {
        font-size: var(--font-size-xl);
    }

    .chart-body {
        height: 250px;
    }

    .chart-body-large {
        height: 320px;
    }
}

/* ============================================================================
   DESKTOP BREAKPOINT (1024px+)
   ============================================================================ */

@media (min-width: 1024px) {
    .filter-bar {
        max-width: 1200px;
        margin: 0 auto;
    }

    .filter-row {
        max-width: 600px;
    }
}