/* Минималистичные стили для медицинского Mini App */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Медицинская цветовая палитра */
    --primary: #2563EB;
    --primary-light: #3B82F6;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    
    /* Telegram переменные */
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, var(--gray-900));
    --hint: var(--tg-theme-hint-color, var(--gray-500));
    --button: var(--tg-theme-button-color, var(--primary));
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, var(--gray-50));
    
    /* Интенсивность боли */
    --pain-1: #10B981;
    --pain-2: #34D399;
    --pain-3: #FBBF24;
    --pain-4: #FB923C;
    --pain-5: #EF4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    background: var(--bg);
    min-height: 100vh;
}

/* Главная навигация */
.main-nav {
    display: flex;
    background: var(--secondary-bg);
    border-radius: 12px;
    padding: 4px;
    margin: 16px 16px 0;
    position: sticky;
    top: 16px;
    z-index: 100;
}

.nav-tab {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--hint);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-tab.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Содержимое вкладок */
.tab-content {
    display: none;
    padding: 20px 16px;
}

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

/* Заголовок периода */
.period-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.period-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

.nav-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--secondary-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--gray-200);
    transform: scale(1.05);
}

/* Сетка метрик */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 32px;
}

.metric-card {
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 20px 16px;
    text-align: center;
    position: relative;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.metric-card.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    border-color: var(--primary);
}

.metric-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.metric-card.primary .metric-value {
    color: white;
}

.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--hint);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-card.primary .metric-label {
    color: rgba(255, 255, 255, 0.9);
}

.metric-trend {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
    display: inline-block;
}

.metric-trend.up {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.metric-trend.down {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* Контейнеры графиков */
.chart-container {
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--gray-200);
}

.chart-container h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.chart-container canvas {
    max-height: 200px !important;
    border-radius: 8px;
}

/* Фильтры */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    padding: 0 4px;
}

.filter-btn {
    background: var(--secondary-bg);
    border: 1px solid var(--gray-200);
    color: var(--hint);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Корреляция лекарств */
.correlation-container {
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--gray-200);
}

.medication-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.medication-item {
    background: var(--bg);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--primary);
}

.medication-name {
    font-weight: 600;
    color: var(--text);
}

.medication-effectiveness {
    display: flex;
    align-items: center;
    gap: 8px;
}

.effectiveness-score {
    font-size: 18px;
    font-weight: 700;
    color: var(--success);
}

.effectiveness-label {
    font-size: 12px;
    color: var(--hint);
    text-transform: uppercase;
}

/* Мини-календарь */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.calendar-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.mini-calendar {
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
}

.weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 8px;
}

.weekday {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--hint);
    padding: 8px 4px;
    text-transform: uppercase;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.day-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: var(--bg);
    border: 1px solid transparent;
}

.day-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.day-cell.other-month {
    color: var(--gray-300);
    background: transparent;
}

.day-cell.today {
    border-color: var(--primary);
    font-weight: 700;
}

.day-cell.selected {
    background: var(--primary);
    color: white;
}

/* Индикаторы боли */
.day-cell.pain-1 { background: var(--pain-1); color: white; }
.day-cell.pain-2 { background: var(--pain-2); color: white; }
.day-cell.pain-3 { background: var(--pain-3); color: white; }
.day-cell.pain-4 { background: var(--pain-4); color: white; }
.day-cell.pain-5 { background: var(--pain-5); color: white; }

.pain-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--danger);
}

/* События дня */
.day-events {
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--gray-200);
}

.day-events h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.events-timeline {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.event-item {
    background: var(--bg);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--primary);
}

.event-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--hint);
    min-width: 50px;
}

.event-icon {
    font-size: 16px;
    width: 24px;
    text-align: center;
}

.event-content {
    flex: 1;
}

.event-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.event-desc {
    font-size: 12px;
    color: var(--hint);
}

/* Загрузка */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    z-index: 1000;
}

.pulse-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    animation: pulse 2s infinite;
    margin-bottom: 16px;
}

@keyframes pulse {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

.loading p {
    font-size: 14px;
    color: var(--hint);
    font-weight: 500;
}

/* Адаптивность */
@media (max-width: 320px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .metric-value {
        font-size: 28px;
    }
    
    .main-nav {
        margin: 12px;
    }
    
    .tab-content {
        padding: 16px 12px;
    }
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: var(--tg-theme-bg-color, var(--gray-900));
        --text: var(--tg-theme-text-color, white);
        --secondary-bg: var(--tg-theme-secondary-bg-color, var(--gray-800));
        --hint: var(--tg-theme-hint-color, var(--gray-400));
    }
}

/* Анимации */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

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