/* ======================================================================= */
/* === ИСТОРИЯ ТРАНЗАКЦИЙ: ТАБЫ, СЕТКА (ТАБЛИЦА) И ПАГИНАЦИЯ           === */
/* ======================================================================= */

/* 1. Табы фильтров (как на скриншоте) */
.history-tabs-container {
    display: flex;
    margin-bottom: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
    width: max-content; /* Ширина по контенту */
}

.hist-tab-btn {
    background: transparent;
    border: none;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.hist-tab-btn:last-child {
    border-right: none;
}

.hist-tab-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.hist-tab-btn.active {
    background: rgba(255, 87, 34, 0.15); /* Ваш оранжевый акцент */
    color: #ff5722; /* Оранжевый текст для активного таба */
}

/* 2. Шапка таблицы (сетки) */
.history-grid-header {
    display: grid;
    /* Пропорции колонок: Дата(140px) | Описание(остальное) | Сумма(100px) | Баланс(100px) */
    grid-template-columns: 140px 1fr 100px 100px;
    gap: 10px;
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* 3. Строки данных */
.transaction-history-grid {
    display: flex;
    flex-direction: column;
}

.tx-grid-row {
    display: grid;
    grid-template-columns: 140px 1fr 100px 100px;
    gap: 10px;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: center;
    transition: background 0.2s;
    font-size: 0.85rem;
    color: #e2e8f0;
}

.tx-grid-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

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

/* Стилизация отдельных колонок */
.tx-col.tx-date {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums; /* Чтобы цифры даты не "плясали" по ширине */
}

.tx-col.tx-desc {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-icon-mini {
    opacity: 0.8;
}

.tx-desc-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-col.tx-amount {
    text-align: right;
    font-weight: 700;
    font-family: monospace; /* Выравниваем цифры */
    font-size: 0.95rem;
}

/* Mobile transaction dialogs: one viewport, large controls, card ledger. */
@media (max-width: 768px) {
    #userActivityModal .modal-dialog,
    #adminTxModal .modal-dialog {
        width: auto;
        max-width: none;
        height: calc(100dvh - 12px);
        min-height: 0;
        margin: 6px;
        align-items: stretch;
    }
    #userActivityModal .modal-content,
    #adminTxModal .modal-content {
        width: 100%;
        height: 100%;
        max-height: none;
        overflow: hidden;
        border-radius: 18px;
    }
    #userActivityModal .modal-header,
    #adminTxModal .modal-header {
        min-height: 58px;
        padding: 12px 14px !important;
        flex: 0 0 auto;
    }
    #userActivityModal .modal-title,
    #adminTxModal .modal-title {
        min-width: 0;
        margin-right: 8px;
        overflow: hidden;
        font-size: 0.95rem;
        line-height: 1.25;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #userActivityModal .modal-body,
    #adminTxModal .modal-body {
        min-height: 0;
        padding: 12px !important;
        flex: 1 1 auto;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }
    #userActivityModal .history-tabs-container,
    #adminTxModal .ref-tabs-wrapper {
        position: sticky;
        z-index: 3;
        top: -12px;
        width: 100%;
        margin-bottom: 10px !important;
        padding: 7px 0;
        background: #0a0a0c;
    }
    #userActivityModal .history-tabs-container {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    #userActivityModal .hist-tab-btn,
    #adminTxModal .ref-tab-btn {
        min-width: 0;
        min-height: 44px;
        padding: 8px 6px;
        font-size: 0.76rem;
        white-space: normal;
    }
    #userActivityModal .tx-grid-row {
        margin-bottom: 8px;
        padding: 13px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 13px;
        background: rgba(255, 255, 255, 0.025);
    }
    #userActivityModal .tx-col.tx-desc {
        min-width: 0;
        align-items: flex-start;
        white-space: normal;
    }
    #userActivityModal .tx-desc-text,
    #userActivityModal .tx-legacy-value { white-space: normal; overflow-wrap: anywhere; }
    #userActivityModal .tx-legacy-value { max-width: 145px; }

    #adminTxModal .table-wrapper { overflow: visible; }
    #adminTxModal .ref-table,
    #adminTxModal .ref-table tbody { display: block; width: 100%; min-width: 0; }
    #adminTxModal .ref-table thead { display: none; }
    #adminTxModal .ref-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(112px, auto);
        grid-template-areas: "description amount" "date balance";
        gap: 8px 12px;
        margin-bottom: 9px;
        padding: 13px;
        border: 1px solid rgba(255, 255, 255, 0.09);
        border-radius: 13px;
        background: rgba(255, 255, 255, 0.025);
    }
    #adminTxModal .ref-table td {
        display: block;
        width: auto;
        min-width: 0;
        padding: 0;
        border: 0;
        text-align: left !important;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    #adminTxModal .ref-table td:nth-child(1) { grid-area: date; font-size: 0.72rem; }
    #adminTxModal .ref-table td:nth-child(2) { grid-area: description; color: #fff; font-weight: 600; }
    #adminTxModal .ref-table td:nth-child(3) { grid-area: amount; align-items: flex-end; text-align: right !important; }
    #adminTxModal .ref-table td:nth-child(4) { grid-area: balance; align-items: flex-end; color: var(--text-secondary); text-align: right !important; }
    #adminTxModal .ref-table td:nth-child(4)::before { content: "Остаток: "; opacity: 0.65; }
    #adminTxModal .ref-pagination {
        position: sticky;
        bottom: -12px;
        padding: 10px 0 calc(6px + env(safe-area-inset-bottom));
        background: #0a0a0c;
    }
}

.tx-col.tx-amount,
.tx-col.tx-bal {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.tx-legacy-value {
    display: block;
    color: #a8a29e;
    font-family: inherit;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
}

.tx-col.tx-bal {
    text-align: right;
    color: var(--text-primary);
    font-family: monospace;
}

/* Цвета сумм */
.text-success { color: #4ade80 !important; }
.text-danger { color: #f87171 !important; }

/* Золотая подсветка PRO транзакций */
.tx-grid-row.is-pro {
    background: linear-gradient(to right, rgba(255, 215, 0, 0.03), transparent);
    border-left: 2px solid #FFD700;
    padding-left: 13px; /* Компенсируем border */
}

/* Микро-бейдж PRO */
.badge-pro-micro {
    background: linear-gradient(45deg, #FFD700, #FFA500);
    color: #000;
    font-size: 0.55rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 4px;
    text-transform: uppercase;
}

/* 4. Пагинация (как на скрине внизу) */
.history-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin-top: 20px;
    padding-top: 15px;
}

.history-pagination button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-pagination button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.history-pagination button.active {
    color: #ff5722; /* Оранжевый акцент */
    font-weight: 700;
}

.history-pagination button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pag-dots {
    color: var(--text-secondary);
    padding: 0 5px;
}

/* 5. Адаптивность для мобильных устройств (чтобы таблица не ломалась) */
@media (max-width: 768px) {
    .history-grid-header {
        display: none; /* Прячем заголовки колонок на мобилках */
    }
    
    .tx-grid-row {
        grid-template-columns: 1fr auto;
        grid-template-areas: 
            "desc amount"
            "date bal";
        gap: 6px;
        padding: 15px;
    }

    .tx-col.tx-desc { grid-area: desc; }
    .tx-col.tx-amount { grid-area: amount; }
    
    .tx-col.tx-date { 
        grid-area: date; 
        font-size: 0.75rem;
    }
    
    .tx-col.tx-bal { 
        grid-area: bal; 
        font-size: 0.8rem;
        color: var(--text-secondary);
    }
    
    /* Добавляем подпись к балансу на мобилках */
    .tx-col.tx-bal::before {
        content: "Остаток: ";
        opacity: 0.7;
    }
}
