/* ========================================
   BASE.CSS - БАЗОВЫЕ СТИЛИ
   ========================================
   
   Содержит:
   - Общие стили (body, header, container)
   - Типографика
   - Основные цвета и переменные
   - Анимации
   - Система уведомлений
*/

/* Основные стили страницы */
body {
    background: #23272f;
    color: #f5f6fa;
    font-family: 'Segoe UI', sans-serif;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Заголовок приложения */
.header {
    padding: 10px 0 6px 0;
    text-align: center;
    background: #2e323a;
    font-size: 1.15em;
    font-weight: bold;
    cursor: pointer;
    letter-spacing: 1px;
    border-radius: 16px;
    margin: 10px auto 8px auto;
    max-width: 600px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

/* Основной контейнер приложения */
.container {
    max-width: 600px;
    margin: 24px auto;
    padding: 16px;
    background: #2e323a;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    box-sizing: border-box;
}

#app-container {
  min-height: 100vh;
  height: 100vh;
  width: 100vw;
  box-sizing: border-box;
  /* Можно добавить background, если нужно */
}

/* Анимация появления */
@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   СИСТЕМА УВЕДОМЛЕНИЙ
   ========================================
   
   Универсальная система уведомлений для замены alert()
   - Успешные действия: зеленый цвет
   - Ошибки: красный цвет
   - Позиция: сверху по центру экрана
   - Анимация: плавное появление и исчезновение
*/

/* Контейнер уведомления */
.notification {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    animation: notificationSlideIn 0.3s ease forwards;
    max-width: 90%;
    text-align: center;
    word-wrap: break-word;
}

/* Анимация появления уведомления */
@keyframes notificationSlideIn {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Анимация исчезновения уведомления */
@keyframes notificationSlideOut {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* Успешные уведомления (зеленые) */
.notification.success {
    background: #4caf50;
    border-left: 4px solid #45a049;
}

/* Уведомления об ошибках (красные) */
.notification.error {
    background: #f44336;
    border-left: 4px solid #d32f2f;
}

/* Уведомления с предупреждением (оранжевые) */
.notification.warning {
    background: #ff9800;
    border-left: 4px solid #f57c00;
}

/* Уведомления с информацией (синие) */
.notification.info {
    background: #2196f3;
    border-left: 4px solid #1976d2;
} 

.last-sync-time {
  font-size: 0.5em; /* ещё мельче */
  color: #c0c7d1;    /* светлее */
  font-weight: 400;  /* обычный, не жирный */
  margin-left: 5px;
  display: inline;
  vertical-align: middle;
  line-height: 1.2;
} 

/* /////////////////////////////////////////////////////////////
   МЕДИАЗАПРОСЫ ДЛЯ МОБИЛЬНЫХ УСТРОЙСТВ (до 600px)
   ///////////////////////////////////////////////////////////// */
@media (max-width: 500px) {
  body, html {
    font-size: 16px;
    /*padding: 5px;
    margin: 5px;*/
    max-width: 100vw;
    width: 100vw;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  body.noscroll {
    overflow: hidden !important;
    height: 100vh;
    position: fixed;
    width: 100vw;
  }

  .header {
    max-width: 100vw;
    width: 100vw;
    height: 90px;
    margin: 30px 0 20px 0;
    border-radius: 0;
    font-size: 1em;
    padding: 20px 0 0px 0;
  }
  .container {
    max-width: 100vw;
    width: 100vw;
    margin-top: 20px;
    padding: 15px 0px;
    border-radius: 10px;
    box-shadow: none;
    align-items: center;
    align-content: center;
    overflow-x: hidden !important;
  }
  /* --- Общие блоки: доходы/расходы/переводы --- */
  .income-expense-container {
    flex-direction: row;
    gap: 8px;
    margin-bottom: 16px;
    align-items: normal;
  }
  .income-block, .expense-block, .transfer-block {
    width: 10% !important;
    min-width: 0 !important;
    font-size: 1em;
    padding: 12px 8px;
    margin-bottom: 8px;
    align-items: center;
    height: auto;
  }
  .transfer-block {
    justify-content: center;
  }
  /* --- Операции: заголовок, блок, поиск (адаптация для мобилки) --- */
  .operations-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    flex-wrap: nowrap;
  }
  .operations-title {
    white-space: nowrap;      /* Не переносить текст */
    overflow: hidden;
    text-overflow: ellipsis; /* ... если не влезает */
    font-weight: bold;
    font-size: 1em;
    flex: 0 1 auto;           /* Только свою ширину */
    max-width: 70vw;
  }
  .search-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    flex: 0 0 auto;
    margin-left: auto;  
    margin-top: 15px;      /* Прижать к правому краю */
  }
  .search-input {
    min-width: 80px;
    max-width: 120px;
    width: 100%;
    font-size: 1em;
    border-radius: 8px 0 0 8px;
    border: 1px solid #ccc;
    padding: 6px 10px;
  }
  .search-clear-btn {
    border-radius: 0 8px 8px 0;
    border: 1px solid #ccc;
    border-left: none;
    background: #eee;
    font-size: 1.2em;
    padding: 0 10px;
    cursor: pointer;
    height: 100%;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .search-clear-btn svg {
    width: 14px;
    height: 14px;
    color: #666;
  }
  .operations-block {
    max-height: 60vh;
    padding: 4px 2px;
    font-size: 1em;
  }
    
  .date-label {
    font-size: 0.95em;
    padding: 2px 4px;
    width: 100%;
  }
  .modal, .date-modal, .category-modal {
    max-width: 98vw !important;
    min-width: 0 !important;
    border-radius: 10px !important;
    padding: 10px 2vw !important;
  }
  input {
    font-size: 0.8em !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }

  button {
    font-size: 1em;
    min-width: 0 !important;
    box-sizing: border-box;
  }

  select {
    font-size: 1em !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  .notification {
    max-width: 98vw;
    font-size: 1em;
    left: 1vw;
    transform: none;
  }
  /* Убираем горизонтальный скролл */
  html, body {
    overflow-x: hidden;
  }
  /* --- Кошелёк: селектор и кнопка --- */
  .wallet-selector {
    display: flex;
    align-items: center;
    justify-content: center;   /* Центрируем всё содержимое */
    gap: 4px;
    white-space: nowrap;
    width: 100%;
  }
  .wallet-selector-btn {
    font-weight: bold;
    font-size: 1.1em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70vw;       /* Можно уменьшить до 60vw, если всё равно не влазит */
    flex: 0 1 auto;        /* Пусть занимает всё доступное место */
    text-align: center;    /* Центрируем текст */
  }
  .wallet-menu-btn {
    background: none;
    border: none;
    font-size: 1.5em;      /* Сделать крупнее, если нужно */
    cursor: pointer;
    padding: 0 6px;
    color: #fff;
    line-height: 1;
    flex: 0 0 auto;        /* Не растягивать! */
  }
  .notification {
    left: 50% !important;
    transform: translateX(-50%) !important;
    top: 90px !important;
    right: auto !important;
    min-width: 120px;
    min-height: 32px;
    padding: 6px 12px;
    font-size: 0.95em;
    z-index: 9999;
    text-align: center;
    border-radius: 7px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90vw !important;
  }

  .last-sync-time {
    margin-left: -15px;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }
} 

/* ========================================
   TELEGRAM MINI APP - ПРЕДОТВРАЩЕНИЕ СВАЙПА ВНИЗ
   ======================================== */

.telegram-webapp {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.telegram-webapp body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* Разрешаем скролл только для определенных элементов */
.telegram-webapp .operations-block,
.telegram-webapp .category-fullscreen-content,
.telegram-webapp .transfer-fullscreen-content,
.telegram-webapp .stats-container,
.telegram-webapp .settings-container {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* Отключаем overscroll для остальных элементов */
.telegram-webapp .income-expense-container,
.telegram-webapp .balance-block,
.telegram-webapp .header,
.telegram-webapp .footer-nav {
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Улучшенные стили для блоков доход/расход/перевод */
.telegram-webapp .income-block,
.telegram-webapp .expense-block,
.telegram-webapp .transfer-block {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ========================================
   СТИЛИ КНОПОК ДЛЯ МОДАЛЬНЫХ ОКОН
   ======================================== */

.btn-primary {
    background: #44bd32;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #3aa028;
}

.btn-secondary {
    background: #2e323a;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #444a56;
}