/* ============================================================
   Hermes — Initialization Overlay
   Full-screen setup wizard that prompts for missing credentials
   and auto-starts the first scraping run.
   ============================================================ */

/* ---- Overlay backdrop ---- */
.hermes-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.hermes-overlay.visible {
  opacity: 1;
}

.hermes-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ---- Central card ---- */
.hermes-card {
  width: 780px;
  max-width: calc(100vw - 32px);
  min-height: 600px;
  max-height: calc(100vh - 64px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow:
    0 25px 60px -12px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.35s ease;
}

.hermes-overlay.visible .hermes-card {
  transform: translateY(0) scale(1);
}

/* ---- Card header ---- */
.hermes-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.hermes-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hermes-avatar svg {
  width: 20px;
  height: 20px;
}

.hermes-header-info h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--foreground);
  margin: 0;
}

.hermes-header-info p {
  font-size: 12px;
  color: var(--muted-foreground);
  margin: 2px 0 0;
}

/* ---- Chat area ---- */
.hermes-chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 200px;
}

.hermes-chat::-webkit-scrollbar {
  width: 4px;
}

.hermes-chat::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ---- Hermes message bubble ---- */
.hermes-bubble {
  display: flex;
  gap: 10px;
  align-self: flex-start;
  max-width: 92%;
  animation: hermesSlideIn 0.3s ease;
}

@keyframes hermesSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hermes-bubble-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.hermes-bubble-avatar svg {
  width: 14px;
  height: 14px;
}

.hermes-bubble-content {
  background: var(--secondary);
  color: var(--foreground);
  padding: 10px 14px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  font-size: 13.5px;
  line-height: 1.55;
}

/* ---- Typing dots ---- */
.hermes-typing {
  display: flex;
  gap: 10px;
  align-self: flex-start;
  animation: hermesSlideIn 0.2s ease;
}

.hermes-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: var(--secondary);
  border-radius: 14px;
  border-top-left-radius: 4px;
}

.hermes-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--muted-foreground);
  border-radius: 50%;
  animation: hermesBounce 1.4s ease-in-out infinite;
}

.hermes-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.hermes-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes hermesBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* ---- Credential form (inline in chat) ---- */
.hermes-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  animation: hermesSlideIn 0.3s ease;
  align-self: flex-end;
  width: 100%;
  max-width: 380px;
}

.hermes-form-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hermes-form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hermes-form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--foreground);
}

.hermes-form-group input {
  padding: 8px 12px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--foreground);
  outline: none;
  transition: border-color 0.15s;
}

.hermes-form-group input:focus {
  border-color: var(--ring);
}

.hermes-form-group input::placeholder {
  color: var(--muted-foreground);
}

.hermes-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.hermes-btn-primary {
  padding: 8px 20px;
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hermes-btn-primary:hover {
  opacity: 0.9;
}

.hermes-btn-primary:active {
  transform: scale(0.97);
}

.hermes-btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hermes-btn-secondary {
  padding: 8px 16px;
  background: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.hermes-btn-secondary:hover {
  background: var(--muted);
}

/* ---- Success checkmark ---- */
.hermes-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: 8px;
  color: #16a34a;
  font-size: 12.5px;
  font-weight: 500;
  animation: hermesSlideIn 0.3s ease;
  align-self: flex-start;
}

.hermes-check svg {
  width: 14px;
  height: 14px;
}

/* ---- Card footer ---- */
.hermes-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}

.hermes-skip {
  font-family: inherit;
  font-size: 12.5px;
  color: var(--muted-foreground);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.hermes-skip:hover {
  color: var(--foreground);
  background: var(--secondary);
}

/* ---- Spinner for save buttons ---- */
.hermes-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: hermesSpin 0.6s linear infinite;
  flex-shrink: 0;
}

@keyframes hermesSpin {
  to { transform: rotate(360deg); }
}

/* ---- Progress indicator for scraping start ---- */
.hermes-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  animation: hermesSlideIn 0.3s ease;
  align-self: flex-start;
  width: 100%;
  max-width: 380px;
}

.hermes-progress-bar {
  height: 6px;
  background: var(--secondary);
  border-radius: 3px;
  overflow: hidden;
}

.hermes-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  width: 0%;
  transition: width 0.5s ease;
  animation: hermesProgressPulse 1.5s ease-in-out infinite;
}

@keyframes hermesProgressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.hermes-progress-label {
  font-size: 12px;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---- Responsive ---- */
@media (max-width: 560px) {
  .hermes-card {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 32px);
    border-radius: 14px;
  }

  .hermes-chat {
    max-height: 50vh;
    padding: 16px;
  }

  .hermes-form {
    max-width: 100%;
  }
}

/* ============================================================
   TOTP Camera QR Scanner Modal
   ============================================================ */

/* ---- Scan QR button in hermes-init form ---- */
.hermes-totp-import-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.hermes-btn-scan-qr {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--foreground);
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.hermes-btn-scan-qr:hover {
  background: var(--muted);
  border-color: var(--ring);
}

.hermes-btn-scan-qr svg {
  flex-shrink: 0;
}

/* ---- Inline TOTP tutorial in credential form ---- */
.hermes-totp-tutorial {
  margin-top: 6px;
}

.hermes-totp-tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--secondary);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--foreground);
}

.hermes-totp-step {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}

.hermes-totp-step-num {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted-foreground);
  color: var(--background);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.hermes-totp-step-highlight {
  background: rgba(var(--brand-rgb), 0.06);
  border-radius: 4px;
  padding: 3px 4px;
  margin: -1px -4px;
}

.hermes-totp-account-badge {
  display: inline-block;
  background: var(--brand);
  color: var(--brand-foreground);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.hermes-btn-scan-qr-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-foreground);
  background: var(--brand);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.hermes-btn-scan-qr-main:hover {
  opacity: 0.9;
}

.hermes-btn-scan-qr-main:active {
  transform: scale(0.98);
}

.hermes-btn-scan-qr-main svg {
  flex-shrink: 0;
}

.hermes-totp-help {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted-foreground);
  margin-top: 6px;
  cursor: default;
}

.hermes-totp-help svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.hermes-totp-success {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: #15803d;
}

html.dark .hermes-totp-success {
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.25);
  color: #4ade80;
}

/* ---- Full-screen camera modal ---- */
.totp-camera-modal {
  position: fixed;
  inset: 0;
  z-index: 30000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.totp-camera-modal.visible {
  opacity: 1;
}

.totp-camera-modal.totp-camera-closing {
  opacity: 0;
  pointer-events: none;
}

.totp-camera-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.totp-camera-content {
  position: relative;
  z-index: 1;
  width: 740px;
  max-width: calc(100vw - 32px);
  background: var(--card, #1a1a2e);
  border: 1px solid var(--border, #333);
  border-radius: 16px;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  animation: hermesSlideIn 0.3s ease;
}

.totp-camera-header {
  padding: 20px 20px 12px;
  text-align: center;
}

.totp-camera-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--foreground, #fff);
  margin: 0 0 4px;
}

.totp-camera-header p {
  font-size: 12.5px;
  color: var(--muted-foreground, #888);
  margin: 0;
}

/* ---- Viewfinder area ---- */
.totp-camera-viewfinder {
  position: relative;
  flex: 1;
  min-width: 0;
  aspect-ratio: 4 / 3;
  background: #000;
  overflow: hidden;
}

.totp-camera-viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Scanning overlay with corner markers */
.totp-camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.totp-camera-corners {
  width: 55%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  position: relative;
  transition: border-color 0.3s;
  /* Animated scan line */
  background: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 48%,
    rgba(59, 130, 246, 0.35) 50%,
    transparent 52%,
    transparent 100%
  );
  background-size: 100% 200%;
  animation: totpScanLine 2s ease-in-out infinite;
}

.totp-camera-corners.found {
  border-color: #22c55e;
  animation: none;
  background: rgba(34, 197, 94, 0.1);
}

@keyframes totpScanLine {
  0%, 100% { background-position: 0% 0%; }
  50%      { background-position: 0% 100%; }
}

/* Corner accents */
.totp-camera-corners::before,
.totp-camera-corners::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--primary, #3b82f6);
  border-style: solid;
  border-width: 0;
}

.totp-camera-corners::before {
  top: -2px;
  left: -2px;
  border-top-width: 3px;
  border-left-width: 3px;
  border-top-left-radius: 12px;
}

.totp-camera-corners::after {
  bottom: -2px;
  right: -2px;
  border-bottom-width: 3px;
  border-right-width: 3px;
  border-bottom-right-radius: 12px;
}

.totp-camera-status {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  transition: color 0.2s;
}

/* ---- Actions footer ---- */
.totp-camera-actions {
  display: flex;
  justify-content: center;
  padding: 14px 20px;
}

.totp-camera-cancel {
  padding: 8px 24px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-foreground, #888);
  background: var(--secondary, #2a2a3e);
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.totp-camera-cancel:hover {
  color: var(--foreground, #fff);
  background: var(--muted, #3a3a4e);
}

/* ---- Two-column body ---- */
.totp-camera-body {
  display: flex;
}

/* ---- Tutorial panel (right side) ---- */
.totp-camera-tutorial {
  width: 280px;
  flex-shrink: 0;
  padding: 16px 20px;
  background: var(--card-hover, #1a1a2e);
  border-left: 1px solid var(--border, #333);
  overflow-y: auto;
}

.totp-camera-tutorial h4 {
  font-size: 13px;
  font-weight: 600;
  color: #f3f4f6;
  margin: 0 0 14px;
}

.totp-tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.totp-tutorial-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 12.5px;
  color: #d1d5db;
  line-height: 1.5;
}

.totp-tutorial-step strong {
  color: #f3f4f6;
}

.totp-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary, #3b82f6);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.totp-step-important {
  background: rgba(59, 130, 246, 0.12);
  margin: 0 -8px;
  padding: 8px 8px;
  border-radius: 8px;
  border-left: 2px solid var(--primary, #3b82f6);
}

.totp-step-important div {
  color: #e5e7eb;
}

.totp-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 1px 5px;
  margin: 0 2px;
}

.totp-account-badge {
  display: inline-block;
  margin-top: 2px;
  padding: 3px 10px;
  background: rgba(59, 130, 246, 0.2);
  color: #93bbfd;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12.5px;
}

@media (max-width: 740px) {
  .totp-camera-content {
    width: calc(100vw - 16px);
    border-radius: 12px;
  }
  .totp-camera-body {
    flex-direction: column;
  }
  .totp-camera-tutorial {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--border, #333);
    max-height: 200px;
  }
}
