/**
 * REAL AI Framework - Enhanced Template Manager Styles
 * Database-driven template management with improved UI/UX
 * Mobile-first responsive design
 */

.enhanced-template-manager {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

/* Mobile Responsive */
@media (min-width: 768px) {
  .enhanced-template-manager {
    padding: 2rem;
  }
}

.template-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--primary-green);
}

.template-title h2 {
  font-size: 1.8rem;
  color: var(--primary-navy);
  margin: 0 0 0.5rem 0;
  font-weight: 700;
}

.template-title p {
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0;
}

.template-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: stretch;
}

/* Tablet and Desktop */
@media (min-width: 768px) {
  .template-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  
  .template-title h2 {
    font-size: 2.5rem;
  }
  
  .template-title p {
    font-size: 1.1rem;
  }
  
  .template-controls {
    flex-direction: row;
    align-items: center;
  }
}

.view-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.view-btn {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--primary-green);
  background: transparent;
  color: var(--primary-green);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
  min-width: 80px;
  text-align: center;
}

/* Mobile tap targets */
@media (max-width: 767px) {
  .view-btn {
    min-height: 44px;
    flex: 1;
    min-width: 120px;
  }
}

/* Tablet and Desktop */
@media (min-width: 768px) {
  .view-controls {
    justify-content: flex-start;
  }
  
  .view-btn {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    min-width: auto;
  }
}

.view-btn:hover {
  background: var(--primary-green);
  color: white;
  transform: translateY(-2px);
}

.view-btn.active {
  background: var(--primary-green);
  color: white;
}

.filter-controls select {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: white;
  color: var(--text-dark);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.3s ease;
}

.filter-controls select:focus {
  outline: none;
  border-color: var(--primary-green);
}

/* Template Grid Layout */
.template-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 2rem;
}

.template-grid.grid {
  grid-template-columns: 1fr;
}

.template-grid.list {
  grid-template-columns: 1fr;
}

/* Mobile Responsive Grid */
@media (min-width: 768px) {
  .template-grid {
    gap: 2rem;
  }
  
  .template-grid.grid {
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  }
}

.template-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(10, 37, 64, 0.1);
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.template-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 8px 40px rgba(10, 37, 64, 0.15);
}

.template-card.enhanced {
  position: relative;
}

.template-preview {
  position: relative;
  height: 200px;
  background: linear-gradient(135deg, var(--primary-navy) 0%, var(--primary-green) 100%);
  overflow: hidden;
}

.template-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  z-index: 2;
}

.complexity-badge {
  background: rgba(255, 255, 255, 0.9);
  color: var(--primary-navy);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.complexity-badge.level-1 { background: rgba(76, 175, 80, 0.9); color: white; }
.complexity-badge.level-2 { background: rgba(139, 195, 74, 0.9); color: white; }
.complexity-badge.level-3 { background: rgba(255, 193, 7, 0.9); color: white; }
.complexity-badge.level-4 { background: rgba(255, 152, 0, 0.9); color: white; }
.complexity-badge.level-5 { background: rgba(244, 67, 54, 0.9); color: white; }

.type-badge {
  background: var(--accent-gold);
  color: var(--primary-navy);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
}

.type-badge.fillable {
  background: var(--primary-green);
  color: white;
}

.type-badge.printable {
  background: var(--accent-gold);
  color: var(--primary-navy);
}

.template-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.3;
}

.template-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.template-content {
  padding: 1.5rem;
}

.template-header h3 {
  font-size: 1.4rem;
  color: var(--primary-navy);
  margin: 0 0 0.5rem 0;
  font-weight: 700;
}

.template-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Mobile Responsive Meta */
@media (min-width: 768px) {
  .template-meta {
    gap: 1rem;
  }
}

.template-meta span {
  background: var(--bg-light);
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.85rem;
}

.template-description {
  margin-bottom: 1.5rem;
}

.template-description p {
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

.template-details {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-light);
  border-radius: 12px;
}

/* Mobile Responsive Details */
@media (min-width: 768px) {
  .template-details {
    flex-direction: row;
    gap: 1rem;
  }
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.detail-item i {
  color: var(--primary-green);
}

.template-fields-preview {
  margin-bottom: 1.5rem;
}

.template-fields-preview h4 {
  font-size: 1rem;
  color: var(--primary-navy);
  margin: 0 0 0.75rem 0;
}

.field-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.field-group {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.group-name {
  font-weight: 600;
  color: var(--primary-navy);
  font-size: 0.85rem;
}

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

.template-skills {
  margin-bottom: 1.5rem;
}

.template-skills h4 {
  font-size: 1rem;
  color: var(--primary-navy);
  margin: 0 0 0.75rem 0;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.skill-tag {
  background: var(--primary-green);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 16px;
  font-size: 0.75rem;
  font-weight: 500;
}

.template-actions {
  display: flex;
  gap: 1rem;
}

.template-actions .btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  transition: all 0.3s ease;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary-green);
  color: white;
}

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

.btn-secondary {
  background: transparent;
  color: var(--primary-green);
  border: 2px solid var(--primary-green);
}

.btn-secondary:hover {
  background: var(--primary-green);
  color: white;
}

/* Template Stats */
.template-stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  padding: 2rem;
  background: var(--bg-light);
  border-radius: 16px;
  margin-top: 2rem;
}

.stats-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stats-item i {
  color: var(--primary-green);
  font-size: 1.2rem;
}

/* Loading and Error States */
.loading-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--primary-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.error-state i {
  font-size: 3rem;
  color: var(--error-color);
  margin-bottom: 1rem;
}

.no-templates {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.no-templates i {
  font-size: 3rem;
  margin-bottom: 1rem;
  color: var(--primary-green);
}

/* Template Modal */
.template-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 800px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  color: var(--primary-navy);
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.5rem;
}

.close-btn:hover {
  color: var(--primary-navy);
}

.modal-body {
  padding: 1.5rem;
}

/* Template Form */
.template-form {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.form-group {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  background: var(--bg-light);
}

.group-title {
  margin: 0 0 1rem 0;
  color: var(--primary-navy);
  font-size: 1.2rem;
  font-weight: 600;
}

.form-field {
  margin-bottom: 1.5rem;
}

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

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--primary-green);
}

.form-field textarea {
  resize: vertical;
  min-height: 100px;
}

.help-text {
  display: block;
  margin-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.form-actions {
  display: flex;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Notifications */
.notification {
  position: fixed;
  top: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  z-index: 1001;
  animation: slideIn 0.3s ease;
}

.notification.success {
  background: var(--success-color);
}

.notification.error {
  background: var(--error-color);
}

.notification.info {
  background: var(--primary-green);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .enhanced-template-manager {
    padding: 1rem;
  }
  
  .template-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }
  
  .template-controls {
    flex-direction: column;
    gap: 1rem;
    width: 100%;
  }
  
  .template-grid.grid {
    grid-template-columns: 1fr;
  }
  
  .template-details {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .template-actions {
    flex-direction: column;
  }
  
  .template-stats {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .form-actions {
    flex-direction: column;
  }
  
  .modal-content {
    width: 95%;
    margin: 1rem;
  }
}

/* List View Specific Styles */
.template-grid.list .template-card {
  display: flex;
  flex-direction: row;
  height: 200px;
}

.template-grid.list .template-preview {
  width: 300px;
  height: 100%;
  flex-shrink: 0;
}

.template-grid.list .template-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.template-grid.list .template-fields-preview,
.template-grid.list .template-skills {
  display: none;
}

.template-grid.list .template-actions {
  margin-top: auto;
}

@media (max-width: 768px) {
  .template-grid.list .template-card {
    flex-direction: column;
    height: auto;
  }
  
  .template-grid.list .template-preview {
    width: 100%;
    height: 200px;
  }
}