body {
    font-family: Arial, sans-serif;
    margin: 0;
    background: #f5f7fa;
    color: #222;
}

.topbar {
    background: #2f6f8f;
    color: #fff;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.brand {
    font-weight: bold;
    font-size: 18px;
    white-space: nowrap;
}

.nav {
    display: flex;
    gap: 18px;
    align-items: center;
    flex-wrap: wrap;
}

.nav a {
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}

.nav .user {
    font-weight: bold;
    opacity: 0.95;
}

.container {
    max-width: 1450px;
    margin: 24px auto;
    padding: 0 16px;
}

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

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}

.card h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
}

.big-number {
    font-size: 28px;
    font-weight: bold;
}

.section {
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08);
    margin-bottom: 24px;
}

.section h2 {
    margin-top: 0;
    font-size: 22px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.three-col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 8px;
    border-bottom: 1px solid #e6e6e6;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f0f4f8;
}

a {
    color: #2f6f8f;
}

.muted {
    color: #666;
    font-size: 13px;
}

.actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.button-link {
    display: inline-block;
    background: #2f6f8f;
    color: #fff !important;
    text-decoration: none;
    padding: 10px 14px;
    border-radius: 8px;
}

.button-link.secondary {
    background: #6c7a86;
}

.form-control,
.form-select {
    width: 100%;
    max-width: 520px;
    padding: 10px 12px;
    border: 1px solid #cfd8df;
    border-radius: 8px;
    font-size: 15px;
    box-sizing: border-box;
}

.form-control {
    background: #fff;
}

.form-select {
    background: #fff;
}

.form-checkbox {
    transform: scale(1.2);
}

@media (max-width: 1200px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .three-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .two-col,
    .grid-4,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }
}
.tx-items-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tx-item-card {
    border: 1px solid #d9e1e7;
    border-radius: 10px;
    padding: 14px;
    background: #f9fbfc;
}

.tx-item-main-row {
    display: grid;
    grid-template-columns: 1.4fr 1.4fr 0.8fr auto;
    gap: 12px;
    align-items: start;
}

.tx-item-field label {
    display: block;
    font-weight: bold;
    margin-bottom: 6px;
}

.tx-item-comment {
    margin-top: 12px;
}

.tx-item-comment textarea {
    min-height: 38px;
    resize: vertical;
}

.tx-item-delete {
    padding-top: 28px;
}

@media (max-width: 1000px) {
    .tx-item-main-row {
        grid-template-columns: 1fr;
    }

    .tx-item-delete {
        padding-top: 0;
    }
}
/* =========================================================
   Позиции транзакции / распределение транзакции
   ========================================================= */

/* Общий контейнер списка позиций */
.tx-items-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Одна карточка позиции */
.tx-item-card {
    background: #f9fbfc;
    border: 1px solid #d9e1e7;
    border-radius: 10px;
    padding: 14px;
}

/* Верхняя строка карточки:
   продукт, категория, цена, количество, итог, удаление */
.tx-item-grid {
    display: grid;

    /* 6 колонок:
       продукт | категория | цена | кол-во | итог | удалить */
    grid-template-columns: 2fr 2fr 1fr 1fr 1fr 0.6fr;

    gap: 12px;
    align-items: end;
}

/* Один блок поля внутри карточки */
.tx-item-field label {
    display: block;
    font-weight: bold;
    margin-bottom: 6px;
}

/* Комментарий всегда отдельной строкой на всю ширину */
.tx-item-comment {
    margin-top: 12px;
}

/* Комментарий по умолчанию маленький, но пользователь может растянуть */
.tx-item-comment textarea {
    min-height: 38px;
    resize: vertical;
}

/* Поле удаления выравниваем с остальными полями */
.tx-item-delete {
    padding-top: 28px;
}

/* Кнопка без inline-style */
.button-submit {
    border: none;
    cursor: pointer;
    font: inherit;
}

/* Скрываем оригинальный select, когда JS строит красивый autocomplete.
   Сам select остаётся в форме, потому что Django должен получить ID. */
.autocomplete-hidden-select {
    display: none;
}

/* Контейнер autocomplete */
.autocomplete-box {
    position: relative;
}

/* Выпадающий список вариантов */
.autocomplete-dropdown {
    position: absolute;
    z-index: 50;
    left: 0;
    right: 0;
    top: 100%;
    background: #fff;
    border: 1px solid #cfd8df;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    max-height: 220px;
    overflow-y: auto;
    margin-top: 4px;
}

/* Один вариант в выпадающем списке */
.autocomplete-option {
    padding: 9px 10px;
    cursor: pointer;
}

/* Подсветка при наведении */
.autocomplete-option:hover {
    background: #eef4f7;
}

/* Текст, если ничего не найдено */
.autocomplete-empty {
    padding: 9px 10px;
    color: #666;
}

/* Адаптивность: на узком экране карточка становится вертикальной */
/* @media (max-width: 1200px) {
    .tx-item-grid {
        grid-template-columns: 1fr 1fr;
    }

    .tx-item-delete {
        padding-top: 0;
    }
}

@media (max-width: 700px) {
    .tx-item-grid {
        grid-template-columns: 1fr;
    }
}


.form-error {
    margin-top: 6px;
    color: #b00020;
}

.tx-items-actions {
    margin-top: 14px;
}

.tx-items-help {
    margin-top: 10px;
}
*/
/* =========================================================
   Финальный вид карточки позиции транзакции
   ========================================================= */

.tx-items-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tx-item-card {
    display: block;
    background: #f9fbfc;
    border: 1px solid #d9e1e7;
    border-radius: 10px;
    padding: 14px;
}

.tx-item-grid {
    display: grid !important;
    grid-template-columns: minmax(220px, 2fr) minmax(220px, 2fr) 110px 90px 110px 70px;
    gap: 12px;
    align-items: end;
}

.tx-item-field label {
    display: block;
    font-weight: bold;
    margin-bottom: 6px;
}

.tx-item-field input,
.tx-item-field select,
.tx-item-field textarea {
    max-width: none;
}

.tx-item-comment {
    margin-top: 12px;
}

.tx-item-comment textarea {
    width: 100%;
    min-height: 38px;
    resize: vertical;
}

.tx-item-delete {
    padding-bottom: 10px;
}

/* Выпадающий список autocomplete */
.autocomplete-box {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    z-index: 100;
    left: 0;
    right: 0;
    top: 100%;
    background: #fff;
    border: 1px solid #cfd8df;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    max-height: 220px;
    overflow-y: auto;
    margin-top: 4px;
}

.autocomplete-option {
    padding: 9px 10px;
    cursor: pointer;
}

.autocomplete-option:hover {
    background: #eef4f7;
}

.autocomplete-empty {
    padding: 9px 10px;
    color: #666;
}

/* Убираем браузерные стрелки у number-полей.
   Свои кнопки +/- можно добавим позже нормально и красиво. */
.tx-item-card input[type="number"]::-webkit-inner-spin-button,
.tx-item-card input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.tx-item-card input[type="number"] {
    -moz-appearance: textfield;
}

@media (max-width: 1200px) {
    .tx-item-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 700px) {
    .tx-item-grid {
        grid-template-columns: 1fr;
    }
}
/* =========================================================
   Модальное окно быстрого создания справочников
   ========================================================= */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.35);

    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-window {
    width: min(520px, calc(100vw - 32px));
    background: #fff;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
}

.modal-header h2 {
    margin: 0;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.modal-label {
    display: block;
    font-weight: bold;
    margin: 12px 0 6px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 18px;
}


/* 
   ВАЖНО:
   Модальные окна по умолчанию должны быть скрыты,
   если у элемента есть HTML-атрибут hidden.

   Без этого правила .modal-backdrop { display: flex; }
   может перебить hidden, и модалка будет открываться сразу при загрузке страницы.
*/
.modal-backdrop[hidden] {
    display: none !important;
}
