/**
 * FitBot Mini App — стили
 *
 * Мобильный дизайн, safe areas, сетка 3x2 на главном экране.
 * CSS-переменные для тематизации под клуб.
 * Совместимость: MAX WebApp + Telegram WebApp.
 */

/* === Сброс и переменные === */

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

:root {
    /* Основные цвета */
    --primary: #4CAF50;
    --primary-dark: #388E3C;
    --primary-light: #66BB6A;

    /* Фон и поверхности */
    --bg: #f5f5f5;
    --card-bg: #ffffff;

    /* Текст */
    --text: #212121;
    --text-secondary: #757575;
    --text-on-primary: #ffffff;

    /* Границы */
    --border: #e0e0e0;

    /* Статусы */
    --success: #4CAF50;
    --warning: #FF9800;
    --danger: #F44336;

    /* Размеры */
    --header-height: 48px;
    --radius: 12px;
    --radius-lg: 16px;

    /* Безопасные области (iPhone notch, Android gesture bar) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}


/* === Типографика и body === */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Динамическая высота для мобильных */
}


/* === Экран загрузки === */

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    gap: 16px;
}

.loading-text {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Спиннер (CSS-анимация) */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* === Контейнер приложения === */

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}


/* === Шапка (Header) === */

.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    padding-top: var(--safe-top);
    position: relative;
}

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

/* Кнопка «Назад» в шапке */
.header-back {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--primary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding-top: var(--safe-top);
}

.header-back:active {
    opacity: 0.6;
}


/* === Область контента === */

.content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(var(--safe-bottom) + 16px);
}


/* === Главный экран (6 кнопок, сетка 3x2) === */

.home-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 16px;
}

.home-greeting {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 24px;
    text-align: center;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 360px;
}

.home-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--card-bg);
    border: none;
    border-radius: var(--radius-lg);
    padding: 20px 8px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.home-btn:active {
    transform: scale(0.95);
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);
}

.home-btn-icon {
    font-size: 32px;
    line-height: 1;
}

.home-btn-text {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
    text-align: center;
}


/* === Экран «Клубная карта» === */

.card-screen {
    padding-top: 8px;
}

.club-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius-lg);
    padding: 24px;
    color: var(--text-on-primary);
    text-align: center;
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
}

.card-club-name {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.85;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.card-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
}

.card-barcode {
    background: #ffffff;
    border-radius: 8px;
    padding: 16px;
    margin: 0 0 12px 0;
}

.barcode-value {
    font-family: 'Courier New', monospace;
    font-size: 24px;
    letter-spacing: 4px;
    color: var(--text);
    font-weight: 700;
}

.card-type {
    font-size: 13px;
    opacity: 0.85;
}


/* === Экран «Абонементы» === */

.subscriptions-screen {
    /* Контейнер списка абонементов */
}

.screen-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.subscription-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    border-left: 4px solid var(--primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: transform 0.15s ease;
}

.subscription-card:active {
    transform: scale(0.98);
}

.subscription-card.expired {
    border-left-color: var(--text-secondary);
    opacity: 0.7;
}

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

.sub-title {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
    margin-right: 8px;
}

.sub-status {
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.sub-status--active {
    background: rgba(76, 175, 80, 0.1);
    color: var(--success);
}

.sub-status--expired {
    background: rgba(117, 117, 117, 0.1);
    color: var(--text-secondary);
}

.sub-date {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.sub-remaining {
    font-size: 12px;
    color: var(--primary);
    margin-top: 2px;
}


/* === Экран «Профиль» === */

.profile-screen {
    /* Контейнер экрана профиля */
}

.profile-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--text-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 12px;
}

.profile-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.profile-phone {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Детали профиля */
.profile-details {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.profile-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

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

.profile-detail-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.profile-detail-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}


/* === Экран «Расписание» === */

.schedule-screen {
    /* Контейнер расписания */
}

.schedule-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.schedule-time {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
    min-width: 50px;
}

.schedule-info {
    flex: 1;
}

.schedule-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 2px;
}

.schedule-trainer {
    font-size: 13px;
    color: var(--text-secondary);
}

.schedule-room {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}


/* === Экран «Помощь» (FAQ) === */

.help-screen {
    /* Контейнер помощи */
}

.help-item {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.help-question {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.help-answer {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}


/* === Экран «Контакты» === */

.contacts-screen {
    /* Контейнер контактов */
}

.contact-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.contact-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
}

.contact-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.4;
}

.contact-row:last-child {
    margin-bottom: 0;
}

.contact-icon {
    font-size: 16px;
    flex-shrink: 0;
    line-height: 1.4;
}


/* === Пустое состояние === */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 16px;
    text-align: center;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    line-height: 1;
}

.empty-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.empty-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
}


/* === Экран ошибки === */

.error-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 16px;
    gap: 12px;
}

.error-icon {
    font-size: 48px;
    line-height: 1;
    color: var(--warning);
}

.error-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

.error-hint {
    font-size: 14px;
    color: var(--text-secondary);
}

.diagnostics {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    padding: 12px;
    text-align: left;
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
    margin-top: 8px;
}


/* === Кнопки === */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
}

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


/* === Всплывающее уведомление (Toast) === */

.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(33, 33, 33, 0.9);
    color: #ffffff;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    z-index: 300;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.toast--fade {
    opacity: 0;
}


/* === Загрузка внутри экранов === */

.screen-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 48px;
}


/* === Модальное окно (заготовка для будущих экранов) === */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 24px;
    padding-bottom: calc(24px + var(--safe-bottom));
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.modal-body {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
