/* ═══════════════════════════════════════════════════════════════════════
   TOTP Authenticator — Telegram Web App
   Dark theme, mobile-first, card-based layout
   ═══════════════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ──────────────────────────────────────────── */
:root {
  --bg:           #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card:      #1e1e36;
  --bg-card-hover:#26264a;
  --bg-elevated:  #2a2a45;
  --border:       #2e2e50;
  --text:         #e8e8f0;
  --text-secondary:#a0a0b8;
  --hint:         #6b6b80;
  --accent:       #6c5ce7;
  --accent-glow:  rgba(108, 92, 231, 0.3);
  --success:      #00cec9;
  --danger:       #e74c3c;
  --warning:      #fdcb6e;
  --radius:       14px;
  --radius-sm:    10px;
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'SF Mono', 'Cascadia Code', 'JetBrains Mono', monospace;
  --shadow:       0 4px 24px rgba(0, 0, 0, 0.4);
  --transition:   0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* Telegram theme overrides (available inside TG WebApp) */
  --tg-bg:           var(--tg-theme-bg-color, var(--bg));
  --tg-bg-secondary: var(--tg-theme-secondary-bg-color, var(--bg-secondary));
  --tg-text:         var(--tg-theme-text-color, var(--text));
  --tg-hint:         var(--tg-theme-hint-color, var(--hint));
  --tg-link:         var(--tg-theme-link-color, var(--accent));
  --tg-button:       var(--tg-theme-button-color, var(--accent));
  --tg-button-text:  var(--tg-theme-button-text-color, #fff);
}

/* ── Reset & Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--tg-text);
  background: var(--tg-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

/* ── App Layout ─────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* ── Header ─────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--tg-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-icon { color: var(--accent); display: flex; }

.app-header h1 {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  color: var(--tg-text);
  letter-spacing: -0.3px;
}

.header-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 8px;
  color: var(--tg-hint);
  cursor: pointer;
  transition: var(--transition);
}
.icon-btn:active { background: var(--bg-elevated); color: var(--tg-text); }

/* ── Main ───────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* ── Empty State ────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 12px;
}

.empty-icon { opacity: 0.4; margin-bottom: 8px; }

.empty-state h2 {
  font-size: 20px; font-weight: 600;
  color: var(--tg-text);
}

.hint-text { color: var(--tg-hint); font-size: 14px; line-height: 1.5; }

/* ── Account Cards ──────────────────────────────────────────────────── */
.account-list { display: flex; flex-direction: column; gap: 10px; }

.account-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px 0;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.account-card:active {
  background: var(--bg-card-hover);
  transform: scale(0.985);
}

.account-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.issuer-avatar {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  flex-shrink: 0;
}

.account-info { flex: 1; min-width: 0; }

.issuer-name {
  font-size: 15px; font-weight: 600;
  color: var(--tg-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.account-label {
  font-size: 12px; color: var(--tg-hint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* OTP code */
.otp-code {
  font-family: var(--font-mono);
  font-size: 32px; font-weight: 700;
  letter-spacing: 6px;
  color: var(--accent);
  text-align: center;
  padding: 6px 0 4px;
  transition: color 0.2s;
}

.otp-code.pulse {
  animation: otpPulse 0.4s ease;
}

@keyframes otpPulse {
  0%   { transform: scale(1); opacity: 1; }
  50%  { transform: scale(1.08); opacity: 0.7; }
  100% { transform: scale(1); opacity: 1; }
}

/* Countdown bar */
.countdown-bar {
  height: 3px;
  background: var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 10px -16px 0;
  overflow: hidden;
  position: relative;
}

.countdown-fill {
  height: 100%;
  background: var(--accent);
  transition: width 1s linear;
  border-radius: 0 2px 2px 0;
}

.countdown-fill.warning { background: var(--warning); }
.countdown-fill.danger { background: var(--danger); }

/* Delete hint */
.account-card .delete-hint {
  position: absolute;
  right: 12px; top: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  color: var(--danger);
  font-size: 20px;
}
.account-card.swiping .delete-hint { opacity: 1; }

/* ── FAB ────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px var(--accent-glow);
  cursor: pointer;
  z-index: 20;
  transition: var(--transition);
}
.fab:active { transform: scale(0.92); }

/* ── Modal / Bottom Sheet ───────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end;
}

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.modal-sheet {
  position: relative;
  width: 100%; max-height: 85vh;
  background: var(--tg-bg);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px 24px;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 40px; height: 4px;
  background: var(--hint); border-radius: 2px;
  margin: 0 auto 16px; opacity: 0.4;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }

/* ── Tabs ───────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.tab {
  flex: 1; padding: 10px;
  background: var(--bg-secondary);
  border: none; border-radius: var(--radius-sm);
  color: var(--tg-hint); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: var(--transition);
}
.tab.active {
  background: var(--accent);
  color: #fff;
}

.tab-content { }
.tab-content.hidden { display: none; }

/* ── QR Scanner ─────────────────────────────────────────────────────── */
.qr-reader {
  width: 100%; max-width: 300px;
  margin: 0 auto 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  aspect-ratio: 1;
}
.qr-reader video { width: 100%; height: 100%; object-fit: cover; }

#qr-reader:empty + .qr-placeholder { display: flex; }
#qr-reader:not(:empty) ~ .qr-placeholder { display: none; }

.qr-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 32px 0;
}

.scan-result {
  text-align: center; padding: 12px;
  background: var(--bg-card); border-radius: var(--radius-sm);
  margin-top: 12px;
}

.scan-result .result-issuer { font-weight: 700; color: var(--success); }
.scan-result .result-label { color: var(--tg-hint); font-size: 13px; }
/* ── Forms ──────────────────────────────────────────────────────────── */
.field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 14px;
}
.field span {
  font-size: 13px; color: var(--tg-hint); font-weight: 500;
}
.field input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--tg-text);
  font-size: 16px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.field input::placeholder { color: var(--hint); opacity: 0.6; }

.primary-btn {
  width: 100%; padding: 14px;
  background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 600;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition);
  margin-top: 4px;
}
.primary-btn:active { opacity: 0.85; transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.5; cursor: default; }

.text-btn {
  background: none; border: none;
  color: var(--tg-hint); font-size: 14px;
  cursor: pointer; padding: 8px;
}

.full-width { width: 100%; }

/* ── PIN Screen ─────────────────────────────────────────────────────── */
.pin-screen {
  position: fixed; inset: 0;
  background: var(--tg-bg);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
}

.pin-container {
  display: flex; flex-direction: column;
  align-items: center; gap: 20px;
  padding: 24px;
}

.pin-icon { color: var(--accent); opacity: 0.8; }
.pin-screen h2 { font-size: 20px; font-weight: 600; }
.pin-screen .hint-text { font-size: 13px; text-align: center; }

.pin-dots { display: flex; gap: 12px; }

.pin-dots .dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: var(--transition);
}
.pin-dots .dot.filled { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.pin-dots .dot.error { background: var(--danger); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  gap: 10px;
  justify-content: center;
}

.pin-key {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--tg-text);
  font-size: 22px; font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.pin-key:active { background: var(--accent); color: #fff; transform: scale(0.92); }
.pin-key.placeholder { visibility: hidden; }

.error-text {
  color: var(--danger); font-size: 13px;
  text-align: center;
}

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--tg-text);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 300;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(20px); }

/* ── Utility ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

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

.account-card { animation: fadeIn 0.3s ease both; }
.account-card:nth-child(1) { animation-delay: 0s; }
.account-card:nth-child(2) { animation-delay: 0.05s; }
.account-card:nth-child(3) { animation-delay: 0.1s; }
.account-card:nth-child(4) { animation-delay: 0.15s; }
.account-card:nth-child(5) { animation-delay: 0.2s; }
