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

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

/* Общие стили для дохода и расхода */
.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: #329d32;
    color: #ffffff;
}

.income-block:hover {
    background: #07580c;
    color: #ececec;
}

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

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

/* Блок перевода */
.transfer-block {
    background: #1185dd;
    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: #0f3c5f;
}

.transfer-block svg {
    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: 15px;
    margin-top: 15px;
    margin-left: 10px;
    margin-right: 10px;
    flex-shrink: 0; /* Не скроллируется */
}

.operations-title {
    font-size: 1em;
    font-weight: 500;
    color: #a6b1c2;
    margin-left: 10px;
    cursor: pointer;
    transition: color 0.2s ease;
    user-select: none;
}

.operations-title:hover {
    color: #f5f6fa;
}

/* Поиск операций */
.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 {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 5px;
    background: #353942;
    padding: 5px 15px 5px 10px;
    margin: 0 5px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

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

/* Заголовки дат в списке операций - STICKY (прилипают при скролле) */
/* В статистике .date-label имеет свои стили без sticky - см. stats.css */
.date-label {
    background: #1c1e21;
    color: #d4d5d5;
    border-radius: 5px;
    padding: 2px 25px 3px 25px;
    font-size: 1em;
    font-weight: 500;
    margin: 8px 0px 0px 0%;
    width: calc(100% + 0);
    box-sizing: border-box;
    position: sticky;
    user-select: none;
    top: 0;
    z-index: 10;
    
    /* Добавляем тень для лучшей видимости поверх операций */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    
    /* Плавный переход при смене дат */
    transition: all 0.2s ease-in-out;
}

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

.operation-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Вертикальное выравнивание по центру */
    padding: 8px 10px;
    /* Увеличен отступ для удобства */
    border-bottom: 1px solid #555;
    width: 98%;
    font-size: 16px;
    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: 5px;
    /* Отступ справа от суммы */
    overflow: hidden;
    gap: 2px;
    min-width: 0; /* Важно для flex-контейнера */
}

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

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

/* Описание */
.operation-desc {
    flex: 1;
    color: #a6b1c2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
    min-width: 0; /* Важно для text-overflow */
}

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

/* Категория */
.operation-category-small {
    user-select: none;
    flex-shrink: 0; /* Не сжимается */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* Важно для text-overflow */
    max-width: 60%; /* Ограничиваем ширину */
}

/* Кто добавил */
.operation-who-small {
    user-select: none;
    opacity: 0.7;
    flex-shrink: 0; /* Не сжимается */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%; /* Ограничиваем ширину */
    min-width: 0; /* Важно для text-overflow */
}

/* Правая часть: сумма */
.operation-sum {
    min-width: 30px;
    /* Увеличена ширина для удобства */
    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 {
    /* Операции теперь немедленно удаляются из списка */
    display: none;
}

/* --- Кнопка добавления/закрытия категории для операций --- */
.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;
}

/* --- Специфичные стили для кнопки отмены в модалке добавления категории --- */
#addCategoryModal .add-category-cancel-btn {
  background: #e84118 !important; /* Красный цвет */
  color: #fff !important;
  border: none !important;
  border-radius: 8px !important;
  width: 32px !important;
  height: 32px !important;
  font-size: 1.2em !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: none !important;
  transition: background 0.2s ease !important;
  padding: 0 !important;
  margin: 0 !important;
}

#addCategoryModal .add-category-cancel-btn:hover {
  background: #c0392b !important; /* Более темный красный при наведении */
}

.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: 7px 8px;
    font-size: 14px; /* было 0.9em, увеличиваем на 2px */
    width: 100%;
    gap: 4px;
  }

  .operations-header {
    margin-top: 10px;
  }
  
  /* --- Добавлен отступ между элементами --- */
  .operation-main-info {
    flex-direction: row;
    align-items: baseline;  /* Вместо flex-end */
    gap: 12px;
  }
  
  .operation-sub-info {
    flex-direction: row;
    align-items: baseline;  /* Вместо end */
    gap: 12px;
  }
  
  /* Улучшение скролла для мобильных устройств */
  .operations-block {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* Улучшение sticky заголовков на мобильных */
  .date-label,
  .scheduled-operations-label {
    font-size: 13px; /* Немного больше на мобильных */
    padding: 4px 20px 5px 20px; /* Больше отступы для лучшего touch */
  }
  
  /* Стили для модалки добавления категории на мобильных */
  #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: 1.2em;
  }
  
  /* Мобильные стили для кнопки отмены в модалке добавления категории */
  #addCategoryModal .add-category-cancel-btn {
    width: 50% !important;
    height: 28px !important;
    font-size: 1.1em !important;
  }
  
  /* Уменьшение отступов для мобильных */
  .operations-title {
    font-size: 1.2em;
    
  }
  
  /* Адаптация поиска */
  .search-input {
    font-size: 0.85em;
    padding: 8px 10px;
   /* max-width: 140px;*/
  }
  
  /* Адаптация блоков доход/расход */
  .income-expense-container {
    gap: 8px;
    /*margin: 20px 5px 10px 5px;*/
  }
  
  .income-block,
  .expense-block {
    padding: 10px 15px;
    min-width: 120px;
    font-size: 15px;
  }
  
  .transfer-block {
    width: 40px;
    padding: 4px;
  }
  
  .transfer-block svg {
    width: 18px;
    height: 18px;
  }
}

/* ========================================
   ПОЛЯ ПЛАНИРОВАНИЯ В ПОЛНОЭКРАННОЙ ВЕРСИИ
   ======================================== */

.operation-schedule-fields {
    margin-top: 16px;
    width: 70%;
    margin-left: auto;
    margin-right: auto;
}

.operation-schedule-section {
    /*margin-bottom: 24px;*/
    text-align: center;
}

.operation-schedule-title {
    font-size: 1.1em;
    font-weight: 600;
    color: #f5f6fa;
    text-align: center;
    margin-bottom: 16px;
   /* background: #1d6fc1;*/
    padding: 8px 16px;
    border-radius: 2px;
    display: inline-block;
    margin-left: auto;
    margin-right: auto;
    width: fit-content;
}

.operation-schedule-label {
    font-size: 1.1em;
    font-weight: 600;
    color: #a6b1c2;
    margin-bottom: 12px;
    display: block;
}

.operation-schedule-select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #444a56;
    border-radius: 8px;
    background: #444a56;
    color: #f5f6fa;
    font-size: 1em;
    cursor: pointer;
    outline: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.operation-schedule-select:hover {
    background: #555b67;
    border-color: #555b67;
}

.operation-schedule-select:focus {
    background: #555b67;
}

.operation-schedule-select option {
    background: #444a56;
    color: #f5f6fa;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 2px 0;
}

.operation-schedule-select option:hover {
    background: #555b67;
}

.operation-schedule-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #444a56;
    border-radius: 8px;
    background: #444a56;
    color: #f5f6fa;
    font-size: 1em;
    outline: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.operation-schedule-input:hover {
    background: #555b67;
    border-color: #555b67;
}

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

.operation-schedule-input::placeholder {
    color: #a6b1c2;
}

/* Адаптация для мобильных устройств */
@media (max-width: 500px) {
    .operation-schedule-fields {
      width: 80%;
      border: 2px solid #444a56;
      border-radius: 10px;
      padding: 25px;
  }
    
    .operation-schedule-title {
        font-size: 1em;
        margin-bottom: 12px;
        padding: 6px 12px;
    }
    
    .operation-schedule-label {
        font-size: 1em;
        margin-bottom: 10px;
        text-align: left;
    }
    
    .operation-schedule-select,
    .operation-schedule-input {
        font-size: 0.9em;
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .operation-schedule-fields {
      width: 75%;
      border: 2px solid #444a56;
      border-radius: 10px;
      padding: 20px;
    }
    
    .operation-schedule-title {
        font-size: 0.95em;
        margin: 5px;
        padding: 5px 10px;
    }
    
    .operation-schedule-label {
        font-size: 0.95em;
        margin-bottom: 8px;
        text-align: left;
    }
    
    .operation-schedule-select,
    .operation-schedule-input {
        font-size: 0.85em;
        padding: 8px 10px;
        height: 40px;
    }
}

/* ========================================
   ЗАПЛАНИРОВАННЫЕ ОПЕРАЦИИ
   ======================================== */

/* Группа запланированных операций - как обычная группа дат */
.scheduled-operations-group {
    margin-bottom: 10px;
}

/* Контейнер для запланированных операций */
.scheduled-operations-container {
    margin-top: 12px; /* Увеличенный отступ сверху */
}

/* Заголовок запланированных операций - как обычный заголовок даты */
.scheduled-operations-label {
    background: #8a571a;
    color: white;
    font-weight: 600;
    border-radius: 5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    
    /* Sticky поведение для заголовка запланированных операций */
    position: sticky;
    top: 0;
    z-index: 15; /* Выше обычных дат, так как запланированные операции важнее */
    
    /* Добавляем тень для лучшей видимости */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.scheduled-operations-label:hover {
    background: #643a02;
}

.scheduled-icon {
    font-size: 1em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.scheduled-icon svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Иконка сворачивания для запланированных операций */
.collapse-icon {
    float: right;
    font-size: 0.9em;
    margin-left: 10px;
    transition: transform 0.3s ease;
    cursor: pointer;
    color: #dc8212;
}

/* Поворот иконки на -90 градусов для свернутого состояния */
.collapse-icon.collapsed {
    transform: rotate(-90deg);
}


/* Строка запланированной операции - точно как обычная операция */
.scheduled-operation-row {
    border-left: 3px solid #b77a10;
    border-radius: 5px;
    margin-bottom: 8px;
    margin-left: 5px;
    padding: 5px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    cursor: pointer;
    box-sizing: border-box;
    width: 100%;
}

/* Выделение просроченных и сегодняшних запланированных операций */
.scheduled-operation-row.urgent-scheduled {
    border-left: 4px solid #e84118;
}



/* Кнопка выполнения запланированной операции - компактная галочка */
.execute-scheduled-btn {
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 15px;
}

.execute-scheduled-btn:hover {
    background: #45a049;
    transform: scale(1.1);
}

.execute-scheduled-btn:active {
    transform: scale(0.95);
}

/* Дата в запланированной операции */
.operation-date-small {
    color: #fff;
    font-size: 0.85em;
    font-weight: 400;
    background: #b57b0b;
    padding: 1px 5px;
    border-radius: 5px;
}

/* Красный фон для срочных дат в запланированных операциях */
.operation-date-small.urgent-date {
    background: #e84118;
}

/* Адаптивность для запланированных операций */
@media (max-width: 480px) {
    .scheduled-operations-label {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .scheduled-operation-row {
        padding: 7px 8px;
    }
    
    .execute-scheduled-btn {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
    
    .operation-date-small {
        font-size: 0.8em;
    }
}

/* ===================================================== */
/* СТИЛИ ДЛЯ СРОЧНЫХ ЗАПЛАНИРОВАННЫХ ОПЕРАЦИЙ */
/* ===================================================== */

/* Красный фон для срочных операций (сегодня и завтра) */
.scheduled-operations-label.urgent-operations {
    background: #d32f2f !important; /* Более красный фон */
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.3);
}


