/* ========================================
   OPERATIONS.CSS - ОПЕРАЦИИ
   ========================================
   
   Содержит:
   - Блоки доход/расход/перевод
   - Список операций
   - Поиск операций
   - Строки операций
   - Заголовки секций
*/

/* Контейнер для блоков доход/расход/перевод */
.income-expense-container {
    display: flex;
    gap: 10px;
    margin: 15px;
    justify-content: center;
}

/* Общие стили для дохода и расхода */
.income-block,
.expense-block {
    flex: 1;
    border-radius: 14px;
    padding: 15px 25px;
    font-weight: 600;
    user-select: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    box-sizing: border-box;
    min-width: 140px;
}

/* Блок дохода */
.income-block {
    background: #c9f0c9;
    color: #1a611a;
}

.income-block:hover {
    background: #0f5f14;
    color: #ececec;
}

/* Блок расхода */
.expense-block {
    background: #f7cdcd;
    color: #7a0505;
}

.expense-block:hover {
    background: #5e0b0b;
    color: #fdfbfb;
}

/* Блок перевода */
.transfer-block {
    background: #516f86;
    color: #fff;
    border-radius: 14px;
    padding: 5px;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    width: 48px;
    min-width: unset;
    flex: none;
}

.transfer-block:hover {
    background: #3a4f5f;
}

.transfer-block svg {
    width: 20px;
    height: 20px;
    transition: transform 0.2s;
    color: #fff;
}

.transfer-block:hover svg {
    transform: rotate(180deg);
}

/* Заголовки секций */
.month-header {
    margin-bottom: 20px;
    text-align: left;
}

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

.operations-title {
    font-size: 1em;
    font-weight: bold;
    color: #a6b1c2;
    margin: 20px 15px 5px 15px
}

/* Поиск операций */
.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: #444a56;
    color: #f5f6fa;
    font-size: 0.9em;
    max-width: 300px;
    outline: none;
    margin-right: 10px;
}

.search-input::placeholder {
    color: #a6b1c2;
}

.search-input:focus {
    background: #555b67;
}

.search-clear-btn {
    position: absolute;
    right: 15px;
    background: none;
    border: none;
    color: #a6b1c2;
    cursor: pointer;
    font-size: 1.2em;
    padding: 2px;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-clear-btn:hover {
    background: #555b67;
    color: #f5f6fa;
}

/* Блок со списком операций */
.operations-block {
    max-height: 300px;
    overflow-y: auto;
    border-radius: 5px;
    background: #353942;
    padding: 5px 15px 5px 10px;
    margin: 0 4px;
}

/* Скрытие скроллбара */
.operations-block::-webkit-scrollbar {
    display: none;
}

/* Заголовки дат в списке операций */
.date-label {
    background: #221f1cab;
    color: #cac6c6;
    border-radius: 5px;
    padding: 2px 25px 3px 25px;
    font-size: 0.7em;
    font-weight: 500;
    margin: 8px 0px 0px 0%;
    width: calc(100% + 0);
    box-sizing: border-box;
    user-select: none;
}

/* Операции */

.operation-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Вертикальное выравнивание по центру */
    padding: 8px 10px;
    /* Увеличен отступ для удобства */
    border-bottom: 1px dotted #555;
    width: 98%;
    font-size: 0.99em;
    cursor: pointer;
    transition: background 0.15s;
    flex-wrap: nowrap;
    /* Запрет переноса */
    /* Запрет выделения текста для предотвращения выделения при долгом тапе */
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Глобальные правила для всех элементов операций */
.operation-row * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

.operation-row:hover {
    background: #3a3f48;
    border-radius: 7px;
}

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

.operation-left {
    display: flex;
    flex-direction: column;
    /* Две строки текста */
    flex-grow: 1;
    /* Занимает всё доступное пространство */
    margin-right: 12px;
    /* Отступ справа от суммы */
    overflow: hidden;
    gap: 2px;
}

/* Верхняя строка: счет и описание */
.operation-main-info {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 2px;
    overflow: hidden;
}

/* Название счета */
.operation-account {
    font-weight: 500;
    color: #f5f6fa;
    white-space: nowrap;
    /* дополнительный перенос */
    overflow: visible;
    text-overflow: ellipsis;
    flex-shrink: 0;
    max-width: 65%; /* Ограничение ширины */
    text-transform: capitalize;
}

/* Описание */
.operation-desc {
    flex: 1;
    color: #a6b1c2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
}

/* Нижняя строка: категория и кто добавил */
.operation-sub-info {
    display: flex;
    align-items: baseline;
    gap: 15px;
    font-size: 0.75em;
    /* Мелкий шрифт */
    color: #8c96a7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Категория */
.operation-category-small {
    user-select: none;
}

/* Кто добавил */
.operation-who-small {
    user-select: none;
    opacity: 0.7;
}

/* Правая часть: сумма */
.operation-sum {
    min-width: 80px;
    /* Увеличена ширина для удобства */
    text-align: right;
    font-weight: 600;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-tap-highlight-color: transparent !important;
    flex-shrink: 0;
    /* Не сжимается */
}

.operation-sum.income {
    color: #50ee38;
}

.operation-sum.expense {
    color: #f75932;
}

/* Операции, которые нельзя редактировать */
.operation-row.operation-readonly {
    opacity: 0.7;
    cursor: default;
}

.operation-row.operation-readonly:hover {
    background: #353942 !important;
    border-radius: 0 !important;
}

.operation-row.operation-readonly .operation-account {
    color: #8c96a7;
    text-transform: capitalize;
}

.operation-row.operation-readonly .operation-desc {
    color: #6a737d;
}

.operation-row.operation-readonly .operation-category-small {
    color: #6a737d;
}

.operation-row.operation-readonly .operation-who-small {
    color: #6a737d;
}

/* Стили для временных операций */
.operation-row.operation-temporary {
    opacity: 0.85;
    background: linear-gradient(90deg, transparent 0%, rgba(35, 207, 35, 0.05) 50%, transparent 100%);
    animation: pulse-temporary 3s ease-in-out infinite;
}

.operation-row.operation-temporary .operation-account {
    text-transform: capitalize;
}

.operation-row.operation-temporary:hover {
    opacity: 0.9;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 193, 7, 0.1) 50%, transparent 100%);
}

@keyframes pulse-temporary {
    0%, 100% {
        background: linear-gradient(90deg, transparent 0%, rgba(73, 206, 55, 0.05) 50%, transparent 100%);
    }
    50% {
        background: linear-gradient(90deg, transparent 0%, rgba(255, 193, 7, 0.1) 50%, transparent 100%);
    }
}

/* Стили для удаленных операций */
.operation-row.just-deleted {
    opacity: 0.3;
    background: #f5f5f5;
    text-decoration: line-through;
    pointer-events: none;
    transition: all 0.3s ease;
    transform: translateX(-10px);
}

.operation-row.just-deleted .operation-sum {
    opacity: 0.5;
}

.operation-row.just-deleted .operation-account,
.operation-row.just-deleted .operation-desc,
.operation-row.just-deleted .operation-category-small,
.operation-row.just-deleted .operation-who-small {
    color: #999;
}

.operation-row.just-deleted .operation-account {
    text-transform: capitalize;
}

/* Анимация удаления */
@keyframes fade-out-delete {
    0% {
        opacity: 1;
        transform: translateX(0);
    }
    100% {
        opacity: 0.3;
        transform: translateX(-10px);
    }
}

.operation-row.just-deleted {
    animation: fade-out-delete 0.3s ease forwards;
}

/* --- Кнопка добавления/закрытия категории для операций --- */
.op-close-btn, .add-category-btn {
  background: #444a56;
  color: #a6b1c2;
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 40px;
  font-size: 1.5em;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}
.op-close-btn:hover, .add-category-btn:hover {
  background: #5a6170;
}

/* --- Модалки добавления/редактирования категории --- */
#addCategoryModal .modal,
#editCategoryModal .modal {
  min-width: 280px;
  max-width: 90vw;
  background: #444a56;
  border-radius: 12px;
  box-shadow: 0 4px 32px #0006;
  padding: 28px 20px 20px 20px;
  text-align: center;
}
#addCategoryModal .modal-header,
#editCategoryModal .modal-header {
  font-size: 1.2em;
  margin-bottom: 16px;
  color: #a6b1c2;
}
#addCategoryModal .modal-input,
#editCategoryModal .modal-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid #a6b1c2;
  font-size: 0.9em;
  background: #444a56;
  color: #a6b1c2;
  margin-bottom: 16px;
}
#addCategoryModal .modal-actions,
#editCategoryModal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
#addCategoryModal .ok-btn, #addCategoryModal .close-btn,
#editCategoryModal .ok-btn, #editCategoryModal .close-btn {
  padding: 8px 24px;
  border-radius: 8px;
  border: none;
  font-size: 1em;
  cursor: pointer;
}
#addCategoryModal .ok-btn, #editCategoryModal .ok-btn {
  background: #44bd32;
  color: #fff;
}
#addCategoryModal .close-btn, #editCategoryModal .close-btn {
  background: #2e323a;
  color: #fff;
}
#addCategoryModal .modal-input.error,
#editCategoryModal .modal-input.error {
  background: #e84118;
  color: #fff;
}

.category-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.category-header-actions {
  display: flex;
  gap: 8px;
}

/* /////////////////////////////////////////////////////////////
   МЕДИАЗАПРОСЫ ДЛЯ МОБИЛЬНЫХ (до 600px)
   ///////////////////////////////////////////////////////////// */
@media (max-width: 500px) {
  /* Уникальные стили для операций, которые не дублируются с base.css */
  .operation-row {
    flex-direction: row;
    align-items: center;
    padding: 10px 8px;
    font-size: 0.95em; /* было 0.9em, увеличиваем на 2px */
    width: 100%;
    gap: 4px;
  }
  
  /* --- Добавлен отступ между элементами --- */
  .operation-main-info {
    flex-direction: row;
    align-items: flex-end;
    gap: 12px;
  }
  
  .operation-sub-info {
    flex-direction: row;
    align-items: end;
    gap: 12px;
  }
  
  /* Улучшение скролла для мобильных устройств */
  .operations-block {
    max-height: 60vh;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* Стили для модалки добавления категории на мобильных */
  #addCategoryModal.modal-bg {
    align-items: flex-end;
    padding-bottom: 20px;
  }
  
  /* Поддержка safe-area для iPhone */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    #addCategoryModal.modal-bg {
      padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    #addCategoryModal .modal {
      margin-bottom: calc(20px + env(safe-area-inset-bottom));
    }
  }
  
  #addCategoryModal .modal {
    min-width: 280px;
    max-width: 90vw;
    padding: 16px 12px 12px 12px; /* Уменьшаем отступы */
    margin-bottom: 20px;
  }
  
  #addCategoryModal .modal-header {
    font-size: 1.1em; /* Немного уменьшаем размер */
    margin-bottom: 12px; /* Уменьшаем отступ */
  }
  
  #addCategoryModal .modal-input {
    padding: 8px 10px; /* Уменьшаем padding */
    margin-bottom: 12px; /* Уменьшаем отступ */
    font-size: 0.9em;
  }
  
  #addCategoryModal .modal-actions {
    gap: 8px; /* Уменьшаем отступ между кнопками */
  }
  
  #addCategoryModal .ok-btn,
  #addCategoryModal .close-btn {
    padding: 6px 16px; /* Уменьшаем padding кнопок */
    font-size: 0.9em;
  }
  
  /* Уменьшение отступов для мобильных */
  .operations-title {
    font-size: 0.9em;
    margin: 15px 10px 5px 10px;
  }
  
  /* Адаптация поиска */
  .search-input {
    font-size: 0.85em;
    padding: 8px 10px;
    max-width: 120px;
  }
  
  /* Адаптация блоков доход/расход */
  .income-expense-container {
    gap: 8px;
    margin: 10px;
  }
  
  .income-block,
  .expense-block {
    padding: 12px 16px;
    min-width: 120px;
    font-size: 0.9em;
  }
  
  .transfer-block {
    width: 40px;
    padding: 4px;
  }
  
  .transfer-block svg {
    width: 18px;
    height: 18px;
  }
}
