.admin-wrap {
  position: relative;
  z-index: 2;
  width: min(100%, 1280px);
  max-width: 1280px;
  margin: 32px auto 80px;
  padding: 0 clamp(12px, 3vw, 24px);
}

.admin-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 28px);
}

.admin-card h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logout-link {
  color: var(--danger);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid rgba(255,45,85,0.35);
  padding: 8px 14px;
  border-radius: 8px;
  transition: background 0.2s;
}

.logout-link:hover { background: rgba(255,45,85,0.12); }

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 20px;
}

.search-box {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box input {
  min-width: 260px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,229,255,0.12);
}

.per-page-label {
  font-size: 0.78rem;
  color: var(--muted);
  align-self: center;
}

.per-page-select {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.per-page-select:focus {
  border-color: var(--accent);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #f87171;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.22);
}

.btn-danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.table-scroll-zone {
  position: relative;
  margin-bottom: 4px;
}

.table-scroll-hint {
  display: none;
  margin: 0 0 8px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-2);
  max-height: min(70vh, 620px);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.table-wrap::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.table-wrap--messages {
  max-height: min(60vh, 420px);
}

.table-wrap--logs {
  max-height: min(72vh, 680px);
}

.table-wrap--templates {
  max-height: min(50vh, 360px);
}

.admin-table {
  width: 100%;
  min-width: 960px;
  table-layout: auto;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
}

.admin-table--sheet {
  min-width: 1100px;
}

.admin-table--sheet#logTable {
  min-width: 1280px;
}

.admin-table th {
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--accent);
  font-weight: 600;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  z-index: 2;
  white-space: nowrap;
}

.admin-table-headers th {
  vertical-align: middle;
}

.col-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

.col-sort-btn:hover {
  color: var(--accent-soft);
}

.col-sort-btn.is-sorted {
  color: var(--text);
}

.col-sort-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 12px;
  font-size: 0.62rem;
  line-height: 1;
  color: var(--muted);
  opacity: 0.45;
}

.col-sort-btn.is-sorted .col-sort-icon {
  color: var(--accent);
  opacity: 1;
}

.col-sort-btn:not(.is-sorted):hover .col-sort-icon::before {
  content: '⇅';
  font-size: 0.68rem;
  opacity: 0.65;
}

.admin-table-filters th {
  top: 44px;
  padding: 6px 8px;
  background: var(--card-2);
  z-index: 3;
  vertical-align: middle;
}

.col-filter-input {
  width: 100%;
  min-width: 72px;
  box-sizing: border-box;
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 500;
  outline: none;
}

.col-filter-input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.col-filter-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.15);
}

.col-filter-input.is-active {
  border-color: var(--accent-soft);
  background: rgba(201, 162, 39, 0.08);
}

.col-filter-clear {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
}

.col-filter-clear:hover {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.1);
}

.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: rgba(0,229,255,0.04); }

.admin-table .col-ip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.admin-table th.col-ua,
.admin-table td.col-ua {
  width: 200px;
  max-width: 200px;
  color: var(--muted);
  overflow: hidden;
  padding-top: 8px;
  padding-bottom: 8px;
}

.admin-table .col-ua-inner {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  font-size: 0.78rem;
  line-height: 1.35;
}

.admin-table .col-ua-inner::-webkit-scrollbar {
  height: 4px;
}

.admin-table .col-ua-inner::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.admin-table .col-time { white-space: nowrap; color: var(--muted); }
.admin-table .col-conf,
.admin-table .col-rows { text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; white-space: nowrap; }
.admin-table .col-check { width: 36px; text-align: center; }
.admin-table .col-del { width: 48px; text-align: center; }

.admin-table th.col-msg,
.admin-table td.col-msg {
  width: 280px;
  max-width: 280px;
  overflow: hidden;
}

.admin-table .col-msg-inner {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  font-size: 0.82rem;
  line-height: 1.4;
}

.msg-row-unread td {
  background: rgba(201, 162, 39, 0.06);
}

.admin-head--section {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.admin-topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.admin-mail-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  color: var(--muted);
  text-decoration: none;
  opacity: 0.72;
  transition: opacity 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.admin-mail-link:hover {
  opacity: 1;
  color: var(--accent-soft);
  border-color: var(--border);
}

.admin-mail-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #0b1f33;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.admin-mail-badge.hidden {
  display: none !important;
}

.btn-del {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
  color: #f87171;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}

.btn-del:hover {
  background: rgba(248, 113, 113, 0.22);
}

.admin-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 40px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-upload { background: rgba(0,229,255,0.12); color: var(--accent); }
.badge-download { background: rgba(0,210,106,0.12); color: var(--success); }

.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.pagination-meta {
  color: var(--muted);
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pagination button {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
}

.pagination button.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #000;
  border-color: transparent;
}

.pagination button:disabled { opacity: 0.4; }

.pagination .page-ellipsis {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 4px;
}

@media (max-width: 900px) {
  .table-scroll-hint {
    display: block;
  }

  .admin-head { flex-direction: column; align-items: stretch; }
  .search-box { width: 100%; }
  .search-box input,
  .search-box .per-page-select,
  .search-box .btn-ghost,
  .search-box .btn-danger {
    flex: 1 1 auto;
    min-width: 0;
  }
  .search-box input { width: 100%; min-width: 0; }

  .pagination-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .pagination {
    justify-content: center;
  }
}

@media (max-width: 600px) {
  .admin-wrap {
    margin-top: 20px;
    margin-bottom: 64px;
  }

  .admin-card h2 {
    font-size: 1.25rem;
  }

  .template-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    padding: 14px 10px;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .admin-table {
    font-size: 0.8rem;
  }

  .admin-table th,
  .admin-table td {
    padding: 10px 10px;
  }

  .col-filter-input {
    min-width: 64px;
    font-size: 0.72rem;
  }
}

.template-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
  gap: 16px;
  margin: 20px 0 30px;
}

.stat-card {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: clamp(14px, 2.5vw, 20px);
  text-align: center;
  min-width: 0;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-view {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(0,229,255,0.4);
  background: rgba(0,229,255,0.1);
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  margin-right: 6px;
}

.btn-view:hover {
  background: rgba(0,229,255,0.22);
}
