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

:root {
  --primary: #ff6b35;
  --primary-dark: #e55a27;
  --primary-light: #fff3ef;
  --text: #1a1a1a;
  --text-sub: #666;
  --text-light: #999;
  --border: #e8e8e8;
  --bg: #f8f8f8;
  --white: #fff;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --shadow-card: 0 4px 20px rgba(0,0,0,.1);
  --radius: 16px;
  --radius-sm: 10px;
  --header-h: 60px;
}

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 8px rgba(0,0,0,.06);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.3px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:active { background: var(--border); }
.btn-icon svg { width: 22px; height: 22px; }

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== Search Section ===== */
.search-section {
  background: var(--white);
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--border);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0 12px;
  transition: border-color .2s;
}
.search-box:focus-within { border-color: var(--primary); }

.search-icon { width: 18px; height: 18px; color: var(--text-light); flex-shrink: 0; }

#search-input {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 8px;
  font-size: 15px;
  outline: none;
  color: var(--text);
}
#search-input::placeholder { color: var(--text-light); }

.btn-clear {
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-light);
  display: flex;
  align-items: center;
}
.btn-clear svg { width: 16px; height: 16px; }

/* Category Tabs */
.category-tabs-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.category-tabs {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.category-tabs::-webkit-scrollbar { display: none; }

.btn-cat-manage {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-cat-manage:active { background: var(--bg); color: var(--primary); }
.btn-cat-manage svg { width: 16px; height: 16px; }

.tab {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
  font-weight: 600;
}

/* ===== Main Content ===== */
.main-content {
  padding: 16px;
  min-height: calc(100vh - var(--header-h) - 120px);
}

/* ===== Recipe Grid ===== */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (min-width: 600px) {
  .recipe-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .recipe-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Recipe Card */
.recipe-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.recipe-card:active { transform: scale(.97); }

.card-img-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  overflow: hidden;
  position: relative;
}
.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
}

.card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}

.card-body { padding: 10px 12px 12px; }

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.card-chip {
  font-size: 11px;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 3px;
}
.card-chip svg { width: 12px; height: 12px; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-title { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-sub { font-size: 14px; color: var(--text-sub); }

/* ===== Detail View ===== */
.detail-container {
  max-width: 680px;
  margin: 0 auto;
  padding-bottom: 40px;
}

.detail-hero {
  width: 100%;
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  overflow: hidden;
  position: relative;
}
.detail-hero img { width: 100%; height: 100%; object-fit: cover; }
.detail-hero-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 80px;
}

.detail-body { padding: 20px 16px; }

.detail-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 12px;
}

.detail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
}
.detail-chip svg { width: 14px; height: 14px; }

.detail-desc {
  font-size: 15px;
  color: var(--text-sub);
  line-height: 1.7;
  margin-bottom: 24px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.detail-section { margin-bottom: 28px; }

.detail-section-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Ingredients */
.ingredient-list { display: flex; flex-direction: column; gap: 2px; }

.ingredient-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 8px;
  transition: background .1s;
}
.ingredient-item:nth-child(even) { background: var(--bg); }

.ingredient-name { font-size: 15px; color: var(--text); }
.ingredient-amount { font-size: 15px; color: var(--primary); font-weight: 600; }

/* Steps */
.step-list { display: flex; flex-direction: column; gap: 16px; }

.step-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  flex: 1;
  padding-top: 5px;
}

/* Tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }

.tag {
  padding: 5px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-sub);
}

/* Detail Actions */
.detail-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  position: sticky;
  bottom: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
}

.btn-edit {
  flex: 1;
  padding: 13px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--primary);
  background: var(--white);
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-edit:active { background: var(--primary-light); }

.btn-pdf {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--primary);
  background: var(--primary);
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background .15s;
}
.btn-pdf svg { width: 16px; height: 16px; }
.btn-pdf:active { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-delete {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid #ff4444;
  background: var(--white);
  color: #ff4444;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-delete:active { background: #fff5f5; }

/* ===== Form View ===== */
.form-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

.form-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* Photo Area */
.form-photo-area {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  margin-bottom: 20px;
  background: var(--bg);
  transition: border-color .2s;
}
.form-photo-area:active { border-color: var(--primary); }

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-light);
}
.photo-placeholder svg { width: 48px; height: 48px; }
.photo-placeholder span { font-size: 14px; }

.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Form Groups */
.form-group { margin-bottom: 16px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-label.required::after {
  content: '*';
  color: var(--primary);
  margin-left: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color .2s;
  appearance: none;
  -webkit-appearance: none;
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 36px;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* Form Section */
.form-section { margin-bottom: 24px; }

.section-heading {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
}

/* Ingredient Row */
.ingredient-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.ingredient-row .form-input { margin: 0; }
.ingredient-row .input-name { flex: 2; }
.ingredient-row .input-amount { flex: 1; }

/* Step Row */
.step-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-start;
}
.step-row-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 10px;
}
.step-row .form-textarea { flex: 1; margin: 0; min-height: 70px; }

/* Remove Button */
.btn-remove {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: #ff4444;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s;
  margin-top: 8px;
}
.btn-remove:active { background: #fff5f5; }
.btn-remove svg { width: 18px; height: 18px; }

/* Add Item Button */
.btn-add-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-add-item svg { width: 18px; height: 18px; }
.btn-add-item:active { background: #fde8df; }

/* Form Actions */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.btn-cancel {
  flex: 1;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--white);
  color: var(--text-sub);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-save {
  flex: 2;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-save:active { background: var(--primary-dark); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a1a;
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Category Management Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 20px; }
}

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 600px) {
  .modal { border-radius: var(--radius); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 17px; font-weight: 700; }

.modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 16px 20px;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cat-row-emoji { font-size: 22px; flex-shrink: 0; }
.cat-row-label { flex: 1; font-size: 15px; font-weight: 500; }

.modal-add-form {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 2px solid var(--primary);
}

.modal-add-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.modal-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cat-emoji-input { width: 60px; flex-shrink: 0; text-align: center; font-size: 18px; padding: 10px 8px; }

.btn-cat-add {
  flex-shrink: 0;
  padding: 12px 16px;
  font-size: 14px;
  white-space: nowrap;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: var(--white);
  font-weight: 700;
  cursor: pointer;
}
.btn-cat-add:active { background: var(--primary-dark); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
