:root {
  --sidebar: #0f2744;
  --sidebar-hover: #163456;
  --sidebar-active: #1a4a7a;
  --brand: #1e3a5f;
  --bg: #f0f3f7;
  --card: #ffffff;
  --ink: #1a2332;
  --muted: #5b6b7c;
  --line: #d5dde8;
  --line-soft: #e8eef5;
  --danger: #b91c1c;
  --ok: #15803d;
  --accent: #0e7490;
  --shadow: 0 1px 2px rgba(15, 39, 68, 0.06), 0 8px 24px rgba(15, 39, 68, 0.06);
  --radius: 12px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 15px;
}

a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- App shell --- */
.admin-app {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(180deg, #0c223c 0%, #143556 100%);
  color: #e8eef5;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 16px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, #2a6fb0, #0e7490);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.sidebar-brand span {
  display: block;
  font-size: 12px;
  color: #9db4cc;
  font-weight: 500;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #c5d4e4;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.sidebar-nav a.is-active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 3px 0 0 #38bdf8;
}

.nav-ico {
  width: 1.25em;
  text-align: center;
  opacity: 0.85;
  font-size: 13px;
}

.sidebar-foot {
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
}

.sidebar-user {
  color: #9db4cc;
  margin-bottom: 6px;
  padding: 0 8px;
}

.sidebar-foot a {
  display: inline-block;
  padding: 6px 8px;
  color: #bfdbfe;
  font-weight: 600;
}

.admin-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.admin-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px 8px;
  background: transparent;
}

.page-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.admin-top-meta { display: flex; gap: 8px; align-items: center; }

.admin-content {
  padding: 12px 28px 40px;
  width: 100%;
  max-width: none;
}

/* --- Cards & stats --- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

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

.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-card .hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.stat-card.accent .value { color: var(--accent); }
.stat-card.ok .value { color: var(--ok); }

/* --- Tables --- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: auto;
}

table.data th,
table.data td {
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 14px;
  text-align: start;
  vertical-align: middle;
}

table.data th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  background: #f7f9fc;
}

table.data tbody tr:hover td {
  background: #f8fafc;
}

table.data td.num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

table.data .col-name { min-width: 140px; }
table.data .col-domains { min-width: 160px; max-width: 280px; }
table.data .col-token { min-width: 200px; }
table.data .col-actions { white-space: nowrap; width: 1%; }

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

.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef4fa;
  color: #334155;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.token-cell {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: ltr;
  text-align: left;
}

/* --- Detail layout --- */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.meta-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.meta-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}

.meta-list li:last-child { border-bottom: 0; }

.meta-list .k { color: var(--muted); font-weight: 600; flex-shrink: 0; }
.meta-list .v {
  font-weight: 600;
  text-align: end;
  word-break: break-word;
}

.history-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.history-bar {
  flex: 1;
  height: 8px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
  min-width: 60px;
}

.history-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #0e7490, #2563eb);
  border-radius: inherit;
}

.empty-state {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
}

/* --- Forms & UI bits --- */
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 14px;
}
.flash-ok { background: #ecfdf5; color: #166534; border: 1px solid #a7f3d0; }
.flash-err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-active { background: #dcfce7; color: #166534; }
.badge-off { background: #e2e8f0; color: #475569; }
.badge-disabled { background: #e2e8f0; color: #475569; } /* legacy */
.badge-suspended { background: #fee2e2; color: #991b1b; }
.badge-over_quota { background: #fef3c7; color: #92400e; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #eef2f7; text-decoration: none; }
.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: #152a45;
}
.btn-primary:hover { background: #152a45; color: #fff; }
.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: #1d4ed8;
  padding-inline: 8px;
}
.btn-sm { padding: 6px 10px; font-size: 12px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
  align-items: center;
}

.inline-form { display: inline; }

label {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 13px;
}

input[type=text],
input[type=password],
input[type=email],
input[type=tel],
input[type=number],
input[type=date],
input[type=search],
textarea,
select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  appearance: none;
  -webkit-appearance: none;
}
input[type=number] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=date] {
  min-height: 42px;
  line-height: 1.2;
}
input[type=date]::-webkit-calendar-picker-indicator {
  opacity: 0.55;
  cursor: pointer;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235b6b7c' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 36px;
}
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(14, 116, 144, 0.35);
  border-color: var(--accent);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.check-row input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex-shrink: 0;
  border: 2px solid #94a3b8;
  border-radius: 5px;
  background: #fff;
  display: grid;
  place-content: center;
  cursor: pointer;
}
.check-row input[type=checkbox]::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform .12s ease;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: inset 1em 1em #fff;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0, 43% 62%);
}
.check-row input[type=checkbox]:checked {
  border-color: var(--accent);
  background: var(--accent);
}
.check-row input[type=checkbox]:checked::before {
  transform: scale(1);
}
.check-row input[type=checkbox]:focus-visible {
  outline: 2px solid rgba(14, 116, 144, 0.45);
  outline-offset: 2px;
}
.check-row .check-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.check-row .check-text small {
  font-weight: 500;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
}

.sidebar-clock {
  padding: 0 8px 8px;
  font-size: 12px;
  color: #9db4cc;
}

textarea {
  min-height: 100px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

code, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

.embed {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 8px;
}
.copy-row .embed {
  flex: 1;
  margin: 0;
  white-space: nowrap;
}

.check-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.check-list li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}
.check-list li:last-child { border-bottom: 0; }
.check-ok { color: var(--ok); font-weight: 800; }
.check-bad { color: var(--danger); font-weight: 800; }

/* --- Login --- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(14, 116, 144, 0.18), transparent),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(30, 58, 95, 0.2), transparent),
    var(--bg);
}

.login-card {
  width: min(400px, 92vw);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.login-card button {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* --- Responsive --- */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .admin-app { flex-direction: column; }
  .sidebar {
    position: relative;
    width: 100%;
    min-height: 0;
    padding: 14px;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .admin-content,
  .admin-top {
    padding-inline: 16px;
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

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