/* =============================================================================
   WADIFA BUILDER - COMPONENTS STYLESHEET v3.0
   Form Controls, Sections, Accordions, Modals, Toasts, Color Pickers,
   Template Gallery, AI Panel, Photo Upload, Toolbar
============================================================================= */

/* ─────────────────────────────────────────────
   1. SECTION ACCORDION
───────────────────────────────────────────── */
.form-section {
  margin-bottom: var(--space-3);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  overflow: hidden;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-section:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px var(--space-4);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}
.section-header:hover { background: var(--surface-hover); }

.section-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--brand-50);
  color: var(--brand-500);
  flex-shrink: 0;
}
[data-theme="dark"] .section-icon { background: rgba(37,99,235,.15); }

.section-title-wrap { flex: 1; min-width: 0; }
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.section-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-chevron {
  color: var(--text-muted);
  transition: transform var(--transition-mid);
}
.section-header[aria-expanded="true"] .section-chevron { transform: rotate(180deg); }

.section-body {
  padding: 0 var(--space-4) var(--space-4);
  display: grid;
  gap: var(--space-3);
}
.section-body.collapsed { display: none; }

/* ─────────────────────────────────────────────
   2. FORM INPUTS
───────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}
.form-label span.required { color: var(--error); margin-inline-start: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-md);
  background: var(--surface-bg);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
  -webkit-appearance: none;
}
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: var(--surface-border-2); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  background: var(--surface-card);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); font-size: 13px; }

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
[dir="rtl"] .form-select { background-position: left 10px center; padding-right: 12px; padding-left: 30px; }

/* Input with icon */
.input-with-icon { position: relative; }
.input-with-icon .input-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.input-with-icon .input-icon:first-child { left: 10px; }
.input-with-icon .form-input { padding-left: 34px; }
[dir="rtl"] .input-with-icon .input-icon:first-child { left: auto; right: 10px; }
[dir="rtl"] .input-with-icon .form-input { padding-left: 12px; padding-right: 34px; }

/* Range slider */
.form-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-border-2);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}
.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(37,99,235,.2);
  transition: transform var(--transition-fast);
}
.form-range::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* Character counter */
.char-counter {
  font-size: 11px;
  color: var(--text-muted);
  text-align: end;
}
.char-counter.warn { color: var(--warning); }
.char-counter.error { color: var(--error); }

/* ─────────────────────────────────────────────
   3. TEMPLATE GALLERY
───────────────────────────────────────────── */
.tpl-gallery-wrap {
  margin-bottom: var(--space-3);
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.tpl-gallery-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: var(--space-3);
}
.tpl-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
}
.tpl-thumb {
  cursor: pointer;
  border: 2px solid var(--surface-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition-fast);
  position: relative;
  aspect-ratio: 7/10;
  background: var(--surface-bg);
}
.tpl-thumb:hover { border-color: var(--brand-500); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.tpl-thumb.active {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 1px var(--brand-500), var(--shadow-brand);
}
.tpl-thumb-preview {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 8px;
  font-size: 4px;
  overflow: hidden;
}
.tpl-thumb-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  background: var(--brand-500);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  display: none;
}
.tpl-thumb.active .tpl-thumb-badge { display: block; }
.tpl-thumb-name {
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 4px;
  border-top: 1px solid var(--surface-border);
  background: var(--surface-card);
}
.tpl-thumb.active .tpl-thumb-name { color: var(--brand-500); }

/* ─────────────────────────────────────────────
   4. CUSTOMIZATION CONTROLS
───────────────────────────────────────────── */
.customize-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.customize-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.customize-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Color Swatches */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.color-swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
  position: relative;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--surface-card), 0 0 0 4px currentColor;
}

/* Font selector */
.font-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.font-pill {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--surface-border);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.font-pill:hover { border-color: var(--brand-500); color: var(--brand-500); }
.font-pill.active { border-color: var(--brand-500); background: var(--brand-50); color: var(--brand-500); font-weight: 600; }
[data-theme="dark"] .font-pill.active { background: rgba(37,99,235,.15); }

/* Zoom controls */
.zoom-control-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-card);
  border-bottom: 1px solid var(--surface-border);
}
.zoom-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.zoom-btn-group { display: flex; gap: 3px; }
.zoom-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-border);
  background: var(--surface-card);
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.zoom-btn:hover { background: var(--surface-hover); }
.zoom-btn.active { background: var(--brand-500); color: #fff; border-color: var(--brand-500); }
.zoom-value { font-size: 12px; font-weight: 600; color: var(--text-secondary); min-width: 36px; text-align: center; }

/* ─────────────────────────────────────────────
   5. PHOTO UPLOAD
───────────────────────────────────────────── */
.photo-upload-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 120px;
  border: 2px dashed var(--surface-border-2);
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  overflow: hidden;
  text-align: center;
  padding: var(--space-4);
}
.photo-upload-zone:hover { border-color: var(--brand-500); background: var(--brand-50); }
.photo-upload-zone.dragging { border-color: var(--brand-500); background: var(--brand-50); box-shadow: var(--shadow-brand); }
.photo-upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-upload-icon { color: var(--brand-500); }
.photo-upload-text { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.photo-upload-hint { font-size: 11px; color: var(--text-muted); }

.photo-preview-wrap {
  position: relative;
  display: inline-block;
  width: 80px; height: 80px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--surface-border);
}
.photo-preview-wrap img { width: 100%; height: 100%; object-fit: cover; }
.photo-remove-btn {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(239,68,68,.9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  transition: all var(--transition-fast);
}
.photo-remove-btn:hover { transform: scale(1.1); }

/* ─────────────────────────────────────────────
   6. REPEATER (Skills, Experience, Education)
───────────────────────────────────────────── */
.repeater-list { display: flex; flex-direction: column; gap: var(--space-2); }

.repeater-item {
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}
.repeater-item:focus-within { border-color: var(--brand-500); }

.repeater-item-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px var(--space-3);
  background: var(--surface-muted);
  cursor: pointer;
}
.repeater-drag-handle {
  color: var(--text-muted);
  cursor: grab;
  touch-action: none;
}
.repeater-item-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.repeater-item-actions { display: flex; gap: 4px; }
.repeater-btn-sm {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.repeater-btn-sm:hover { background: var(--surface-border); color: var(--text-primary); }
.repeater-btn-sm.danger:hover { background: rgba(239,68,68,.1); color: var(--error); }
.repeater-chevron { transition: transform var(--transition-fast); color: var(--text-muted); }
.repeater-item.collapsed .repeater-chevron { transform: rotate(-90deg); }

.repeater-item-body { padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.repeater-item.collapsed .repeater-item-body { display: none; }

.btn-add-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--surface-border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition-fast);
}
.btn-add-item:hover { border-color: var(--brand-500); color: var(--brand-500); background: var(--brand-50); }

/* Rating stars */
.star-rating {
  display: flex;
  gap: 3px;
}
.star-btn {
  color: var(--surface-border-2);
  transition: color var(--transition-fast);
  font-size: 18px;
  line-height: 1;
}
.star-btn.filled, .star-btn:hover { color: var(--warning); }

/* Progress bar for skills */
.skill-bar {
  display: flex;
  gap: var(--space-1);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-border);
}
.skill-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--brand-500);
  transition: width var(--transition-spring);
}

/* ─────────────────────────────────────────────
   7. AI ASSISTANT PANEL
───────────────────────────────────────────── */
.ai-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: var(--space-4);
  backdrop-filter: blur(4px);
}
.ai-panel-overlay.open { display: flex; }

.ai-panel {
  width: 420px;
  max-height: 80vh;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-up var(--transition-slow) both;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--surface-border);
  background: linear-gradient(135deg, rgba(124,58,237,.08) 0%, rgba(37,99,235,.08) 100%);
}
.ai-panel-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.ai-panel-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.ai-panel-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.ai-panel-close {
  margin-inline-start: auto;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-hover);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.ai-panel-close:hover { background: var(--error); color: #fff; }

.ai-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.ai-prompt-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.ai-chip {
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--surface-border);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.ai-chip:hover { border-color: var(--brand-500); color: var(--brand-500); background: var(--brand-50); }

.ai-input-wrap {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--surface-border);
}
.ai-input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  background: var(--surface-bg);
  color: var(--text-primary);
  transition: border-color var(--transition-fast);
}
.ai-input:focus { outline: none; border-color: var(--brand-500); }
.ai-send-btn {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  background: var(--brand-500);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.ai-send-btn:hover { background: var(--brand-600); }

.ai-msg {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.6;
  max-width: 90%;
}
.ai-msg.assistant {
  background: linear-gradient(135deg, rgba(124,58,237,.08), rgba(37,99,235,.08));
  border: 1px solid rgba(124,58,237,.15);
  align-self: flex-start;
}
.ai-msg.user {
  background: var(--brand-500);
  color: #fff;
  align-self: flex-end;
}
.ai-msg.loading { display: flex; gap: 5px; align-items: center; }
.ai-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--brand-500);
  animation: ai-bounce 1.2s ease-in-out infinite;
}
.ai-dot:nth-child(2) { animation-delay: .2s; }
.ai-dot:nth-child(3) { animation-delay: .4s; }
@keyframes ai-bounce { 0%, 80%, 100% { transform: scale(0.6); } 40% { transform: scale(1); } }

/* ─────────────────────────────────────────────
   8. TOAST NOTIFICATIONS
───────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 500;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  pointer-events: none;
}
[dir="rtl"] .toast-container { right: auto; left: var(--space-5); }

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 360px;
  padding: 12px 16px;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
  animation: fade-in var(--transition-mid) both;
  transition: opacity var(--transition-mid), transform var(--transition-mid);
}
.toast.exiting { opacity: 0; transform: translateX(12px); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-text { flex: 1; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--error);   }
.toast.info    { border-left: 3px solid var(--info);    }
.toast.warning { border-left: 3px solid var(--warning); }
[dir="rtl"] .toast.success { border-left: none; border-right: 3px solid var(--success); }

/* ─────────────────────────────────────────────
   9. MODAL
───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; }

.modal-box {
  width: 100%;
  max-width: 480px;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: slide-up var(--transition-slow) both;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--surface-border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--surface-hover);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--error); color: #fff; }
.modal-body { padding: var(--space-5); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--surface-border);
}

/* Button variants */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  background: var(--brand-500);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-primary:hover { background: var(--brand-600); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  background: var(--surface-hover);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  border: 1.5px solid var(--surface-border);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-secondary:hover { background: var(--surface-muted); border-color: var(--surface-border-2); }

/* Progress loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ─────────────────────────────────────────────
   10. TOOLTIP
───────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--text-primary);
  color: var(--surface-card);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 99;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ─────────────────────────────────────────────
   11. CANVA-STYLE TEMPLATE GALLERY COMPONENT
───────────────────────────────────────────── */
.template-gallery-container {
  padding: 16px;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.gallery-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.gallery-count {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--brand-500);
  background: var(--brand-50);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
[data-theme="dark"] .gallery-count { background: rgba(37,99,235,0.18); }

.gallery-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.template-card {
  position: relative;
  background: var(--surface-bg);
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.template-card:hover {
  border-color: var(--brand-500);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.template-card.active {
  border-color: var(--brand-500);
  background: var(--surface-hover);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.25);
}

.card-preview-mini {
  position: relative;
  height: 90px;
  background: var(--surface-card);
  border-top: 3.5px solid var(--brand-500);
  border-radius: 4px;
  padding: 6px;
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 8px;
}

.mini-paper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0.85;
}

.mini-line {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-border-2);
}

.mini-line.header-line {
  height: 8px;
  width: 60%;
  margin-bottom: 4px;
}

.mini-line.body-line {
  width: 90%;
}

.mini-line.body-line.short {
  width: 50%;
}

.template-badge {
  position: absolute;
  top: 4px;
  inset-inline-start: 4px;
  color: #ffffff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.03em;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.active-check-icon {
  position: absolute;
  bottom: 4px;
  inset-inline-end: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand-500);
  color: #ffffff;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-card-info {
  text-align: center;
}

.template-name-ar {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.template-name-en {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

