/* История транзакций. Отдельный слой экрана поверх общей дизайн-системы:
   не влияет на выпуск, оплату и карточные реквизиты. */

.history-flow-root {
  --history-purple: #7338ed;
  --history-purple-dark: #5522bf;
  --history-border: #e7e2eb;
  --history-muted: #7d7583;
  --history-surface: #fff;
  color: #1d1922;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  container: history-page / inline-size;
}

.history-flow-root *,
.history-flow-root *::before,
.history-flow-root *::after { box-sizing: border-box; }

.history-page-head,
.history-summary,
.history-tools,
.history-workspace {
  /* На больших мониторах история остаётся чтением, а не широкой таблицей:
     строка операции и её сумма должны считываться одним взглядом. */
  width: min(100%, 1120px);
  margin-left: auto;
  margin-right: auto;
}

.history-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.history-head-action {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid #ddd4e5;
  border-radius: 14px;
  background: #fff;
  color: #5a2dc2;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.history-head-action:hover { border-color: #aa8ce8; background: #faf7ff; transform: translateY(-1px); }
.history-head-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.history-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.history-stat {
  display: flex;
  min-width: 0;
  min-height: 136px;
  align-items: flex-start;
  gap: 15px;
  padding: 22px;
  border: 1px solid var(--history-border);
  border-radius: 22px;
  background: var(--history-surface);
}

.history-stat--spent { background: #fbf8ff; border-color: #e5d8fb; }
.history-stat--topup { background: #f3fbf8; border-color: #d8eee5; }
.history-stat--activity { background: #f7f9fd; border-color: #e0e6f0; }

.history-stat__icon,
.history-row__icon,
.history-empty__icon,
.history-dialog__icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
}

.history-stat__icon {
  width: 42px;
  height: 42px;
  background: rgba(115,56,237,.1);
  color: var(--history-purple);
}

.history-stat--topup .history-stat__icon { background: #dff3eb; color: #238468; }
.history-stat--activity .history-stat__icon { background: #e9eef8; color: #50698b; }
.history-stat__icon svg { width: 21px; height: 21px; }
.history-stat > div { display: flex; min-width: 0; flex-direction: column; }
.history-stat small { color: var(--history-muted); font-size: 11px; font-weight: 700; line-height: 1.35; }
.history-stat strong { margin-top: 7px; color: #1d1922; font-size: clamp(20px, 1.8vw, 27px); font-weight: 800; line-height: 1.1; letter-spacing: -.035em; }
.history-stat span:not(.history-stat__icon) { margin-top: 8px; color: #8b8490; font-size: 11px; line-height: 1.35; }

.history-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1.25fr) auto auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--history-border);
  border-radius: 20px;
  background: #fff;
}

.history-product-tabs {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  padding: 5px;
  border-radius: 15px;
  background: linear-gradient(100deg, #f5efff, #faf8ff);
}

.history-product-tabs button {
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  color: #706678;
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.history-product-tabs button:hover { color: #5321b9; }
.history-product-tabs button.is-active { color: #fff; background: linear-gradient(135deg, #6827d8, #9145ef); box-shadow: 0 8px 18px rgba(92,35,190,.18); }

.history-search {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
}

.history-search > svg {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #8c8492;
  stroke-width: 1.8;
  pointer-events: none;
}

.history-search input {
  width: 100%;
  height: 46px;
  padding: 0 42px;
  border: 1px solid #e5e0e8;
  border-radius: 13px;
  outline: 0;
  background: #faf9fb;
  color: #211c27;
  font-size: 13px;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.history-search input::placeholder { color: #9a939e; }
.history-search input:focus { border-color: #9a72ec; background: #fff; box-shadow: 0 0 0 3px rgba(115,56,237,.1); }
.history-search input::-webkit-search-cancel-button { display: none; }

.history-search button {
  position: absolute;
  right: 7px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #7f7686;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.history-search button:hover { background: #f0ebf7; color: #4f288f; }

.history-type-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  background: #f4f1f7;
}

.history-type-tabs button {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #746c7b;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.history-type-tabs button:hover { color: #4f288f; }
.history-type-tabs button.is-active { background: #fff; color: #6023d4; box-shadow: 0 3px 11px rgba(58,30,96,.08); }

.history-selects { display: flex; gap: 8px; }
.history-filter { position: relative; display: block; min-width: 0; }
.history-filter > span { position: absolute; left: 12px; top: 7px; z-index: 1; color: #9a929f; font-size: 8px; font-weight: 800; line-height: 1; text-transform: uppercase; letter-spacing: .06em; pointer-events: none; }

.history-filter__trigger {
  width: 126px;
  height: 46px;
  padding: 17px 30px 4px 12px;
  border: 1px solid #e5e0e8;
  border-radius: 13px;
  outline: 0;
  background: #fff;
  color: #39313f;
  font-size: 11px;
  font-weight: 750;
  text-align: left;
  cursor: pointer;
}

.history-filter__trigger strong { display: block; overflow: hidden; font: inherit; text-overflow: ellipsis; white-space: nowrap; }
.history-filter__trigger svg { position: absolute; right: 9px; top: 17px; width: 13px; height: 13px; fill: none; stroke: #776e7e; stroke-width: 2; transform: rotate(90deg); transition: transform .16s ease; pointer-events: none; }
.history-filter--card .history-filter__trigger { width: 132px; }
.history-filter__trigger:focus-visible,
.history-filter.is-open .history-filter__trigger { border-color: #9a72ec; box-shadow: 0 0 0 3px rgba(115,56,237,.1); }
.history-filter.is-open .history-filter__trigger svg { transform: rotate(-90deg); }

.history-filter__menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 7px);
  left: 0;
  width: max(100%, 150px);
  padding: 6px;
  border: 1px solid #e4ddea;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(42,24,63,.18);
}

.history-filter__menu[hidden] { display: none; }
.history-filter__option {
  width: 100%;
  min-height: 38px;
  padding: 0 10px 0 7px;
  border: 0;
  border-radius: 9px;
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  background: transparent;
  color: #4e4654;
  font-size: 11px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.history-filter__option > span { color: #6630d5; font-size: 12px; font-weight: 900; }
.history-filter__option:hover,
.history-filter__option:focus-visible { outline: 0; background: #f5f0fc; color: #5424bd; }
.history-filter__option[aria-selected="true"] { background: #f1eaff; color: #5424bd; }

.history-ledger {
  overflow: hidden;
  border: 1px solid var(--history-border);
  border-radius: 24px;
  background: #fff;
}

.history-workspace { min-width: 0; }
.history-insights { display: none; }

.history-insight-card,
.history-insight-action {
  width: 100%;
  border: 1px solid var(--history-border);
  border-radius: 22px;
  background: #fff;
}

.history-insight-card { padding: 22px; }
.history-insight-card .section-kicker { color: #8b55e9; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.history-insight-card h2,
.history-insight-card h3 { margin: 7px 0 0; color: #211c27; font-size: 20px; font-weight: 800; line-height: 1.2; letter-spacing: -.025em; }
.history-insight-card--selection { border-color: #dfd1f8; background: linear-gradient(145deg, #faf7ff 0%, #fff 76%); }

.history-selection-summary { margin-top: 18px; }
.history-selection-summary__row {
  display: flex;
  min-height: 43px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid #eee9f2;
}
.history-selection-summary__row > span { color: #746c7a; font-size: 13px; font-weight: 700; }
.history-selection-summary__row > strong { font-size: 15px; font-weight: 800; white-space: nowrap; }
.history-selection-summary__row--total { margin-top: 3px; border-bottom: 0; }
.history-selection-summary__row--total > strong { color: #5f2bc9; font-size: 22px; }
.history-selection-summary p { margin: 8px 0 0; color: #847b8a; font-size: 12px; line-height: 1.5; }

.history-insight-action {
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 18px;
  color: #4f288f;
  text-align: left;
  cursor: pointer;
}
.history-insight-action > span { display: flex; min-width: 0; flex-direction: column; }
.history-insight-action strong { color: #2b2430; font-size: 14px; font-weight: 800; }
.history-insight-action small { margin-top: 3px; color: #8a818f; font-size: 12px; }
.history-insight-action svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; }
.history-insight-action:hover { border-color: #bda4ec; background: #faf7ff; }

@container history-page (min-width: 1080px) {
  .history-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 264px;
    align-items: start;
    gap: 16px;
  }
  .history-insights {
    position: sticky;
    top: 22px;
    display: grid;
    gap: 14px;
  }
}

.history-ledger__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 23px 24px 17px;
  border-bottom: 1px solid #eeeaf0;
}

.history-ledger__head .section-kicker { color: #8b55e9; font-size: 9px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.history-ledger__head h2 { margin: 5px 0 0; color: #211c27; font-size: 21px; font-weight: 800; line-height: 1.15; letter-spacing: -.03em; }
.history-result-count { color: #89808e; font-size: 12px; font-weight: 700; }

.history-group { padding: 0 24px; }
.history-group + .history-group { border-top: 8px solid #f7f5f8; }
.history-group__date { padding: 17px 0 8px; color: #837a89; font-size: 11px; font-weight: 800; letter-spacing: .02em; }
.history-group__rows { width: 100%; }

.history-row {
  display: grid;
  width: 100%;
  grid-template-columns: 45px minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 12px 0;
  border: 0;
  border-top: 1px solid #f0edf2;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.history-row:first-child { border-top: 0; }
.history-row:hover .history-row__title { color: #6228cf; }
.history-row:focus-visible { border-radius: 12px; box-shadow: 0 0 0 3px rgba(115,56,237,.14); }

.history-row__icon {
  width: 45px;
  height: 45px;
  background: #f1ebff;
  color: #6930d9;
}

.history-row__icon--in { background: #e6f6f0; color: #21866a; }
.history-row__icon--neutral { background: #eef1f7; color: #536780; }
.history-row__icon svg,
.history-dialog__icon svg { width: 21px; height: 21px; }
.history-row__main { display: flex; min-width: 0; flex-direction: column; }
.history-row__title { overflow: hidden; color: #25202a; font-size: 14px; font-weight: 800; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; transition: color .18s ease; }
.history-row__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; color: #8c8492; font-size: 10px; font-style: normal; line-height: 1.35; }
.history-row__meta > i { width: 3px; height: 3px; border-radius: 50%; background: #c0b9c5; }
.history-row__message { display: block; overflow: hidden; margin-top: 5px; color: #a14550; font-size: 10px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }

.history-status { display: inline-flex; align-items: center; color: #397a66; font-size: inherit; font-style: normal; font-weight: 800; }
.history-status--pending { color: #9b6b16; }
.history-status--failed { color: #a14550; }
.history-status::before { width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: currentColor; content: ""; }

.history-row__side { display: flex; min-width: 118px; align-items: flex-end; flex-direction: column; }
.history-row__side strong { font-size: 14px; font-weight: 800; line-height: 1.35; }
.history-row__side small { margin-top: 3px; color: #9b949f; font-size: 9px; line-height: 1.25; }
.history-row__chevron { display: inline-flex; color: #a59eaa; }
.history-row__chevron svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }

.history-empty { display: flex; min-height: 310px; align-items: center; justify-content: center; padding: 48px 20px; flex-direction: column; text-align: center; }
.history-empty__icon { width: 54px; height: 54px; background: #f0e9ff; color: #6b32db; }
.history-empty__icon--search { background: #f1f3f7; color: #68758a; }
.history-empty__icon svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.history-empty h3 { margin: 17px 0 0; color: #27212c; font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.history-empty p { max-width: 410px; margin: 8px 0 0; color: #827986; font-size: 12px; line-height: 1.55; }
.history-empty button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; margin-top: 18px; padding: 0 17px; border: 0; border-radius: 12px; background: #7035e8; color: #fff; font-size: 11px; font-weight: 800; cursor: pointer; }
.history-empty button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.history-modal-backdrop {
  position: fixed;
  z-index: 1500;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(24,18,31,.48);
  backdrop-filter: blur(6px);
}

.history-modal-backdrop[hidden] { display: none !important; }
body.history-dialog-open { overflow: hidden; }

.history-dialog {
  position: relative;
  width: min(100%, 470px);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  padding: 28px;
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 25px;
  outline: 0;
  background: #fff;
  box-shadow: 0 30px 90px rgba(30,18,45,.28);
}

.history-dialog__close { position: absolute; z-index: 1; top: 15px; right: 15px; width: 36px; height: 36px; border: 0; border-radius: 11px; background: #f4f1f6; color: #6f6675; font-size: 24px; line-height: 1; cursor: pointer; }
.history-dialog__close:hover { background: #ebe4f4; color: #4e278c; }
.history-dialog__close:focus-visible { box-shadow: 0 0 0 3px rgba(115,56,237,.18); }
.history-dialog__hero { display: flex; align-items: center; padding: 8px 24px 20px; flex-direction: column; text-align: center; }
.history-dialog__icon { width: 54px; height: 54px; margin-bottom: 14px; background: #f0e9ff; color: #6930d9; }
.history-dialog__icon.history-row__icon--in { background: #e6f6f0; color: #21866a; }
.history-dialog__icon.history-row__icon--neutral { background: #eef1f7; color: #536780; }
.history-dialog__hero > .history-status { padding: 5px 10px; border-radius: 999px; background: #ecf8f3; font-size: 9px; letter-spacing: .02em; }
.history-dialog__hero > .history-status--pending { background: #fff5dc; }
.history-dialog__hero > .history-status--failed { background: #fff0f2; }
.history-dialog__hero h2 { margin: 13px 0 0; color: #221d27; font-size: 23px; font-weight: 800; line-height: 1.2; letter-spacing: -.035em; }
.history-dialog__amount { margin-top: 9px; font-size: 20px; font-weight: 800; }
.history-dialog__notice { width: 100%; margin: 15px 0 0; padding: 11px 13px; border-radius: 12px; background: #fff3f4; color: #994650; font-size: 11px; line-height: 1.45; }

.history-dialog__details { margin: 0; padding: 0; border-top: 1px solid #eeeaf0; }
.history-dialog__details > div { display: grid; grid-template-columns: minmax(110px, .8fr) minmax(0, 1.2fr); gap: 15px; padding: 13px 0; border-bottom: 1px solid #eeeaf0; }
.history-dialog__details dt { color: #8b828f; font-size: 10px; line-height: 1.45; }
.history-dialog__details dd { margin: 0; color: #312a36; font-size: 11px; font-weight: 750; line-height: 1.45; text-align: right; word-break: break-word; }
.history-dialog__actions { display: grid; grid-template-columns: 1.3fr 1fr; gap: 9px; margin-top: 19px; }
.history-dialog__actions button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 7px; border-radius: 12px; font-size: 10px; font-weight: 800; cursor: pointer; }
.history-dialog__primary { border: 0; background: #7137e9; color: #fff; }
.history-dialog__primary svg { width: 15px; height: 15px; }
.history-dialog__secondary { border: 1px solid #ddd5e3; background: #fff; color: #5c2dbd; }
.history-dialog__support { width: 100%; margin-top: 14px; padding: 0; border: 0; background: transparent; color: #756c7c; font-size: 10px; font-weight: 700; line-height: 1.45; cursor: pointer; }
.history-dialog__support:hover { color: #5e29c7; }

@media (max-width: 1180px) {
  .history-tools { grid-template-columns: minmax(260px, 1fr) auto; }
  .history-selects { grid-column: 1 / -1; }
  .history-filter select { width: 150px; }
}

@media (max-width: 767px) {
  .history-page-head { align-items: flex-start; flex-direction: column; gap: 14px; }
  .history-head-action { width: 100%; min-height: 42px; font-size: 11px; }
  .history-summary { grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
  .history-stat { min-height: 102px; padding: 17px; border-radius: 19px; }
  .history-stat strong { font-size: 22px; }
  .history-tools { display: block; margin-bottom: 14px; padding: 11px; border-radius: 18px; }
  .history-product-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 10px; }
  .history-product-tabs button { min-height: 38px; padding: 0 6px; font-size: 9px; }
  .history-search input { height: 44px; font-size: 12px; }
  .history-type-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 10px; }
  .history-type-tabs button { min-height: 36px; padding: 0 4px; font-size: 9px; }
  .history-selects { display: grid; grid-template-columns: minmax(0, .82fr) minmax(0, 1.18fr); gap: 8px; margin-top: 10px; }
  .history-filter__trigger,
  .history-filter--card .history-filter__trigger { width: 100%; height: 44px; font-size: 10px; }
  .history-filter:nth-child(2) .history-filter__menu { right: 0; left: auto; }
  .history-filter__menu { width: max(100%, 158px); }
  .history-filter__option { min-height: 40px; font-size: 10px; }
  .history-filter--card { grid-column: 1 / -1; }
  .history-ledger { border-radius: 20px; }
  .history-ledger__head { padding: 19px 16px 14px; }
  .history-ledger__head h2 { font-size: 19px; }
  .history-result-count { font-size: 10px; }
  .history-group { padding: 0 14px; }
  .history-group__date { padding-top: 14px; }
  .history-row { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; min-height: 72px; }
  .history-row__icon { width: 40px; height: 40px; border-radius: 12px; }
  .history-row__icon svg { width: 19px; height: 19px; }
  .history-row__title { font-size: 12px; }
  .history-row__meta { gap: 4px; font-size: 9px; }
  .history-row__message { max-width: 48vw; font-size: 9px; }
  .history-row__side { min-width: 82px; }
  .history-row__side strong { font-size: 11px; }
  .history-row__side small { font-size: 8px; }
  .history-row__chevron { display: none; }
  .history-empty { min-height: 270px; padding: 36px 16px; }
  .history-modal-backdrop { align-items: flex-end; padding: 0; }
  .history-dialog { width: 100%; max-height: calc(92vh - env(safe-area-inset-bottom, 0px)); padding: 24px 18px calc(20px + env(safe-area-inset-bottom, 0px)); border-radius: 24px 24px 0 0; }
  .history-dialog__hero { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 369px) {
  .history-stat { padding: 15px; }
  .history-stat__icon { width: 38px; height: 38px; }
  .history-row { grid-template-columns: 37px minmax(0, 1fr) auto; gap: 8px; }
  .history-row__icon { width: 37px; height: 37px; }
  .history-row__side { min-width: 70px; }
  .history-dialog__actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .history-flow-root *,
  .history-flow-root *::before,
  .history-flow-root *::after { scroll-behavior: auto !important; transition: none !important; }
}
