/* Full-width dashboard layout, keeping every data block inside the viewport. */
.operations-panel {
  --ops-muted: #a5b6c9;
  --ops-border: #ffffff16;
  --ops-space: 1rem;
  --ops-surface: #ffffff05;
}
.operations-panel > .section-heading { flex-wrap: wrap; }
.operations-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; }
.webhook-ping-result { color: var(--ops-muted); font-size: .8rem; }
.nile-reset-button {
  padding: .52rem .75rem; border: 1px solid #ff657488; border-radius: 7px;
  background: #ff536314; color: #ff9aa3; font: inherit; font-size: .72rem; font-weight: 700;
  letter-spacing: .03em; cursor: pointer;
}
.nile-reset-button:hover:not(:disabled), .nile-reset-button:focus-visible:not(:disabled) { border-color: #ff7e88; background: #ff536326; color: #ffd7da; }
.nile-reset-button:focus-visible { outline: 2px solid #ff9aa3; outline-offset: 3px; }
.nile-reset-button:disabled { opacity: .55; cursor: wait; }
.nile-reset-button[hidden], .nile-reset-result[hidden] { display: none; }
.nile-reset-result { color: var(--ops-muted); font-size: .8rem; }
.nile-reset-result.ok { color: #70e0bf; }
.nile-reset-result.error { color: #ff9ba2; }
.status-help { display: inline-grid; place-items: center; width: 1.35rem; height: 1.35rem; padding: 0; border: 1px solid #f2c86b88; border-radius: 50%; background: #f2c86b0d; color: #f2c86b; font: inherit; font-size: .72rem; font-weight: 700; line-height: 1; }
.status-help:hover, .status-help:focus-visible { border-color: #f2c86b; background: #f2c86b1a; color: #ffe19a; }
.status-help:focus-visible { outline: 2px solid #a7c7f5; outline-offset: 3px; }
.status-help[hidden] { display: none; }
.monitoring-status-modal { width: min(42rem, 100%); max-height: min(80vh, 42rem); overflow: auto; }
#monitoring-status-modal { z-index: 30; }
#api-auth-modal { z-index: 40; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.modal-heading h2 { margin-bottom: .25rem; }
.modal-close { padding: .15rem .5rem; background: transparent; color: #a5b6c9; font-size: 1.5rem; line-height: 1; }
.modal-close:hover, .modal-close:focus-visible { color: #fff; background: #ffffff10; }
.status-reasons { display: grid; gap: .7rem; margin: 1rem 0 0; padding-left: 1.4rem; }
.status-reasons li { padding: .85rem 1rem .85rem .35rem; border: 1px solid var(--ops-border); border-radius: 10px; background: #ffffff05; }
.status-reason-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.status-reason-heading strong { color: #e7edf5; }
.status-reason-state { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.status-reasons p { margin: .35rem 0 0; color: #b9cce0; font-size: .82rem; line-height: 1.5; overflow-wrap: anywhere; }
.status-reasons code { display: inline-block; margin-top: .45rem; color: #f2c86b; font-size: .7rem; overflow-wrap: anywhere; }
.monitoring-reset-result { min-height: 1.3em; margin: .9rem 0 0; color: #70e0bf; font-size: .8rem; }
.monitoring-reset-result.warning { color: #f2c86b; }
.monitoring-reset-result.error { color: #ff9ba2; }
.monitoring-reset-progress { height: .22rem; margin: .65rem 0 1rem; overflow: hidden; border-radius: 999px; background: #ffffff10; }
.monitoring-reset-progress[hidden] { display: none; }
.monitoring-reset-progress i { display: block; width: 38%; height: 100%; border-radius: inherit; background: #58d5b5; animation: monitoring-reset-progress 1.15s ease-in-out infinite; }
#monitoring-status-reset.is-loading { display: inline-flex; align-items: center; gap: .55rem; cursor: wait; }
#monitoring-status-reset.is-loading::before { content: ''; width: .85rem; height: .85rem; border: 2px solid #a7c7f555; border-top-color: #a7c7f5; border-radius: 50%; animation: monitoring-reset-spin .75s linear infinite; }
@keyframes monitoring-reset-progress { from { transform: translateX(-105%); } to { transform: translateX(275%); } }
@keyframes monitoring-reset-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .monitoring-reset-progress i, #monitoring-status-reset.is-loading::before { animation-duration: 2.5s; } }
.monitoring-api-key-row { display: block; }
.monitoring-api-key-row > .monitoring-api-summary {
  display: flex; align-items: center; flex-wrap: wrap; gap: .6rem 1.5rem;
  padding: var(--ops-space) 0; margin-bottom: var(--ops-space);
  background: transparent; border-block: 1px solid var(--ops-border); border-radius: 0; cursor: default;
}
.monitoring-api-summary > span { margin: 0; }
.monitoring-api-summary .api-guide { margin-left: auto; color: var(--ops-muted); font-size: .75rem; }
.monitoring-api-key-row > .api-key-cards {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--ops-space);
  padding: 0; background: transparent;
}
.api-key-card {
  grid-template-columns: minmax(0, 1fr) auto; gap: .85rem .5rem;
  border: 1px solid var(--ops-border); background: var(--ops-surface); line-height: 1.5;
}
.api-key-card .api-key-state { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.api-key-card .api-key-count { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; font-size: 1.2rem; font-weight: 600; color: #e7edf5; white-space: normal; }
.api-key-card .api-key-details { display: grid; gap: .65rem; margin: .2rem 0 0; white-space: normal; min-width: 0; }
.api-key-details > div { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: .55rem; align-items: baseline; }
.api-key-details dt { color: var(--ops-muted); font-size: .72rem; }
.api-key-details dd { display: flex; justify-content: flex-end; align-items: baseline; gap: .35rem; margin: 0; min-width: 0; text-align: right; font-size: .74rem; overflow-wrap: anywhere; }
.api-key-details dd > span { min-width: 0; }
.api-key-empty { color: var(--ops-muted); font-size: .8rem; margin: 0; max-width: 28ch; }
.api-key-card.not-configured { opacity: 1; border-style: dashed; background: transparent; }
.api-key-card.not-configured > strong { color: var(--ops-muted); }
.api-key-card.cooldown .api-key-state { color: #f2c86b; }
.operations-panel .metric-with-help { display: inline-flex; align-items: baseline; gap: .45rem; margin: 0; min-width: 0; color: inherit; font-size: inherit; }
.metric-with-help > b { min-width: 0; overflow-wrap: anywhere; }
.operations-panel .monitoring-time-values { padding: 0; background: transparent; }
.monitoring-time-values > span { flex-wrap: wrap; }
.operations-panel .reconciliation-summary-card { display: grid; grid-template-columns: 1fr; gap: 1rem; align-content: start; }
.operations-panel .reconciliation-summary-section { min-width: 0; padding: 0; background: transparent; border-radius: 0; }
.operations-panel .reconciliation-summary-divider { width: 100%; height: 1px; min-height: 1px; padding: 0; background: var(--ops-border); border-radius: 0; }
.operations-panel .monitoring-cursor-values { display: grid; gap: .18rem; padding: 0; background: transparent; }
.monitoring-cursor-values > b { display: block; margin-bottom: .2rem; font-variant-numeric: tabular-nums; }
.monitoring-cursor-values > span {
  display: flex; justify-content: space-between; gap: .5rem; margin: 0;
  color: var(--ops-muted); font-size: .72rem;
}
.monitoring-cursor-values > span .metric-with-help { color: #e7edf5; font-size: .78rem; text-align: right; font-variant-numeric: tabular-nums; }
.operations-panel .monitoring-lag-values { display: grid; gap: .18rem; padding: 0; background: transparent; }
.monitoring-lag-values > b { display: block; margin-bottom: .2rem; font-variant-numeric: tabular-nums; }
.monitoring-lag-values > span {
  display: flex; justify-content: space-between; gap: .5rem; margin: 0;
  color: var(--ops-muted); font-size: .72rem;
}
.monitoring-lag-values > span > b { color: #e7edf5; font-size: .78rem; text-align: right; font-variant-numeric: tabular-nums; }
.monitoring-lag-values.is-converging > span > b { color: #70e0bf; }
.monitoring-lag-values.is-diverging > span > b { color: #ff7e88; }
.monitoring-lag-values.is-steady > span > b { color: #f2c86b; }
.reconciliation-lag-values.status-healthy > b { color: #70e0bf; }
.reconciliation-lag-values.status-degraded > b, .reconciliation-lag-values.status-stale > b { color: #f2c86b; }
.reconciliation-lag-values.status-error > b, .reconciliation-lag-values.status-version_mismatch > b { color: #ff7e88; }
.monitoring-lag-values.is-converging .metric-with-help { color: #70e0bf; }
.monitoring-lag-values.is-diverging .metric-with-help { color: #ff7e88; }
.monitoring-lag-values.is-steady .metric-with-help { color: #f2c86b; }
.monitoring-lag-values > span .metric-with-help b { color: inherit; font-size: .78rem; }
.lag-reset-row { display: grid; gap: .35rem; margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--ops-border); }
.operations-panel .lag-reset-button {
  width: 100%; padding: .52rem .65rem; border: 1px solid #ff657488; border-radius: 7px;
  background: #ff536314; color: #ff9aa3; font: inherit; font-size: .72rem; font-weight: 700;
  letter-spacing: .02em; cursor: pointer;
}
.operations-panel .lag-reset-button:hover:not(:disabled), .operations-panel .lag-reset-button:focus-visible:not(:disabled) {
  border-color: #ff7e88; background: #ff536326; color: #ffd7da;
}
.operations-panel .lag-reset-button:focus-visible { outline: 2px solid #ff9aa3; outline-offset: 3px; }
.operations-panel .lag-reset-button:disabled { border-color: #8fa0b42b; background: transparent; color: #8fa0b477; cursor: not-allowed; }
.lag-reset-row small { color: var(--ops-muted); font-size: .66rem; line-height: 1.35; }
.operations-panel .metric-help {
  display: inline-grid; place-items: center; flex: 0 0 1.15rem;
  width: 1.15rem; height: 1.15rem; padding: 0; margin: 0; border: 1px solid #8fa0b455;
  border-radius: 50%; background: transparent; color: #a5b6c9;
  font-family: inherit; font-weight: 600; font-size: .7rem; line-height: 1; cursor: help; vertical-align: middle;
}
.operations-panel .metric-help:hover, .operations-panel .metric-help:focus-visible { color: #70e0bf; border-color: #70e0bf; background: #58d5b510; }
.operations-panel .metric-help:focus-visible { outline: 2px solid #a7c7f5; outline-offset: 3px; }
.metric-tooltip { position: fixed; z-index: 1000; width: min(21rem, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; padding: .85rem 1rem; border: 1px solid #58d5b555; border-radius: 10px; background: #17283a; color: #e7edf5; box-shadow: 0 12px 36px #0008; font-size: .8rem; line-height: 1.55; overflow-wrap: anywhere; }
.metric-tooltip[hidden] { display: none; }
@media (max-width: 1250px) {
  .monitoring-api-key-row > .api-key-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .operations-panel .monitoring-grid { grid-template-columns: 1fr; }
  .monitoring-api-key-row > .api-key-cards { grid-template-columns: 1fr; }
  .monitoring-api-summary .api-guide { width: 100%; margin-left: 0; }
  .operations-actions { width: 100%; }
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 760px) {
  .monitoring-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .batch-table, .batch-table tbody, .batch-table tr { display: block; }
  .batch-table thead { display: none; }
  .batch-table tr { padding: .65rem 0; border-bottom: 1px solid #ffffff12; }
  .batch-table td { display: grid; grid-template-columns: minmax(7rem,34%) minmax(0,1fr); gap: .75rem; padding: .42rem 0; border: 0; }
  .batch-table td::before { color: #8fa0b4; font-size: .72rem; }
  .batch-table td:nth-child(1)::before { content: 'Batch / sequence'; }
  .batch-table td:nth-child(2)::before { content: 'Status'; }
  .batch-table td:nth-child(3)::before { content: 'Attempts'; }
  .batch-table td:nth-child(4)::before { content: 'Events'; }
  .batch-table td:nth-child(5)::before { content: 'Создан'; }
  .batch-table td:nth-child(6)::before { content: 'Следующая попытка'; }
  .batch-table td:nth-child(7)::before { content: 'HTTP / error'; }
  .batch-table td:nth-child(8)::before { content: 'Действие'; }
}

@media (max-width: 480px) {
  .monitoring-grid { grid-template-columns: 1fr; }
}

header {
  min-width: 0;
  padding-inline: clamp(1rem, 3vw, 3rem);
  flex-wrap: wrap;
  gap: .75rem;
}

/* Keep the wallet list bounded so the rest of the dashboard remains reachable. */
.table-wrap.tron-wallets-scroll {
  max-height: 34rem;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #58d5b566 #ffffff08;
  scrollbar-width: thin;
}

.table-wrap.api-users-scroll {
  max-height: 25rem;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #58d5b566 #ffffff08;
  scrollbar-width: thin;
}

.api-users-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #111a26;
}

.tron-wallets-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.15rem;
}

.tron-wallets-search {
  display: grid;
  gap: .35rem;
  width: min(100%, 28rem);
  color: #8fa0b4;
  font-size: .72rem;
  letter-spacing: .03em;
}

.tron-wallets-search input {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: .65rem .8rem;
  border-radius: 8px;
  font-size: .82rem;
}

#tron-filter-count {
  padding-bottom: .65rem;
  font-size: .72rem;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .tron-wallets-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: .55rem;
  }

  .tron-wallets-search {
    width: 100%;
  }

  #tron-filter-count {
    padding-bottom: 0;
  }
}

nav {
  min-width: 0;
  flex-wrap: wrap;
}

main {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: clamp(2.5rem, 5vw, 5rem) clamp(1rem, 3vw, 3rem) 4rem;
}

.panel,
.table-wrap {
  min-width: 0;
}

.table-wrap {
  width: 100%;
  overflow: visible;
}

.api-users-panel table,
.tron-panel table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.api-users-panel th,
.api-users-panel td,
.tron-panel th,
.tron-panel td {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tron-panel th {
  white-space: normal;
}

.address-cell {
  white-space: normal;
}

.address-cell code {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: normal;
}

.tron-panel th:nth-child(3),
.tron-panel td:nth-child(3),
.tron-panel th:nth-child(4),
.tron-panel td:nth-child(4) {
  display: none !important;
}

.tron-panel th:first-child,
.tron-panel td:first-child {
  width: 2rem;
}

.tron-panel th:first-child {
  font-size: 0;
}

.tron-panel td.address-cell {
  display: flex !important;
  align-items: center;
  gap: .55rem;
  min-width: 0;
}

.tron-panel td.address-cell::before {
  display: none;
}

.tron-panel td.address-cell code {
  flex: 1;
  min-width: 0;
  margin-right: 0;
}

.tron-wallets-scroll {
  max-height: 34rem;
}

.copy-address {
  white-space: nowrap;
}

@media (max-width: 760px) {
  .section-heading {
    align-items: flex-start;
  }

  .health-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .api-users-panel table,
  .tron-panel table {
    display: block;
  }

  .api-users-panel thead,
  .tron-panel thead {
    display: none;
  }

  .api-users-panel tbody,
  .tron-panel tbody {
    display: block;
  }

  .api-users-panel tr,
  .tron-panel tr {
    display: block;
    padding: .65rem 0;
    border-bottom: 1px solid #ffffff12;
  }

  .api-users-panel td,
  .tron-panel td {
    display: grid;
    grid-template-columns: minmax(7rem, 34%) minmax(0, 1fr);
    gap: .75rem;
    width: 100% !important;
    padding: .42rem 0;
    border: 0;
  }

  .api-users-panel td::before,
  .tron-panel td::before {
    color: #8fa0b4;
    font-size: .72rem;
    line-height: 1.35;
  }

  .api-users-panel td:nth-child(1)::before { content: 'Пользователь'; }
  .api-users-panel td:nth-child(2)::before { content: 'JWT'; }
  .api-users-panel td:nth-child(3)::before { content: 'Активность'; }
  .tron-panel td:nth-child(1)::before { content: 'Состояние'; }
  .tron-panel td:nth-child(2)::before { content: 'Address'; }
  .tron-panel td:nth-child(3)::before { content: 'TRX'; }
  .tron-panel td:nth-child(4)::before { content: 'USDT'; }
  .tron-panel td:nth-child(5)::before { content: 'Cursor block'; }
  .tron-panel td:nth-child(6)::before { content: 'Успешный scan'; }
  .tron-panel td:nth-child(7)::before { content: 'Scan error'; }
  .tron-panel td:nth-child(8)::before { content: 'Pending'; }
  .tron-panel td:nth-child(9)::before { content: 'Webhook доставлен'; }
  .tron-panel td:nth-child(10)::before { content: 'Последняя транзакция'; }
  .tron-panel td:nth-child(11)::before { content: 'Постановка'; }
  .tron-panel td:nth-child(12)::before { content: 'API user'; }
}

@media (max-width: 480px) {
  header {
    height: auto;
    padding-block: 1rem;
  }

  nav {
    width: 100%;
    justify-content: space-between;
    gap: .5rem;
    font-size: .8rem;
  }

  main {
    padding-inline: .75rem;
  }

  .panel {
    padding: 1rem;
    border-radius: 14px;
  }

  .dashboard-controls,
  .dashboard-controls button {
    width: 100%;
  }

  .api-users-panel td,
  .tron-panel td {
    grid-template-columns: minmax(6rem, 38%) minmax(0, 1fr);
    gap: .5rem;
  }

  form input {
    min-width: 0;
    width: 100%;
  }

}
@media(max-width:850px){.api-logs-filters{grid-template-columns:repeat(2,minmax(0,1fr))}.api-logs-submit{grid-column:span 2}.api-logs-actions{align-items:flex-end;flex-direction:column}.api-logs-table-wrap{margin-left:-1rem;margin-right:-1rem}}
@media(max-width:650px){.api-logs-filters{grid-template-columns:1fr}.api-logs-submit{grid-column:auto;align-items:flex-start;flex-direction:column}.api-logs-footer{align-items:flex-start;flex-direction:column}.api-logs-actions{align-items:flex-start;width:100%}.api-logs-actions .muted{order:3}}
