/* =====================================================
   Telegram Mini App - Master App Styles
   Поддержка светлой и тёмной темы Telegram
   ===================================================== */

:root {
    /* Светлая тема по умолчанию */
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0f0f0;

    /* Дополнительные переменные */
    --card-bg: #ffffff;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --border-color: #e5e5e5;
    --success-color: #34c759;
    --warning-color: #ff9500;
    --danger-color: #ff3b30;

    /* Safe area */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* Тёмная тема - Glassmorphism эффект для Android */
@media (prefers-color-scheme: dark) {
    :root {
        /* Telegram тема - тёмные значения по умолчанию */
        --tg-theme-bg-color: #1c1c1e;
        --tg-theme-text-color: #ffffff;
        --tg-theme-hint-color: #8e8e93;
        --tg-theme-link-color: #0a84ff;
        --tg-theme-button-color: #0a84ff;
        --tg-theme-button-text-color: #ffffff;
        --tg-theme-secondary-bg-color: #2c2c2e;

        /* Glassmorphism эффект для карточек */
        --card-bg: rgba(44, 44, 46, 0.8);
        --card-shadow: 0 4px 16px rgba(0, 0, 0, 0.4),
                       inset 0 1px 0 rgba(255, 255, 255, 0.1);
        --border-color: rgba(255, 255, 255, 0.12);
    }
}

/* Glassmorphism стили для карточек в тёмной теме */
@media (prefers-color-scheme: dark) {
    .stat-card,
    .appointment-card,
    .salary-card,
    .profile-header,
    .settings-section,
    .analytics-section,
    .chart-container,
    .stat-box {
        border: 1px solid var(--border-color);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* =====================================================
   Экраны
   ===================================================== */

.screen {
    display: none;
    height: 100%;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Экран загрузки */
#loading-screen {
    justify-content: center;
    align-items: center;
    background: var(--tg-theme-bg-color);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--tg-theme-secondary-bg-color);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-screen p {
    margin-top: 16px;
    color: var(--tg-theme-hint-color);
}

/* Экран ошибки */
#error-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: var(--tg-theme-bg-color);
}

.error-content {
    text-align: center;
    max-width: 300px;
}

.error-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--danger-color);
    color: white;
    font-size: 32px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.error-content h2 {
    margin-bottom: 10px;
}

.error-content p {
    color: var(--tg-theme-hint-color);
    margin-bottom: 20px;
}

/* =====================================================
   Основной контейнер
   ===================================================== */

#app-container {
    flex-direction: column;
    padding-top: var(--safe-area-top);
    padding-bottom: calc(60px + var(--safe-area-bottom));
}

/* Заголовок */
.app-header {
    padding: 16px 20px;
    background: var(--tg-theme-bg-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.header-date {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    margin-top: 4px;
}

/* =====================================================
   Вкладки
   ===================================================== */

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

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

/* =====================================================
   Нижняя навигация
   ===================================================== */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--tg-theme-bg-color);
    border-top: 1px solid var(--border-color);
    padding-bottom: var(--safe-area-bottom);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--tg-theme-hint-color);
    cursor: pointer;
    transition: color 0.2s;
}

.nav-item.active {
    color: var(--tg-theme-button-color);
}

.nav-icon {
    font-size: 24px;
    margin-bottom: 2px;
}

.nav-label {
    font-size: 10px;
    font-weight: 500;
}

/* =====================================================
   Быстрая статистика
   ===================================================== */

.quick-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
}

.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--tg-theme-button-color);
}

.stat-label {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    margin-top: 4px;
}

/* =====================================================
   Список записей
   ===================================================== */

.appointments-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.appointment-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s;
}

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

.appointment-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.appointment-time {
    font-size: 18px;
    font-weight: 600;
}

.appointment-duration {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    background: var(--tg-theme-secondary-bg-color);
    padding: 4px 8px;
    border-radius: 4px;
}

.appointment-client {
    font-size: 16px;
    margin-bottom: 4px;
}

.appointment-services {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.appointment-status {
    display: inline-block;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 8px;
}

.status-confirmed {
    background: rgba(52, 199, 89, 0.15);
    color: var(--success-color);
}

.status-pending {
    background: rgba(255, 149, 0, 0.15);
    color: var(--warning-color);
}

.status-cancelled {
    background: rgba(255, 59, 48, 0.15);
    color: var(--danger-color);
}

.status-paid {
    background: rgba(52, 199, 89, 0.15);
    color: var(--success-color);
}

.appointment-statuses {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--tg-theme-hint-color);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

/* =====================================================
   Календарь
   ===================================================== */

.calendar-nav, .salary-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.nav-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.calendar-period, .salary-period {
    font-size: 16px;
    font-weight: 500;
}

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

.calendar-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 4px;
    border-radius: 8px;
    background: var(--tg-theme-secondary-bg-color);
    cursor: pointer;
    transition: background 0.2s;
}

.calendar-day.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

.calendar-day.today {
    border: 2px solid var(--tg-theme-button-color);
}

.day-name {
    font-size: 10px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.day-number {
    font-size: 16px;
    font-weight: 600;
}

.day-count {
    font-size: 10px;
    margin-top: 2px;
    opacity: 0.7;
}

/* =====================================================
   Зарплата
   ===================================================== */

.salary-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.salary-tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.salary-tab.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

.salary-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
}

.salary-total {
    margin-bottom: 20px;
}

.salary-amount {
    font-size: 42px;
    font-weight: 700;
    color: var(--success-color);
}

.salary-currency {
    font-size: 24px;
    color: var(--tg-theme-hint-color);
    margin-left: 4px;
}

.salary-breakdown {
    text-align: left;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.breakdown-label {
    color: var(--tg-theme-hint-color);
}

.breakdown-value {
    font-weight: 500;
}

.breakdown-item.positive .breakdown-value {
    color: var(--success-color);
}

.breakdown-item.negative .breakdown-value {
    color: var(--danger-color);
}

.salary-stats {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    text-align: center;
}

/* =====================================================
   Профиль
   ===================================================== */

.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.profile-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
}

.profile-info h2 {
    font-size: 18px;
    margin-bottom: 4px;
}

.profile-info p {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.settings-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.settings-section h3 {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.settings-list {
    display: flex;
    flex-direction: column;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

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

.setting-value {
    color: var(--tg-theme-hint-color);
}

/* Toggle switch */
.toggle {
    appearance: none;
    width: 50px;
    height: 30px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 15px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle::before {
    content: '';
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--tg-theme-bg-color, white);
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle:checked {
    background: var(--success-color);
}

.toggle:checked::before {
    transform: translateX(20px);
}

/* =====================================================
   Модальное окно
   ===================================================== */

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

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--tg-theme-bg-color);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--tg-theme-bg-color);
}

.modal-header h2 {
    font-size: 18px;
}

.close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.client-info {
    margin-bottom: 24px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-label {
    color: var(--tg-theme-hint-color);
}

.info-value {
    font-weight: 500;
}

.phone-link {
    color: var(--tg-theme-link-color);
    text-decoration: none;
}

.client-history h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 12px;
}

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

.history-date {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.history-status {
    display: inline-block;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
}

.history-master {
    font-size: 13px;
    color: var(--tg-theme-hint-color);
    margin-bottom: 4px;
}

.history-services {
    font-size: 14px;
}

.history-price {
    font-size: 14px;
    font-weight: 500;
    color: var(--success-color);
    margin-top: 4px;
}

/* =====================================================
   Аналитика
   ===================================================== */

.analytics-period-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.analytics-tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.analytics-tab.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

.analytics-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.analytics-period-label {
    font-size: 16px;
    font-weight: 500;
}

.analytics-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.analytics-section-title {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    text-transform: uppercase;
    margin-bottom: 16px;
}

/* Графики */
.chart-container {
    margin-bottom: 12px;
    overflow: hidden;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    height: 120px;
    gap: 2px;
    padding: 0 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chart-bar {
    flex: 0 0 auto;
    width: 12px;
    min-width: 8px;
    background: var(--tg-theme-button-color);
    border-radius: 3px 3px 0 0;
    min-height: 4px;
    transition: height 0.3s ease;
}

/* Для недели - шире столбцы */
.chart-bars.week-view .chart-bar {
    width: 32px;
    min-width: 24px;
}

.chart-bar.income-bar {
    background: var(--success-color);
}

.chart-labels {
    display: flex;
    justify-content: flex-start;
    padding: 8px 4px 0;
    border-top: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chart-label {
    font-size: 9px;
    color: var(--tg-theme-hint-color);
    flex: 0 0 auto;
    width: 12px;
    min-width: 8px;
    text-align: center;
    white-space: nowrap;
}

/* Для недели - шире подписи */
.chart-labels.week-view .chart-label {
    width: 32px;
    min-width: 24px;
    font-size: 10px;
}

.chart-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
}

.summary-label {
    font-size: 13px;
    color: var(--tg-theme-hint-color);
}

.summary-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-theme-button-color);
}

.empty-chart {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

/* Статистика */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-box {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-box-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--tg-theme-button-color);
    margin-bottom: 4px;
}

.stat-box-label {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:active {
    opacity: 0.8;
}

.btn-primary {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

/* =====================================================
   Утилиты
   ===================================================== */

.text-muted {
    color: var(--tg-theme-hint-color);
}

.text-success {
    color: var(--success-color);
}

.text-warning {
    color: var(--warning-color);
}

.text-danger {
    color: var(--danger-color);
}
