/* =========================================================
   DeltaUpd — Панель управления (админка)
   Дизайн в стиле основного сайта (тёмная тема, indigo-акцент)
   ========================================================= */

.admin-page {
  position: relative;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.admin-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  z-index: 0;
  pointer-events: none;
}

.admin-glow--one {
  width: 520px;
  height: 520px;
  top: -180px;
  left: -140px;
  background: rgba(255, 59, 92, 0.22);
}

.admin-glow--two {
  width: 460px;
  height: 460px;
  bottom: -180px;
  right: -140px;
  background: rgba(190, 18, 60, 0.18);
}

.admin-wrap {
  position: relative;
  z-index: 1;
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 130px 24px 72px;
}

/* ---------- Forbidden ---------- */
.admin-forbidden {
  display: flex;
  justify-content: center;
}

.admin-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  width: min(460px, 100%);
  padding: 48px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
}

.admin-placeholder__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.admin-placeholder .btn {
  width: auto;
  margin-top: 8px;
  padding: 11px 24px;
}

/* ---------- Head ---------- */
.admin-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.admin-head__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s ease;
}

.admin-head__back:hover {
  color: var(--text);
}

.admin-head__title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

/* ---------- Stats ---------- */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.admin-stat {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-stat--accent {
  border-color: rgba(255, 59, 92, 0.3);
  background: linear-gradient(to bottom, rgba(255, 59, 92, 0.1), rgba(255, 59, 92, 0.03));
}

.admin-stat__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.admin-stat__value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.admin-stat--accent .admin-stat__value {
  color: var(--accent);
}

/* ---------- Layout ---------- */
.admin-layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 20px;
  align-items: start;
}

.admin-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 130px;
}

.admin__tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.admin__tab svg {
  flex-shrink: 0;
  opacity: 0.9;
}

.admin__tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.admin__tab.is-active {
  background: var(--accent-soft);
  border-color: rgba(255, 59, 92, 0.25);
  color: var(--accent);
}

/* ---------- View / Toolbar ---------- */
.admin-view {
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  padding: 20px;
}

.admin__toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.admin__search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 200px;
}

.admin__search svg {
  position: absolute;
  left: 12px;
  color: var(--text-faint);
  pointer-events: none;
}

.admin__search input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.admin__search input:focus {
  border-color: var(--accent);
}

.admin__filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin__filter {
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.admin__filter:hover {
  color: var(--text);
}

.admin__filter.is-active {
  background: var(--accent-soft);
  border-color: rgba(255, 59, 92, 0.3);
  color: var(--accent);
}

/* ---------- Buttons ---------- */
.admin__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.admin__btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.admin__btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #0a0a12;
}

.admin__btn--primary:hover {
  filter: brightness(1.1);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.admin__btn--danger {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(248, 113, 113, 0.08);
}

.admin__btn--danger:hover {
  background: rgba(248, 113, 113, 0.16);
}

.admin__btn--ghost {
  background: transparent;
}

.admin__btn--sm {
  padding: 6px 10px;
  font-size: 12px;
}

/* ---------- Table ---------- */
.admin__table {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.admin__row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}

/* Настройка колонок по разделам */
.admin__table--users .admin__row {
  grid-template-columns: 64px 1.4fr 1.2fr 1fr minmax(max-content, 0.9fr) minmax(max-content, 0.9fr) auto;
}
.admin__table--roles .admin__row {
  grid-template-columns: 1.6fr minmax(max-content, 1fr) auto;
}
.admin__table--subs .admin__row {
  grid-template-columns: 1.2fr 0.9fr 0.8fr 0.9fr 0.7fr auto;
}
.admin__table--keys .admin__row {
  grid-template-columns: 1.5fr 0.7fr 0.6fr 0.8fr 1fr auto;
}
.admin__table--promo .admin__row {
  grid-template-columns: 1.2fr 0.5fr 0.7fr 0.8fr auto;
}
.admin__table--products .admin__row {
  grid-template-columns: 1.2fr 0.8fr 0.7fr auto;
}
.admin__table--audit .admin__row {
  grid-template-columns: 130px 0.8fr 0.9fr 0.9fr 1.6fr;
}
.admin__table--attempts .admin__row {
  grid-template-columns: 130px 1.1fr 0.9fr 0.7fr auto;
}
.admin__table--ip .admin__row {
  grid-template-columns: 1.2fr 1fr auto;
}
.admin__table--hwid .admin__row {
  grid-template-columns: 1.2fr 1.2fr 0.9fr auto;
}

.admin__row > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.admin__table--users .admin__row > div:nth-child(5),
.admin__table--users .admin__row > div:nth-child(6) {
  white-space: nowrap;
  overflow-wrap: normal;
}

.admin__table:not(.admin__table--audit):not(.admin__table--attempts):not(.admin__table--finance) .admin__row--head ~ .admin__row:last-child {
  border-bottom: none;
}

.admin__row:last-child {
  border-bottom: none;
}

.admin__row--head {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.03);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin__row--head div {
  padding: 2px 0;
}

.admin__row--head.admin__row--head-only {
  border-bottom: 1px solid var(--border);
}

.admin__user-name {
  font-weight: 600;
  color: var(--text);
}

.admin__user-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.admin__uid {
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 12.5px;
}

.admin__dim {
  color: var(--text-dim);
}

.admin__mono {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', monospace;
  font-size: 12.5px;
  color: var(--text-dim);
}

.admin__key-code {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', monospace;
  font-size: 13px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-user-select: text !important;
  user-select: text !important;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.admin__key-code:hover {
  opacity: 0.85;
  text-decoration: underline;
}

.admin__email {
  color: var(--text-dim);
  font-size: 13px;
  word-break: break-all;
}

.admin__cell-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.admin__tg-link {
  color: #2aabee;
  text-decoration: none;
}

.admin__tg-link:hover {
  text-decoration: underline;
}

/* ---------- Badges ---------- */
.admin__status,
.admin__role,
.admin__tone {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.admin__status--active,
.admin__tone--ok {
  background: rgba(107, 216, 150, 0.16);
  color: #6bd896;
}

.admin__status--muted,
.admin__admin__status--banned,
.admin__tone--warn {
  background: rgba(251, 191, 36, 0.16);
  color: #fbbf24;
}

.admin__status--banned,
.admin__tone--danger {
  background: rgba(248, 113, 113, 0.16);
  color: #f87171;
}

.admin__tone--neutral {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
}

.admin__role--admin {
  background: rgba(255, 59, 92, 0.18);
  color: #ff3b5c;
}

.admin__role--moderator {
  background: rgba(190, 18, 60, 0.16);
  color: #be123c;
}

.admin__role--user {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-dim);
}

.admin__subbadge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.admin__subbadge--free {
  background: rgba(107, 216, 150, 0.2);
  color: #6bd896;
}

.admin__subbadge--paid {
  background: rgba(157, 78, 221, 0.2);
  color: #b066ff;
}

.admin__warning {
  color: #fbbf24;
  font-weight: 700;
}

/* ---------- Toggle ---------- */
.admin__toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  cursor: pointer;
}

.admin__toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.admin__toggle span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.2s ease;
}

.admin__toggle span::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #8a93a6;
  transition: transform 0.2s ease, background 0.2s ease;
}

.admin__toggle input:checked + span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.admin__toggle input:checked + span::before {
  transform: translateX(16px);
  background: #fff;
}

.admin__toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}

/* ---------- Forms ---------- */
.admin__promo-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.admin__promo-form input {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.admin__promo-form input:focus {
  border-color: var(--accent);
}

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

.admin__field-input {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin__field-input span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.admin__field-input input,
.admin__field-input select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.admin__field-input input:focus,
.admin__field-input select:focus {
  border-color: var(--accent);
}

.admin__section-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 22px 0 12px;
}

.admin__section-label:first-child {
  margin-top: 0;
}

.admin__hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 14px;
  line-height: 1.5;
}

.admin__saved {
  color: #6bd896;
  font-size: 13px;
  font-weight: 600;
}

.admin__empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.admin__loading {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}

.admin__code {
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
}

/* =========================================================
   Модалки
   ========================================================= */
.modal-root {
  position: relative;
  z-index: 100;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 4, 8, 0.7);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(480px, 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: #0d0d18;
  padding: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.modal-card--danger {
  border-color: rgba(248, 113, 113, 0.3);
}

.modal-card h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}

.modal-card p {
  font-size: 13.5px;
  color: var(--text-dim);
  margin: 0 0 18px;
  line-height: 1.5;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.modal-field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.modal-field input:focus {
  border-color: var(--accent);
}

.modal-durations {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.modal-duration {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-duration:hover {
  color: var(--text);
}

.modal-duration.is-selected {
  background: var(--accent-soft);
  border-color: rgba(255, 59, 92, 0.35);
  color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions .admin__btn {
  flex: 1;
}

/* =========================================================
   Toast
   ========================================================= */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: #0d0d18;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.25s ease;
}

.toast--ok {
  border-color: rgba(107, 216, 150, 0.4);
}

.toast--ok::before {
  content: '✓';
  color: #6bd896;
}

.toast--err {
  border-color: rgba(248, 113, 113, 0.4);
}

.toast--err::before {
  content: '✕';
  color: #f87171;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 900px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-tabs {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .admin__tab {
    width: auto;
    padding: 8px 12px;
  }

  .admin-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .admin-stats {
    grid-template-columns: 1fr 1fr;
  }

  .admin__form-grid {
    grid-template-columns: 1fr;
  }

  .admin__row {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 12px;
  }

  .admin__row--head {
    display: none;
  }

  .admin__cell-actions {
    justify-content: flex-start;
  }
}
