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

:root {
    /* Telegram theme variables with fallbacks */
    --primary: var(--tg-theme-button-color, #4f46e5);
    --primary-dark: var(--tg-theme-button-color, #4338ca);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: var(--tg-theme-bg-color, #0f172a);
    --bg-card: var(--tg-theme-secondary-bg-color, #1e293b);
    --bg-input: var(--tg-theme-secondary-bg-color, #334155);
    --text: var(--tg-theme-text-color, #f1f5f9);
    --text-muted: var(--tg-theme-hint-color, #94a3b8);
    --border: var(--tg-theme-hint-color, #475569);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

.app {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 100px;
}

/* Хедер */
.header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 20px;
    text-align: center;
}

.header h1 {
    font-size: 1.5rem;
    margin-bottom: 15px;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 15px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
}

.stat-label {
    font-size: 0.75rem;
    opacity: 0.8;
}

.progress-bar {
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
    transition: width 0.3s;
}

/* Навигация */
.nav {
    display: flex;
    background: var(--bg-card);
    padding: 10px;
    gap: 5px;
    overflow-x: auto;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-btn:hover {
    background: var(--bg-input);
}

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

/* Контент */
.content {
    padding: 15px;
}

.tab-content {
    display: none;
}

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

h2 {
    font-size: 1.3rem;
    margin-bottom: 15px;
}

h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--text-muted);
}

/* Сегодня */
.today-header {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.today-header h2 {
    margin-bottom: 5px;
}

.today-type {
    color: var(--primary);
    font-weight: 500;
}

/* Чек-лист */
.checklist {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.checklist-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.checklist-item:last-child {
    border-bottom: none;
}

.checklist-item input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-right: 12px;
    accent-color: var(--success);
}

.checklist-item.completed label {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Таймлайн */
.schedule-today {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.timeline-item {
    display: flex;
    padding: 10px 0;
    border-left: 2px solid var(--border);
    margin-left: 10px;
    padding-left: 15px;
    position: relative;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 14px;
    width: 10px;
    height: 10px;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: 50%;
}

.timeline-item.current::before {
    background: var(--primary);
}

.timeline-item.completed::before {
    background: var(--success);
    border-color: var(--success);
}

.timeline-time {
    min-width: 60px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.timeline-activity {
    flex: 1;
}

.timeline-activity strong {
    display: block;
    margin-bottom: 2px;
}

.timeline-activity small {
    color: var(--text-muted);
}

/* Быстрый ввод */
.quick-log {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
}

.quick-inputs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.input-group input {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    text-align: center;
}

.water-counter {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.water-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
}

#water-count {
    font-size: 1.2rem;
    min-width: 30px;
    text-align: center;
}

/* Расписание недели */
.week-selector {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.day-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
}

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

.day-btn.today {
    border-color: var(--success);
}

.day-schedule {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.schedule-row {
    display: flex;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
}

.schedule-row:last-child {
    border-bottom: none;
}

.schedule-time {
    min-width: 80px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.schedule-activity {
    flex: 1;
}

.schedule-row.highlight {
    background: rgba(79, 70, 229, 0.1);
}

/* Тренировка */
.workout-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    overflow-x: auto;
}

.workout-type-btn {
    padding: 10px 15px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.workout-type-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

.exercise-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
}

.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.exercise-name {
    font-weight: 600;
}

.exercise-badge {
    background: var(--primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.exercise-details {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.exercise-sets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.set-btn {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.set-btn.completed {
    background: var(--success);
    border-color: var(--success);
}

.exercise-weight-input {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.exercise-weight-input label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.exercise-weight-input input {
    width: 80px;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    text-align: center;
}

/* Питание */
.nutrition-summary {
    display: flex;
    gap: 20px;
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.macro {
    flex: 1;
    text-align: center;
}

.macro-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary);
}

.macro-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.meal-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
}

.meal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.meal-name {
    font-weight: 600;
}

.meal-time {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.meal-items {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.meal-macros {
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
}

.meal-macros span {
    color: var(--text-muted);
}

.meal-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.meal-checkbox input {
    width: 20px;
    height: 20px;
    accent-color: var(--success);
}

/* Прогресс */
.weight-input-section {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.weight-input-row {
    display: flex;
    gap: 10px;
}

.weight-input-row input {
    flex: 1;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
}

.btn-primary {
    padding: 12px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.weight-history {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.weight-chart {
    height: 150px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 0;
    margin-bottom: 15px;
}

.chart-bar {
    flex: 1;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 20px;
    position: relative;
}

.chart-bar-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
}

.weight-table {
    width: 100%;
    border-collapse: collapse;
}

.weight-table th,
.weight-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.weight-table th {
    color: var(--text-muted);
    font-weight: normal;
    font-size: 0.85rem;
}

.change-positive {
    color: var(--danger);
}

.change-negative {
    color: var(--success);
}

/* Замеры */
.measurements-section {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
}

.measurements-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.measure-input label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.measure-input input {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
}

.measurements-form .btn-primary {
    grid-column: span 2;
    margin-top: 10px;
}

/* Рабочие веса */
.workout-weights-section {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
}

.weights-table {
    width: 100%;
    border-collapse: collapse;
}

.weights-table th,
.weights-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.weights-table th {
    color: var(--text-muted);
    font-weight: normal;
    font-size: 0.85rem;
}

.weights-table input {
    width: 80px;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    text-align: center;
}

/* Адаптив */
@media (max-width: 400px) {
    .quick-inputs {
        grid-template-columns: 1fr;
    }

    .measurements-form {
        grid-template-columns: 1fr;
    }

    .measurements-form .btn-primary {
        grid-column: span 1;
    }
}
