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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  color: #333;
}

.container {
  max-width: 1600px;
  margin: 0 auto;
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

/* Header */
header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 40px;
  text-align: center;
}

header h1 {
  font-size: 48px;
  margin-bottom: 10px;
  font-weight: bold;
}

.subtitle {
  font-size: 18px;
  opacity: 0.9;
}

/* Main Layout */
.main-layout {
  display: grid;
  grid-template-columns: 500px 1fr;
  gap: 30px;
  padding: 40px;
}

@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

/* Controls Panel */
.controls-panel {
  background: #f8f9fa;
  padding: 30px;
  border-radius: 15px;
  height: fit-content;
}

.control-section {
  background: white;
  padding: 25px;
  border-radius: 10px;
  margin-bottom: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.control-section h2 {
  font-size: 20px;
  margin-bottom: 20px;
  color: #667eea;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Form Elements */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #555;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #667eea;
}

.form-group small {
  display: block;
  margin-top: 5px;
  color: #888;
  font-size: 13px;
}

/* Template Cards */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.template-card {
  position: relative;
  cursor: pointer;
  display: block;
}

.template-preview {
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  font-weight: bold;
  margin-bottom: 8px;
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.template-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.template-name {
  display: block;
  text-align: center;
  font-size: 14px;
  color: #666;
  transition: color 0.2s;
}

.template-card input[type="radio"]:checked ~ .template-name {
  color: #667eea;
  font-weight: bold;
}

.template-card input[type="radio"]:checked ~ .template-preview {
  box-shadow: 0 0 0 3px #667eea;
}

/* Search Box */
.search-box {
  display: flex;
  gap: 10px;
}

.search-box input {
  flex: 1;
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  width: 100%;
  padding: 18px;
  font-size: 18px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.action-buttons {
  margin-top: 30px;
}

/* Image Results */
.image-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 15px;
  max-height: 300px;
  overflow-y: auto;
}

.image-item {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid transparent;
  transition: all 0.3s;
  position: relative;
}

.image-item img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.image-item:hover {
  transform: scale(1.05);
  border-color: #667eea;
}

.image-item.selected {
  border-color: #667eea;
  box-shadow: 0 0 0 2px #667eea;
}

.image-loading {
  text-align: center;
  padding: 20px;
  color: #888;
}

/* Preview Panel */
.preview-panel {
  position: sticky;
  top: 20px;
  height: fit-content;
}

.preview-panel h2 {
  font-size: 24px;
  margin-bottom: 20px;
  color: #667eea;
}

.gift-card-preview {
  width: 100%;
  aspect-ratio: 210 / 297; /* A4 default */
  background-image: url('https://images.unsplash.com/photo-1557683316-973673baf926?w=1200');
  background-size: cover;
  background-position: center;
  border-radius: 15px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* padding will be set dynamically by JS */
}

.gift-card-preview::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(2px);
}

.preview-content {
  position: relative;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  /* border, border-radius, padding, box-shadow set dynamically by JS */
  text-align: center;
  width: 100%;
}

.preview-title {
  /* font-size, color, margin-bottom, letter-spacing set dynamically by JS */
  font-weight: bold;
  text-transform: uppercase;
  word-wrap: break-word;
  line-height: 1.2;
}

.preview-message {
  /* font-size, margin-bottom set dynamically by JS */
  color: #333;
  line-height: 1.4;
  font-style: italic;
  word-wrap: break-word;
}

.preview-from {
  /* font-size, margin-top set dynamically by JS */
  color: #666;
  font-weight: normal;
}

.preview-clips {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  /* width set dynamically by JS */
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.95);
  border-left: 3px dashed #999;
  z-index: 20;
}

.preview-clip {
  /* flex set dynamically by JS */
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 2px dashed #999;
  /* font-size, color, border-color set dynamically by JS */
  font-weight: bold;
  text-align: center;
  position: relative;
  background: white;
}

.preview-clip:last-child {
  border-bottom: none;
}

.preview-clip .clip-number {
  transform: rotate(90deg);
  display: block;
}

.preview-hint {
  margin-top: 15px;
  text-align: center;
  color: #888;
  font-size: 14px;
}

/* Footer */
footer {
  background: #2c3e50;
  color: white;
  text-align: center;
  padding: 20px;
}

/* Loading State */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '⏳';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
}
