/* ═══════════════════════════════════════════════════════════════════════════
   Admin Dashboard — Pro Layout
   ═══════════════════════════════════════════════════════════════════════════ */

#app {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* On the admin login screen, #app holds a single login-wrap which must fill the viewport */
#app > .login-wrap { flex: 1; }

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.sidebar-head {
  padding: 24px 20px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.03) 0%, transparent 100%);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.logo-mark {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  flex-shrink: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 4px 12px rgba(239, 68, 68, 0.4);
  letter-spacing: -1px;
}

.logo-text {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}
.logo-text b { color: var(--red); font-weight: 600; }

.admin-badge {
  font-size: 9px;
  font-family: var(--mono);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.1) 100%);
  color: var(--red-bright);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 4px 9px;
  border-radius: var(--radius-xs);
  letter-spacing: 0.7px;
  display: inline-block;
  font-weight: 700;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
}

.nav-section { padding: 12px 0 4px; }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 16px;
}

.nav-label {
  font-size: 10px;
  color: var(--text4);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 20px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all var(--tr);
  user-select: none;
  position: relative;
  font-weight: 500;
}
.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.025);
}
.nav-item.active {
  color: var(--red-bright);
  border-left-color: var(--red);
  background: linear-gradient(90deg, var(--red-dim) 0%, transparent 100%);
}
.nav-item.active::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}
.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-item.active svg { opacity: 1; }

.sidebar-spacer { flex: 1; }

.sidebar-foot {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.25) 0%, transparent 100%);
}

/* User-dashboard / Admin-area switch button (sidebar) — PROMINENT */
.go-user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12) 0%, rgba(59, 130, 246, 0.06) 100%);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12.5px;
  color: #93c5fd;
  font-weight: 500;
  transition: all var(--tr);
  box-shadow: var(--hl-top);
}
.go-user-btn:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(59, 130, 246, 0.1) 100%);
  border-color: rgba(59, 130, 246, 0.5);
  color: #bfdbfe;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}
.go-user-btn svg { opacity: 0.9; }

/* User pill */
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--tr);
  box-shadow: var(--hl-top);
}
.user-pill:hover {
  background: var(--bg4);
  border-color: var(--border2);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: 0.3px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 2px 6px rgba(239, 68, 68, 0.3);
}

.user-pill-info { flex: 1; min-width: 0; }
.user-pill-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.1px;
}
.user-pill-email {
  font-size: 10.5px;
  color: var(--text4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* ─── Main ─────────────────────────────────────────────────────────────────── */

.main {
  flex: 1;
  padding: 38px;
  overflow-x: hidden;
  min-width: 0;
}

.page { display: none; }
.page.active {
  display: block;
  animation: fadeIn 250ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

.page-title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.8px;
  line-height: 1.2;
  background: linear-gradient(180deg, #f5f5f7 0%, #d4d4d8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.page-sub {
  color: var(--text2);
  font-size: 13.5px;
  margin-top: 6px;
}

/* ─── Stat cards ───────────────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  position: relative;
  overflow: hidden;
  transition: all var(--tr);
  box-shadow: var(--shadow), var(--hl-top);
}
.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg), var(--hl-top);
  border-color: var(--border2);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent, var(--red)) 0%, transparent 100%);
  opacity: 0.8;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: -50%; right: -20%;
  width: 200px; height: 200px;
  background: radial-gradient(circle, var(--accent, var(--red)) 0%, transparent 70%);
  opacity: 0.06;
  pointer-events: none;
}

.stat-label {
  font-size: 10.5px;
  color: var(--text4);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 10px;
  font-weight: 600;
}

.stat-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.stat-icon svg {
  width: 15px;
  height: 15px;
  opacity: 0.9;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1.2px;
  line-height: 1;
  font-feature-settings: "tnum" 1;
}

.stat-sub {
  font-size: 11.5px;
  color: var(--text4);
  margin-top: 8px;
}

/* ─── Chart ────────────────────────────────────────────────────────────────── */

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow), var(--hl-top);
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.chart-area {
  height: 160px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.chart-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.chart-bar {
  width: 100%;
  background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  opacity: 0.75;
  transition: opacity var(--tr), transform var(--tr);
  position: relative;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
}
.chart-bar-wrap:hover .chart-bar {
  opacity: 1;
  transform: scaleY(1.04);
}

.chart-date {
  font-size: 9.5px;
  color: var(--text4);
  font-family: var(--mono);
  letter-spacing: 0.3px;
}

/* ─── Pagination ───────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}

.page-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--tr);
}
.page-btn:hover { border-color: var(--border3); color: var(--text); }
.page-btn.active {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
  border-color: var(--red);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.page-info {
  font-size: 12px;
  color: var(--text4);
  margin-left: auto;
}

/* ─── Detail grid ──────────────────────────────────────────────────────────── */

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

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

.detail-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.detail-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text4);
  margin-bottom: 13px;
  font-weight: 600;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  gap: 12px;
}
.detail-row:last-child { border-bottom: none; padding-bottom: 0; }
.detail-row:first-child { padding-top: 0; }

.detail-key { color: var(--text2); flex-shrink: 0; }
.detail-value {
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  text-align: right;
  word-break: break-word;
}

/* ─── Integration Guide ────────────────────────────────────────────────────── */

.itab-bar {
  display: flex;
  gap: 3px;
  margin-bottom: 18px;
  background: var(--bg3);
  padding: 4px;
  border-radius: var(--radius);
  width: fit-content;
  border: 1px solid var(--border);
  box-shadow: var(--hl-top);
}

.itab {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text2);
  transition: all var(--tr);
  border: none;
  background: transparent;
  font-family: inherit;
}
.itab.active {
  background: linear-gradient(180deg, var(--bg5) 0%, var(--bg4) 100%);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border3), 0 1px 2px rgba(0, 0, 0, 0.3);
}
.itab:hover:not(.active) { color: var(--text); }

.itab-content { display: none; }
.itab-content.active {
  display: block;
  animation: fadeIn 250ms ease both;
}

.step {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  align-items: flex-start;
}

.step-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 3px 8px rgba(239, 68, 68, 0.35);
}

.step-body { flex: 1; min-width: 0; }

.step-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.step-desc {
  font-size: 12.5px;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 10px;
}

.step-desc code {
  background: var(--bg4);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  font-family: var(--mono);
  font-size: 11.5px;
  color: #fbbf24;
  border: 1px solid var(--border);
}

/* ─── Code blocks ──────────────────────────────────────────────────────────── */

.code-block {
  background: linear-gradient(180deg, #0f1014 0%, #0a0b0d 100%);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  margin: 10px 0;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.code-block pre {
  margin: 0;
  padding: 18px 20px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: #e2e8f0;
  white-space: pre;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
  font-feature-settings: "calt" 0;
}

.code-block pre::-webkit-scrollbar { height: 6px; }
.code-block pre::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

.copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--bg5);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  font-size: 10.5px;
  font-family: var(--mono);
  color: var(--text2);
  cursor: pointer;
  transition: all var(--tr);
  opacity: 0.6;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.copy-btn:hover {
  background: var(--bg4);
  color: var(--text);
  opacity: 1;
  border-color: var(--border3);
}
.copy-btn.copied {
  color: #4ade80;
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.08);
  opacity: 1;
}

.lang-badge {
  position: absolute;
  bottom: 10px; right: 10px;
  font-size: 9.5px;
  font-family: var(--mono);
  color: var(--text4);
  background: var(--bg5);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  pointer-events: none;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
}

/* ─── Secret reveal box ────────────────────────────────────────────────────── */

.secret-box {
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.05) 0%, rgba(239, 68, 68, 0.02) 100%);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  box-shadow: 0 0 32px rgba(239, 68, 68, 0.08);
}

.secret-label {
  font-size: 10.5px;
  color: var(--red-bright);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-weight: 700;
}

.secret-value {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text);
  word-break: break-all;
  line-height: 1.7;
  background: var(--bg);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ─── API endpoint list ────────────────────────────────────────────────────── */

.endpoint {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  transition: background var(--tr);
}
.endpoint:hover { background: rgba(255, 255, 255, 0.015); }
.endpoint:last-child { border-bottom: none; }

.endpoint-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 5px;
}

.endpoint-path {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
}

.endpoint-desc {
  font-size: 12.5px;
  color: var(--text2);
  margin-left: 64px;
  line-height: 1.5;
}

.endpoint-params {
  font-size: 11px;
  color: var(--text4);
  margin-left: 64px;
  margin-top: 5px;
  font-family: var(--mono);
}

/* ─── Login screen ─────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.login-wrap::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: 600px;
  background:
    radial-gradient(circle at center, rgba(239, 68, 68, 0.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.login-card {
  background: var(--surface-2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  animation: cardIn 400ms cubic-bezier(0.16, 1, 0.3, 1) both;
  box-shadow: var(--shadow-xl), var(--hl-top);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(239, 68, 68, 0.5) 50%, transparent 100%);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.6px;
  margin-bottom: 6px;
}

.login-sub {
  color: var(--text2);
  font-size: 13.5px;
  margin-bottom: 26px;
}

/* ─── Audit action colors ──────────────────────────────────────────────────── */

.action-login         { color: #4ade80; }
.action-login_failed  { color: var(--red-bright); }
.action-migrate       { color: #60a5fa; }
.action-register      { color: #fbbf24; }
.action-password_change,
.action-password_reset { color: #c084fc; }
.action-totp_enable,
.action-totp_disable  { color: #f9a8d4; }
.action-account_delete { color: var(--red-bright); }

/* ─── Service logo thumb (in table) ────────────────────────────────────────── */

.svc-logo-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background-color: var(--bg4);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: 1px solid var(--border2);
  flex-shrink: 0;
  box-shadow: var(--hl-top), 0 1px 2px rgba(0, 0, 0, 0.3);
}

.svc-logo-thumb.svc-logo-empty {
  background: linear-gradient(135deg, var(--bg4) 0%, var(--bg3) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--red-bright);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.5px;
}

/* ─── Logo uploader widget ─────────────────────────────────────────────────── */

.logo-uploader {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.logo-uploader-preview {
  width: 100%;
  height: 140px;
  background: var(--bg3);
  border: 2px dashed var(--border3);
  border-radius: var(--radius);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: all var(--tr);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.logo-uploader-preview:hover {
  border-color: var(--red);
  background-color: var(--bg4);
}

.logo-uploader-preview.dragging {
  border-color: var(--red);
  background-color: rgba(239, 68, 68, 0.05);
  border-style: solid;
}

.logo-uploader-placeholder {
  text-align: center;
  pointer-events: none;
}

.logo-uploader-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg4);
  border-radius: 50%;
  border: 1px solid var(--border2);
  color: var(--text3);
}

.logo-uploader-hint {
  font-size: 11.5px;
  color: var(--text3);
  letter-spacing: -0.1px;
}

.logo-uploader-actions {
  display: flex;
  gap: 8px;
}

.logo-uploader-actions .btn {
  flex: 1;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .sidebar { width: 220px; }
  .main { padding: 28px; }
  .page-title { font-size: 24px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .sidebar { width: 60px; }
  .sidebar-head .logo-text,
  .sidebar-head .admin-badge,
  .nav-label,
  .nav-item span:not(.badge),
  .user-pill-info,
  .go-user-btn span { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .main { padding: 20px; }
}
