:root {
  --bg: #070a10;
  --bg-elevated: #0d1219;
  --surface: #111823;
  --surface-2: #17202e;
  --surface-hover: #1c2634;
  --border: #1f2937;
  --border-focus: #3b82f6;
  --text: #e8edf4;
  --text-2: #94a3b8;
  --text-3: #5b6b80;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --danger: #f87171;
  --success: #34d399;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: 'Vazirmatn', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 85% -5%, rgba(59, 130, 246, 0.10), transparent 60%),
    radial-gradient(ellipse 50% 35% at 10% 110%, rgba(99, 102, 241, 0.07), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; min-height: 100dvh; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

input[type="search"]::-webkit-search-cancel-button,
input[type="text"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 28px 32px;
  box-shadow: var(--shadow);
  animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.lock-badge {
  width: 72px; height: 72px;
  margin: 0 auto 22px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  border-radius: 22px;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.25), 0 10px 30px var(--accent-glow);
}
.lock-badge svg { width: 32px; height: 32px; color: #fff; }

.login-card h1 {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.login-card .sub {
  text-align: center;
  color: var(--text-2);
  font-size: 13.5px;
  margin: 8px 0 28px;
  line-height: 1.7;
}

.field { position: relative; }

.field input {
  width: 100%;
  height: 54px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  padding: 0 48px 0 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  letter-spacing: 2px;
  direction: ltr;
  text-align: left;
}
.field input::placeholder { color: var(--text-3); letter-spacing: 0; text-align: left; }
.field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.eye-btn {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: none; border: none;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 10px;
  transition: color 0.2s;
}
.eye-btn:hover, .eye-btn:active { color: var(--text-2); }
.eye-btn svg { width: 21px; height: 21px; }

.login-error {
  display: none;
  align-items: center;
  gap: 7px;
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
}
.login-error.show { display: flex; }
.login-error svg { width: 16px; height: 16px; flex-shrink: 0; }

.login-card.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-5px); }
}

.btn-primary {
  width: 100%;
  height: 54px;
  margin-top: 20px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.75; cursor: default; }

.btn-primary #login-btn-text {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#main-screen { padding-bottom: calc(24px + var(--safe-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: rgba(7, 10, 16, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(31, 41, 55, 0.6);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  border-radius: 11px;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.brand-icon svg { width: 19px; height: 19px; color: #fff; }
.brand h2 { font-size: 16.5px; font-weight: 800; }
.brand span { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; margin-top: 1px; }

.logout-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.logout-btn:active { background: var(--surface-hover); color: var(--danger); }
.logout-btn svg { width: 18px; height: 18px; }

.search-wrap { position: relative; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 15px;
  height: 52px;
  transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}
.search-box:focus-within {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.14), 0 8px 24px rgba(0, 0, 0, 0.35);
}

.search-icon {
  display: grid; place-items: center;
  padding: 0 15px 0 8px;
  color: var(--text-3);
  transition: color 0.25s;
}
.search-box:focus-within .search-icon { color: var(--accent-2); }
.search-icon svg { width: 20px; height: 20px; }

#search-input {
  flex: 1;
  height: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15.5px;
  min-width: 0;
}
#search-input::placeholder { color: var(--text-3); }

.clear-btn {
  display: none;
  width: 40px; height: 40px;
  place-items: center;
  margin-left: 5px;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 10px;
  transition: color 0.2s;
}
.clear-btn.show { display: grid; }
.clear-btn:active { color: var(--text); }
.clear-btn svg { width: 17px; height: 17px; }

.search-loading {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  display: none;
}
.search-loading.show { display: block; }
.search-loading .spinner { width: 17px; height: 17px; border-width: 2px; border-color: rgba(96,165,250,0.25); border-top-color: var(--accent-2); }

.results-meta {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 4px;
  font-size: 12.5px;
  color: var(--text-2);
}
.results-meta.show { display: flex; }
.results-meta b { color: var(--accent-2); font-weight: 700; }

#results { padding: 10px 14px 0; display: flex; flex-direction: column; gap: 12px; }

.user-card {
  background: linear-gradient(180deg, var(--surface) 0%, rgba(13, 18, 25, 0.9) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  animation: cardIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: border-color 0.2s;
}
.user-card:active { border-color: #2b3a4f; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.card-head {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 11px 12px;
  background: rgba(23, 32, 46, 0.4);
  border-bottom: 1px solid var(--border);
}

.avatar {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
}

.card-head-info { flex: 1; min-width: 0; }
.card-head-info .name {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.card-head-info .sub {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 2px;
}

.card-body { padding: 5px 12px 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(31, 41, 55, 0.38);
}
.row:last-child { border-bottom: none; }

.row .ic {
  width: 28px; height: 28px;
  flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--surface-2);
  border-radius: 8px;
  color: var(--text-3);
}
.row.is-key .ic {
  background: rgba(59, 130, 246, 0.13);
  color: var(--accent-2);
}
.row .ic svg { width: 15px; height: 15px; }

.row .k {
  width: 62px;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-3);
}
.row .v {
  flex: 1;
  min-width: 0;
  font-size: 12.7px;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.45;
  text-align: left;
}
.row .v.num {
  direction: ltr;
  font-feature-settings: 'tnum';
  letter-spacing: 0.3px;
}
.row .v.accent { color: var(--accent-2); font-weight: 600; }

.copy-btn {
  width: 36px; height: 36px;
  flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-2);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}
.copy-btn:active { color: var(--success); background: var(--surface-hover); }
.copy-btn svg { width: 16px; height: 16px; }

mark {
  background: rgba(59, 130, 246, 0.28);
  color: var(--accent-2);
  border-radius: 4px;
  padding: 0 2px;
}

.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
}
.sk-head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.sk {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-avatar { width: 46px; height: 46px; border-radius: 14px; flex-shrink: 0; }
.sk-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.sk-line { height: 11px; }
.sk-body { display: flex; flex-direction: column; gap: 11px; }

.state-view {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 70px 32px;
  color: var(--text-2);
}
.state-view.show { display: flex; }
.state-view .state-icon {
  width: 76px; height: 76px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  margin-bottom: 20px;
}
.state-view .state-icon svg { width: 34px; height: 34px; color: var(--text-3); }
.state-view h3 { color: var(--text); font-size: 16.5px; font-weight: 700; margin-bottom: 7px; }
.state-view p { font-size: 13.5px; line-height: 1.8; max-width: 280px; }

.retry-btn {
  margin-top: 18px;
  padding: 11px 28px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.retry-btn:active { background: var(--surface-hover); }

#load-more-sentinel { height: 1px; }
.load-more-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px 0 10px;
  color: var(--text-3);
  font-size: 13px;
}
.load-more-indicator.show { display: flex; }
.load-more-indicator .spinner { width: 18px; height: 18px; border-width: 2px; border-color: rgba(96,165,250,0.25); border-top-color: var(--accent-2); }

.end-of-list {
  display: none;
  text-align: center;
  padding: 24px 0 10px;
  color: var(--text-3);
  font-size: 12.5px;
}
.end-of-list.show { display: block; }

#toast {
  position: fixed;
  bottom: calc(28px + var(--safe-bottom));
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 9px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: var(--shadow);
  z-index: 100;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast svg { width: 17px; height: 17px; color: var(--success); }
#toast.error svg { color: var(--danger); }

#scroll-top-btn {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 18px;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  border: none;
  border-radius: 15px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px var(--accent-glow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  z-index: 90;
}
#scroll-top-btn.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
#scroll-top-btn svg { width: 20px; height: 20px; }

@media (min-width: 640px) {
  #results, .results-meta, .topbar-inner { max-width: 640px; margin-inline: auto; width: 100%; }
}
