* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #ff6b6b;
  --primary-dark: #ee5a5a;
  --secondary: #4ecdc4;
  --bg: #f8f9fa;
  --card-bg: #ffffff;
  --text: #333333;
  --text-light: #666666;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-hover: 0 4px 20px rgba(0,0,0,0.12);
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 40px 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.header p {
  opacity: 0.9;
  font-size: 1.1rem;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
}

/* Search Section */
.search-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.search-box {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  padding: 14px 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  transition: all 0.3s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 500;
}

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

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

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

.btn-secondary:hover {
  background: #3dbdb5;
  transform: translateY(-2px);
}

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

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

/* Action Buttons */
.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  align-items: center;
}

.view-toggle {
  display: flex;
  gap: 8px;
  margin-left: auto;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
}

.view-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s;
}

.view-btn.active {
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Menu List View */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-list .menu-card {
  display: flex;
  align-items: stretch;
  min-height: 100px;
}

.menu-list .menu-card-main {
  display: flex;
  flex: 1;
  cursor: pointer;
}

.menu-list .menu-image {
  width: 100px;
  height: auto;
  min-height: 100px;
  flex-shrink: 0;
  font-size: 2.5rem;
}

.menu-list .menu-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 20px;
}

.menu-list .menu-title {
  margin-bottom: 6px;
}

.menu-list .menu-desc {
  -webkit-line-clamp: 1;
  margin-bottom: 8px;
}

.menu-list .menu-tags {
  margin-top: 0;
}

/* Random Generator */
.random-section {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  color: white;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.random-section h3 {
  font-size: 1.2rem;
  margin-right: auto;
}

.random-input {
  width: 80px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  text-align: center;
}

/* Menu Grid */
.section-title {
  font-size: 1.5rem;
  margin-bottom: 20px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title::before {
  content: '';
  width: 4px;
  height: 24px;
  background: var(--primary);
  border-radius: 2px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.menu-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: all 0.3s;
  position: relative;
}

.menu-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.menu-card-main {
  cursor: pointer;
}

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.3s;
}

.menu-card:hover .card-actions {
  opacity: 1;
}

.card-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.card-btn:hover {
  transform: scale(1.1);
}

.card-btn.edit {
  color: var(--secondary);
}

.card-btn.edit:hover {
  background: var(--secondary);
  color: white;
}

.card-btn.delete {
  color: var(--primary);
}

.card-btn.delete:hover {
  background: var(--primary);
  color: white;
}

.menu-image {
  width: 100%;
  height: 180px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
}

.menu-content {
  padding: 20px;
}

.menu-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.menu-desc {
  color: var(--text-light);
  font-size: 0.95rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.menu-tags {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.tag {
  padding: 4px 12px;
  background: var(--bg);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-light);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  padding: 24px 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 600;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s;
}

.modal-close:hover {
  background: var(--primary);
  color: white;
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text);
}

.form-input, .form-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s;
  font-family: inherit;
}

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

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

.form-hint {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 6px;
}

/* Image Upload */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--bg);
}

.image-upload-area:hover {
  border-color: var(--primary);
  background: #fff5f5;
}

.image-upload-area.dragover {
  border-color: var(--primary);
  background: #fff5f5;
  transform: scale(1.02);
}

.upload-placeholder {
  padding: 20px;
}

.upload-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.upload-placeholder p {
  color: var(--text);
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 0.85rem;
  color: var(--text-light);
}

.image-preview {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.image-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.remove-image {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.remove-image:hover {
  background: var(--primary-dark);
  transform: scale(1.1);
}

.ocr-buttons {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ocr-status {
  font-size: 0.9rem;
  color: var(--text-light);
}

.ocr-status.loading::before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

/* JSON Input */
.json-input-area {
  margin-top: 8px;
}

.json-code {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9rem;
  min-height: 150px;
  background: #f8f9fa;
}

.json-buttons {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* JSON Template Modal */
.template-preview {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
  overflow-x: auto;
}

.template-preview pre {
  margin: 0;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #333;
}

.template-preview code {
  color: #d63384;
}

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

/* Detail Page */
.detail-page {
  display: none;
  background: var(--bg);
  min-height: 100vh;
}

.detail-page.active {
  display: block;
}

.detail-header {
  background: var(--card-bg);
  padding: 20px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
}

.detail-back:hover {
  transform: translateX(-4px);
}

.detail-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 30px 20px;
}

.detail-hero {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.detail-icon {
  font-size: 6rem;
  margin-bottom: 20px;
}

.detail-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.detail-desc {
  color: var(--text-light);
  font-size: 1.1rem;
}

.detail-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.detail-section h3 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.ingredients-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.ingredient-item {
  padding: 12px 16px;
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ingredient-item::before {
  content: '•';
  color: var(--primary);
  font-weight: bold;
  font-size: 1.2rem;
}

.steps-list {
  counter-reset: step;
}

.step-item {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.step-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.step-number {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}

.step-content {
  flex: 1;
  padding-top: 6px;
  line-height: 1.7;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
  color: var(--text);
}

/* Home Page */
.home-page {
  display: block;
}

.home-page.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  .header h1 {
    font-size: 1.8rem;
  }

  .search-box {
    flex-direction: column;
  }

  .random-section {
    flex-direction: column;
    text-align: center;
  }

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

  .menu-list .menu-card {
    flex-direction: column;
  }

  .menu-list .menu-card-main {
    flex-direction: column;
  }

  .menu-list .menu-image {
    width: 100%;
    height: 120px;
  }

  .view-toggle {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }

  .detail-hero {
    padding: 28px 20px;
  }

  .detail-title {
    font-size: 1.5rem;
  }

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

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.menu-card {
  animation: fadeIn 0.4s ease-out;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: white;
  padding: 14px 28px;
  border-radius: 8px;
  font-size: 0.95rem;
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* JSON File Upload */
.json-file-upload {
  margin-bottom: 12px;
}

.json-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.json-upload-area:hover {
  border-color: var(--secondary);
  background: #f0f9f9;
}

.json-upload-area.dragover {
  border-color: var(--secondary);
  background: #f0f9f9;
  transform: scale(1.01);
}

.json-upload-icon {
  font-size: 1.5rem;
}

.json-divider {
  text-align: center;
  margin: 16px 0;
  position: relative;
}

.json-divider span {
  background: var(--card-bg);
  padding: 0 12px;
  color: var(--text-light);
  font-size: 0.85rem;
}

.json-divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
  z-index: 0;
}

/* Icon Selector */
.icon-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  max-height: 160px;
  overflow-y: auto;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.icon-option {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
  user-select: none;
}

.icon-option:hover {
  transform: scale(1.1);
  border-color: var(--primary);
  background: #fff5f5;
}

.icon-option.selected {
  border-color: var(--primary);
  background: #fff5f5;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

.icon-random-btn {
  grid-column: 1 / -1;
  padding: 8px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-light);
  cursor: pointer;
  border: 2px dashed var(--border);
  border-radius: 8px;
  transition: all 0.2s;
  background: white;
}

.icon-random-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #fff5f5;
}
