/* ---------------------------------------------------------------------------
   Templates & Instagram Video Deep-Dive Analyzer Styles
   --------------------------------------------------------------------------- */

.templates-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Hero / Analyzer Input Card */
.analyzer-hero-card {
  background: linear-gradient(135deg, rgba(30, 27, 75, 0.75) 0%, rgba(15, 23, 42, 0.85) 100%);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: var(--radius-lg, 16px);
  padding: 24px 28px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 16px 40px -16px rgba(139, 92, 246, 0.25);
}

.analyzer-hero-card::before {
  content: "";
  position: absolute;
  top: -50%;
  right: -20%;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(236, 72, 153, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.analyzer-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.analyzer-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(236, 72, 153, 0.15);
  border: 1px solid rgba(236, 72, 153, 0.35);
  color: #f472b6;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 999px;
}

.analyzer-form-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.analyzer-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.analyzer-url-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14px;
  color: #fff;
  outline: none;
  transition: all 0.2s ease;
}

.analyzer-url-input:focus {
  border-color: #a855f7;
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}

.analyzer-secondary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.analyzer-niche-select {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-muted, #94a3b8);
  outline: none;
}

.analyzer-toggle-transcript-btn {
  font-size: 12px;
  color: #a5b4fc;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 6px;
}

.analyzer-transcript-drawer {
  display: none;
  margin-top: 12px;
}

.analyzer-transcript-drawer.open {
  display: block;
}

.analyzer-transcript-textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fff;
  min-height: 80px;
  resize: vertical;
  outline: none;
}

/* Toolbar & Filters */
.templates-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  background: var(--bg-card, #131722);
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-lg, 16px);
  padding: 14px 18px;
}

.templates-filter-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.template-filter-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  color: var(--text-muted, #94a3b8);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.template-filter-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.template-filter-chip.active {
  background: rgba(139, 92, 246, 0.2);
  border-color: rgba(139, 92, 246, 0.4);
  color: #c4b5fd;
}

.templates-sort-select {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: #e2e8f0;
  outline: none;
}

/* Templates Grid */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.template-card {
  background: var(--bg-card, #131722);
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-lg, 16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.template-card:hover {
  transform: translateY(-4px);
  border-color: rgba(139, 92, 246, 0.4);
  box-shadow: 0 16px 36px -12px rgba(0, 0, 0, 0.5), 0 0 24px -6px rgba(139, 92, 246, 0.2);
}

.template-card-preview {
  height: 220px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  overflow: hidden;
  background-color: #0b0f19;
  cursor: pointer;
}

.template-preview-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  transition: opacity 0.35s ease, transform 0.4s ease;
}

.template-preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.template-preview-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.1) 45%, rgba(0, 0, 0, 0.75) 100%);
  z-index: 3;
  pointer-events: none;
}

.template-card:hover .template-preview-poster {
  transform: scale(1.04);
}

.template-card.is-playing .template-preview-video {
  opacity: 1;
}

.template-card.is-playing .template-preview-poster {
  opacity: 0;
}

.template-top-badges {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 4;
}

.template-views-badge {
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  color: #f8fafc;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.template-score-badge {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
}

.template-preview-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  text-align: center;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.template-card.is-playing .template-preview-center {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.85);
}

.template-hover-live-pill {
  position: absolute;
  bottom: 42px;
  left: 16px;
  z-index: 4;
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.template-card.is-playing .template-hover-live-pill {
  opacity: 1;
  transform: translateY(0);
}

.template-play-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  display: inline-grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease, background 0.2s ease;
}

.template-card:hover .template-play-icon {
  transform: scale(1.1);
  background: rgba(139, 92, 246, 0.85);
  border-color: #c4b5fd;
}

.template-creator-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 4;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

.template-card-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.template-hook-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 10px 12px;
}

.template-hook-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a78bfa;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.template-hook-text {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  color: #f1f5f9;
  font-style: italic;
}

.template-format-pill {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.template-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}

/* Deep Dive Modal */
.analysis-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  z-index: 9999;
  display: none;
  place-items: center;
  padding: 20px;
}

.analysis-modal-backdrop.open {
  display: grid;
}

.analysis-modal-card {
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  background: #0f131f;
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9), 0 0 40px -10px rgba(139, 92, 246, 0.35);
  animation: modalScaleUp 0.25s ease-out;
}

@keyframes modalScaleUp {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.analysis-modal-header {
  padding: 20px 24px;
  border-b: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(180deg, rgba(26, 31, 46, 0.9) 0%, rgba(15, 19, 31, 0.9) 100%);
}

.analysis-modal-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #94a3b8;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s;
}

.analysis-modal-close-btn:hover {
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
}

.analysis-modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Breakdown Grid within Modal */
.analysis-two-col {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 18px;
}

.analysis-panel {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.analysis-panel-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a78bfa;
  display: flex;
  align-items: center;
  gap: 6px;
}

.transcript-timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.transcript-step-row {
  display: grid;
  grid-template-columns: 75px 1fr;
  gap: 12px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  font-size: 13px;
}

.transcript-time {
  font-family: monospace;
  font-weight: 700;
  color: #38bdf8;
  font-size: 11.5px;
}

.storytelling-step-pill {
  padding: 10px 14px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
}

.storytelling-step-header {
  font-weight: 700;
  color: #c4b5fd;
  margin-bottom: 2px;
}

.analysis-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 14, 21, 0.95);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

@media (max-width: 768px) {
  .analyzer-form-grid {
    grid-template-columns: 1fr;
  }
  .analysis-two-col {
    grid-template-columns: 1fr;
  }
  .templates-grid {
    grid-template-columns: 1fr;
  }
}

/* Find viral Reels (research) */
.research-hint { margin: 8px 0 0; font-size: 12px; line-height: 1.5; color: var(--text-muted); }
.research-hint span { color: #c4b5fd; }
label.btn.research-upload { cursor: pointer; font-size: 12.5px; padding: 7px 12px; }
.research-results { margin: 18px 0 22px; padding: 18px; border-radius: 16px; background: var(--bg-card); border: 1px solid var(--border-subtle); }
.research-results[hidden] { display: none; }
.research-results-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 6px 16px; margin-bottom: 14px; }
.research-results-title { margin: 0; font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.research-account { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.research-account[hidden] { display: none; }
.research-account > div { display: flex; flex-direction: column; line-height: 1.3; }
.research-account small { font-size: 12px; color: var(--text-muted); }
.research-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.research-card { display: flex; flex-direction: column; border-radius: 14px; overflow: hidden; background: var(--bg-card-elevated); border: 1px solid var(--border-subtle); min-width: 0; }
.research-media { position: relative; aspect-ratio: 4 / 5; background: #0b0e15; }
.research-media video, .research-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.research-play { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(11, 14, 21, 0.62); color: #fff; font-size: 20px; padding-left: 4px; cursor: pointer; backdrop-filter: blur(4px); transition: transform 0.15s ease, background 0.15s ease; }
.research-play:hover, .research-play:focus-visible { background: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #ec4899); transform: translate(-50%, -50%) scale(1.08); }
.research-play[hidden] { display: none; }
.research-media > [hidden] { display: none; }
.research-hover-hint { position: absolute; right: 8px; bottom: 8px; padding: 3px 8px; border-radius: 999px; background: rgba(11, 14, 21, 0.62); color: #fff; font-size: 11px; font-weight: 600; pointer-events: none; backdrop-filter: blur(4px); }
.research-no-media { display: grid; place-items: center; height: 100%; padding: 14px; text-align: center; font-size: 12px; line-height: 1.45; color: var(--text-muted); }
.research-rank { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 11px; font-weight: 700; }
.research-body { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; flex: 1; }
.research-stats { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12.5px; color: var(--text-muted); }
.research-stats b { color: var(--text-main); }
.research-caption { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.research-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.research-actions .btn { font-size: 11.5px; padding: 6px 10px; text-decoration: none; }
.research-link { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border-subtle); background: rgba(255, 255, 255, 0.04); color: var(--text-main); font-size: 11.5px; font-weight: 600; text-decoration: none; }
.research-link:hover { border-color: rgba(99, 102, 241, 0.5); }
#tab-templates .analyzer-secondary-row .analyzer-niche-select { width: auto; flex: 0 0 auto; }
