/* ============================================
   WORDTUNE CODE LIBRARY - PROFESSIONAL CSS
   Mobile-First | Clean | Accessible
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
  /* Light Theme (Default) */
  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-elevated: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --accent: #e94560;
  --accent-dark: #c7354e;
  --accent-light: #fecdd3;
  --success: #10b981;
  --gradient-start: #8b5cf6;
  --gradient-end: #ec4899;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
  --transition: all 0.2s ease;
}

[data-theme="dark"] {
  --bg-body: #0f0f1a;
  --bg-surface: #1a1a2a;
  --bg-surface-hover: #252540;
  --bg-elevated: #252540;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-light: #2d2d3a;
  --border-medium: #3d3d4a;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.2);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.2);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  transition: var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

/* ---------- Ad Container ---------- */
.ad-container {
  text-align: center;
  padding: 0.75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
}

.ad-container ins {
  display: inline-block;
  max-width: 100%;
  height: auto;
}

/* ---------- Header ---------- */
.header {
  background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 100%);
  padding: 0.875rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .header {
    padding: 0.875rem 1rem;
  }
  .header-container {
    flex-direction: column;
    gap: 1rem;
  }
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 1.8rem;
}

.logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.02em;
}

.logo-badge {
  background: var(--accent);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
}

.nav-links {
  display: flex;
  gap: 1.8rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.4rem 1.2rem;
  border-radius: 60px;
  backdrop-filter: blur(4px);
}

@media (max-width: 768px) {
  .nav-links {
    width: 100%;
    justify-content: center;
    gap: 1.2rem;
    padding: 0.6rem 1rem;
    border-radius: 40px;
  }
}

.nav-links a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
}

.nav-links a i {
  font-size: 0.85rem;
}

.nav-links a:hover {
  color: white;
}

.nav-links a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.header-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .header-actions {
    width: 100%;
    justify-content: center;
  }
}

.wizard-btn {
  background: var(--accent);
  color: white;
  padding: 0.5rem 1.3rem;
  border-radius: 40px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.wizard-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.icon-btn:hover {
  background: var(--accent);
  transform: scale(1.05);
}

/* ---------- Hero Section ---------- */
.hero {
  padding: 3rem 1.5rem;
  text-align: center;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
}

.hero h1 {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

@media (min-width: 768px) {
  .hero {
    padding: 4rem 1.5rem;
  }
  .hero h1 {
    font-size: 3rem;
  }
}

@media (min-width: 1024px) {
  .hero h1 {
    font-size: 3.5rem;
  }
}

.hero-gradient {
  background: linear-gradient(135deg, var(--accent), var(--gradient-start));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 1.5rem;
}

@media (min-width: 768px) {
  .hero p {
    font-size: 1.125rem;
  }
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1.5rem;
}

.stat {
  text-align: center;
}

.stat-number {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

@media (min-width: 768px) {
  .hero-stats {
    gap: 3rem;
  }
  .stat-number {
    font-size: 2rem;
  }
}

/* ---------- Search Section ---------- */
.search-section {
  padding: 1.5rem 0 0.5rem;
  background: var(--bg-body);
}

.search-bar {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.875rem;
  pointer-events: none;
}

#searchInput {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 2.5rem;
  border: 2px solid var(--border-light);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: var(--transition);
}

#searchInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.clear-search {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0.25rem;
}

/* ---------- Professional Category Menu ---------- */
.category-section {
  padding: 0.5rem 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
}

.category-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.scroll-arrow {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.scroll-arrow:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.category-scroll {
  flex: 1;
  overflow-x: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.category-scroll::-webkit-scrollbar {
  height: 4px;
}

.category-scroll::-webkit-scrollbar-track {
  background: var(--border-light);
  border-radius: 10px;
}

.category-scroll::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 10px;
}

.category-list {
  display: flex;
  gap: 0.5rem;
  min-width: min-content;
  padding: 0.25rem 0;
}

.cat-btn {
  padding: 0.5rem 1.2rem;
  border-radius: 40px;
  border: 1px solid var(--border-light);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.cat-btn:hover {
  background: rgba(233, 69, 96, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.cat-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Desktop: center the menu */
@media (min-width: 768px) {
  .category-wrapper {
    max-width: 600px;
    margin: 0 auto;
  }
}

/* Mobile: smaller buttons */
@media (max-width: 767px) {
  .cat-btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.75rem;
  }
}

/* ---------- Options Section ---------- */
.options-section {
  padding: 1rem 0;
  background: var(--bg-body);
}

.options-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.results-info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.options-right {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.sort-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  padding: 0.4rem 0.8rem;
  border-radius: 40px;
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
}

.view-buttons {
  display: flex;
  gap: 0.5rem;
}

.view-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.view-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ---------- Main Templates Grid ---------- */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

@media (min-width: 768px) {
  .main {
    padding: 2rem 1.5rem;
  }
}

.templates-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .templates-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .templates-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.templates-grid.list {
  display: flex;
  flex-direction: column;
}

.templates-grid.list .template-card {
  display: flex;
  flex-direction: column;
}

@media (min-width: 640px) {
  .templates-grid.list .template-card {
    flex-direction: row;
    align-items: center;
    gap: 1.5rem;
  }
  .templates-grid.list .card-preview {
    width: 160px;
    height: 160px;
    flex-shrink: 0;
  }
}

/* Template Card */
.template-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-light);
  transition: var(--transition);
  cursor: pointer;
}

.template-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-medium);
}

/* Card Preview Area */
.card-preview {
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  position: relative;
}

.card-badge-group {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.code-badge {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 600;
  color: white;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Favorite Button on Card */
.favorite-icon {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  color: white;
  border: none;
}

.favorite-icon:hover {
  transform: scale(1.1);
  background: rgba(0, 0, 0, 0.7);
}

.favorite-icon.active {
  color: var(--accent);
}

/* Card Content */
.card-content {
  padding: 1.25rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.card-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card Tags */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tag {
  background: var(--bg-elevated);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  color: var(--text-secondary);
}

/* Card Stats */
.card-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.card-stats i {
  margin-right: 0.25rem;
  width: 14px;
}

/* Card Actions */
.card-actions {
  display: flex;
  gap: 0.75rem;
}

.card-btn {
  flex: 1;
  padding: 0.6rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-copy:hover {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.btn-preview-card:hover {
  background: var(--gradient-start);
  color: white;
  border-color: var(--gradient-start);
}

.btn-ai {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
}

.btn-ai:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-2px);
}

/* ---------- Modal ---------- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: var(--bg-surface);
  width: 90%;
  max-width: 500px;
  border-radius: var(--radius-xl);
  overflow: hidden;
  animation: modalSlideIn 0.3s ease;
}

.modal-large {
  max-width: 95%;
  width: 95%;
  height: 90vh;
}

@media (min-width: 1024px) {
  .modal-large {
    max-width: 1400px;
    width: 92%;
    height: 88vh;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .modal-large {
    height: 85vh;
    width: 94%;
  }
}

.modal-header {
  background: linear-gradient(135deg, #0f0f1a, #1a1a2e);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.preview-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.preview-action-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-full);
  color: white;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.preview-action-btn:hover {
  background: var(--accent);
  transform: translateY(-1px);
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
  transition: var(--transition);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 0;
  background: #fff;
}

.modal-large .modal-body {
  padding: 0;
  height: calc(90vh - 60px);
}

@media (min-width: 1024px) {
  .modal-large .modal-body {
    height: calc(88vh - 65px);
  }
}

.preview-frame {
  width: 100%;
  height: 100%;
  border: none;
}

/* Fullscreen mode */
.modal-large.fullscreen {
  width: 100%;
  height: 100%;
  max-width: 100%;
  border-radius: 0;
}

.modal-large.fullscreen .preview-frame {
  height: calc(100vh - 60px);
}

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

/* ---------- Toast Notification ---------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1rem;
  background: var(--success);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 1100;
  opacity: 0;
  transform: translateY(1rem);
  transition: all 0.25s ease;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 768px) {
  .toast {
    right: 1.5rem;
    bottom: 1.5rem;
  }
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- No Results ---------- */
.no-results {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-light);
}

.no-results i {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.no-results h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.no-results p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.reset-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.reset-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
}

/* ---------- Exit Popup ---------- */
.exit-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(12px);
  z-index: 10000;
  display: none;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.exit-overlay.show {
  display: flex;
  opacity: 1;
}

.exit-card {
  background: linear-gradient(135deg, #1a1a2e, #0f0f1a);
  border-radius: var(--radius-xl);
  max-width: 420px;
  width: 90%;
  padding: 2rem 1.5rem;
  text-align: center;
  position: relative;
  border: 1px solid rgba(233, 69, 96, 0.3);
  animation: slideUp 0.3s ease;
}

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

.exit-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: var(--transition);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
}

.exit-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

.exit-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
}

.exit-card h3 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: white;
}

.exit-card p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.exit-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.exit-btn-primary {
  background: var(--accent);
  color: white;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.exit-btn-primary:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
}

.exit-btn-secondary {
  background: transparent;
  color: white;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-medium);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
}

.exit-btn-secondary:hover {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

/* ---------- Footer ---------- */
.footer {
  background: #0f0f1a;
  color: var(--text-muted);
  text-align: center;
  padding: 2rem 1.5rem;
  margin-top: 3rem;
  border-top: 1px solid var(--border-light);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  transition: var(--transition);
}

.footer a:hover {
  text-decoration: underline;
}

/* ---------- AI Modal Styles ---------- */
.ai-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  z-index: 10001;
  display: none;
  justify-content: center;
  align-items: center;
}

.ai-modal {
  background: var(--bg-surface);
  border-radius: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow: auto;
  padding: 2rem;
  position: relative;
  border: 1px solid var(--accent);
}

.ai-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.ai-modal-header h2 {
  font-size: 1.5rem;
  color: var(--accent);
}

.ai-modal-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.ai-modal-close:hover {
  color: var(--accent);
}

.ai-form-group {
  margin-bottom: 1.2rem;
}

.ai-form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.ai-form-group input,
.ai-form-group textarea,
.ai-form-group select {
  width: 100%;
  padding: 0.8rem;
  border: 2px solid var(--border-light);
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.ai-form-group input:focus,
.ai-form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.ai-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.ai-submit-btn {
  width: 100%;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  padding: 1rem;
  border: none;
  border-radius: 40px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 1rem;
}

.ai-submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
}

.ai-preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.ai-preset {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.3s;
}

.ai-preset:hover {
  background: var(--accent);
  color: white;
}

.ai-note {
  margin-top: 1rem;
  padding: 0.8rem;
  background: rgba(233, 69, 96, 0.1);
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Loader Spinner */
.loader-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.5rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Mobile Improvements ---------- */
@media (max-width: 640px) {
  .options-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .options-right {
    justify-content: space-between;
  }
  
  .card-actions {
    flex-wrap: wrap;
  }
  
  .card-btn {
    padding: 0.5rem;
    font-size: 0.7rem;
  }
}

/* ---------- Touch Improvements ---------- */
@media (hover: none) {
  .filter-btn:hover,
  .card-btn:hover,
  .icon-btn:hover,
  .cat-btn:hover {
    transform: none;
  }
  
  .filter-btn:active,
  .card-btn:active,
  .icon-btn:active,
  .cat-btn:active {
    opacity: 0.7;
  }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Preview Modal - FIXED ---------- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal.active {
  display: flex;
  opacity: 1;
}

/* Preview Modal Container */
.modal-content {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  overflow: hidden;
  animation: modalSlideIn 0.3s ease;
  display: flex;
  flex-direction: column;
}

/* Large Preview Modal */
.modal-preview {
  max-width: 95%;
  width: 95%;
  height: 90vh;
}

@media (min-width: 1024px) {
  .modal-preview {
    max-width: 1400px;
    width: 92%;
    height: 88vh;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .modal-preview {
    height: 85vh;
    width: 94%;
  }
}

@media (max-width: 767px) {
  .modal-preview {
    width: 98%;
    height: 80vh;
  }
}

/* Modal Header */
.modal-header {
  background: linear-gradient(135deg, #0f0f1a, #1a1a2e);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

/* Preview Action Buttons */
.preview-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.preview-action-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-full);
  color: white;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.preview-action-btn:hover {
  background: var(--accent);
  transform: translateY(-1px);
}

/* Modal Close Button */
.close-modal {
  background: none;
  border: none;
  color: white;
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
  transition: var(--transition);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
}

.close-modal:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}

/* Modal Body */
.modal-body {
  flex: 1;
  overflow: auto;
  padding: 0;
  background: #fff;
}

/* Preview Iframe */
.preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Fix for modal-preview body */
.modal-preview .modal-body {
  padding: 0;
  height: calc(90vh - 60px);
}

@media (min-width: 1024px) {
  .modal-preview .modal-body {
    height: calc(88vh - 65px);
  }
}

@media (max-width: 767px) {
  .modal-preview .modal-body {
    height: calc(80vh - 60px);
  }
}

/* Fullscreen Mode */
.modal-preview.fullscreen {
  width: 100%;
  height: 100%;
  max-width: 100%;
  border-radius: 0;
}

.modal-preview.fullscreen .modal-body {
  height: calc(100vh - 60px);
}

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

/* Favorites Modal */
#favoritesModal .modal-content {
  max-width: 700px;
  width: 90%;
}

#favoritesModal .modal-body {
  padding: 1.5rem;
  max-height: 70vh;
  overflow-y: auto;
}

.fav-preview, .fav-copy {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.fav-preview:hover, .fav-copy:hover {
  background: var(--accent);
  color: white;
}



/* OpenWidget Chat Customization */
.openwidget-chat-button {
  --ow-primary-color: #e94560 !important;
  --ow-primary-hover-color: #c7354e !important;
}

/* If chat appears in dark mode */
[data-theme="dark"] .openwidget-chat-window {
  --ow-bg-color: #1a1a2a !important;
  --ow-text-color: #ffffff !important;
}


/* Card Preview - Support for images */
.card-preview {
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  height: 180px;
  position: relative;
  overflow: hidden;
}

.card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.template-card:hover .card-preview img {
  transform: scale(1.05);
}