/* === Design System: Modern Kitchen === */
:root {
  --bg: #FAFAF8;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --text-secondary: #6B6B6B;
  --text-muted: #A0A0A0;
  --accent: #E8633A;
  --accent-hover: #D1441E;
  --green: #4A8C5C;
  --green-bg: #EDF5EF;
  --orange-bg: #FEF4F0;
  --gold: #E8A830;
  --border: #EBEBEB;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 4px 10px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* === Navbar === */
.navbar {
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.3px;
  color: var(--text);
}
.navbar-brand::before { content: "🍳 "; }
.nav-tabs {
  display: flex;
  gap: 2px;
  background: #F5F5F3;
  border-radius: 10px;
  padding: 3px;
}
.nav-tab {
  padding: 7px 16px;
  border-radius: 8px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.nav-tab.active {
  background: white;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.nav-tab:hover:not(.active) { color: var(--text); }

/* === Main === */
.main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.view-title {
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.3px;
  margin-bottom: 2px;
}
.view-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* === Toolbar === */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 180px;
  max-width: 280px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,99,58,0.1); }
.select-input {
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.btn {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--green); color: white; }
.btn-secondary:hover { background: #3D7A4E; }
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover { border-color: #D0D0D0; background: #FAFAFA; }
.btn-danger { background: none; border: 1px solid var(--accent); color: var(--accent); }

/* === Dish Grid === */
.dish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.dish-grid.col3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* === Dish Card === */
.dish-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.dish-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.dish-card-image {
  width: 100%;
  height: 170px;
  background: linear-gradient(135deg, #F5F3F0, #EDEAE6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  position: relative;
  overflow: hidden;
}
.dish-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}
.dish-card-image .image-count {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.45);
  color: white;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  z-index: 1;
  backdrop-filter: blur(4px);
}
.dish-card-body { padding: 14px 16px 16px; }
.dish-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2px;
}
.dish-card-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.2px;
}
.dish-card-rating {
  font-size: 12px;
  color: var(--gold);
  white-space: nowrap;
  margin-top: 2px;
}
.dish-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 6px 0 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.dish-card-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 5px;
  font-weight: 500;
  letter-spacing: 0.1px;
}
.badge-time { background: var(--green-bg); color: var(--green); }
.badge-diff { background: var(--orange-bg); color: var(--accent); }
.badge-tag  { background: #F3F3F3; color: var(--text-secondary); }
.dish-card-last-cooked {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Add Card */
.add-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px dashed #E0E0E0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 270px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.add-card:hover { border-color: var(--accent); color: var(--accent); }
.add-card .plus { font-size: 36px; margin-bottom: 2px; line-height: 1; }
.add-card .txt  { font-size: 13px; font-weight: 500; }

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px 60px;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 100%;
  padding: 24px;
  position: relative;
}
.modal h2 {
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 16px;
  letter-spacing: -0.2px;
}
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background 0.15s;
}
.modal-close:hover { background: #F3F3F3; }

/* Form */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 12px;
  background: #FAFAFA;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-input:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,99,58,0.08);
  background: white;
}
.form-textarea { min-height: 80px; resize: vertical; }

/* Image upload */
.image-upload-area {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.img-thumb {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}
.img-thumb-wrapper {
  position: relative;
  display: inline-block;
}
.img-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.15s;
}
.img-thumb-remove:hover { transform: scale(1.1); }
.upload-placeholder {
  width: 88px;
  height: 88px;
  border: 2px dashed #D0D0D0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.upload-placeholder:hover { border-color: var(--accent); color: var(--accent); }

/* Ingredient rows */
.ingredient-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}
.ingredient-row input { flex: 1; }
.btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s;
}
.btn-remove:hover { color: var(--accent); background: var(--orange-bg); }

/* Stars */
.stars {
  color: var(--gold);
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  gap: 2px;
}
.stars .star-empty { opacity: 0.15; }

/* === Menu View - Category Tiles === */
.category-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.cat-tile {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.cat-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.cat-tile.active {
  border-color: var(--accent);
}
.cat-tile-thumb {
  width: 100%;
  height: 120px;
  background: linear-gradient(135deg, #F5F3F0, #EDEAE6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  position: relative;
  overflow: hidden;
}
.cat-tile-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}
.cat-tile-info {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cat-tile-name {
  font-weight: 600;
  font-size: 14px;
}
.cat-tile-count {
  font-size: 11px;
  color: var(--text-muted);
  background: #F5F5F3;
  padding: 2px 8px;
  border-radius: 10px;
}
.cat-tile.active .cat-tile-count {
  background: var(--orange-bg);
  color: var(--accent);
}
.cat-tile.add-cat {
  border: 2px dashed #E0E0E0;
  background: transparent;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 172px;
  color: var(--text-muted);
}
.cat-tile.add-cat:hover { border-color: var(--accent); color: var(--accent); }
.cat-tile.add-cat .plus { font-size: 32px; margin-bottom: 2px; }
.cat-tile.add-cat .txt { font-size: 12px; }

.menu-dishes-section {
  margin-top: 4px;
}
.menu-dishes-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Weekly Planner === */
.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}
.day-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.day-card.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.day-card.selected {
  border-color: var(--green);
  background: var(--green-bg);
  box-shadow: 0 0 0 1px var(--green);
}
.day-card.today.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green);
}
.day-select {
  text-align: right;
  margin-bottom: -2px;
  cursor: pointer;
  user-select: none;
  line-height: 1;
}
.day-checkbox {
  font-size: 15px;
  color: #D0D0D0;
  transition: color 0.15s;
}
.day-card.selected .day-checkbox { color: var(--green); }
.day-select:hover .day-checkbox { color: var(--green); }
.day-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}
.day-card.today .day-label { color: var(--accent); }
.day-date {
  font-weight: 700;
  font-size: 18px;
  margin: 2px 0 6px;
}
.day-meal {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 5px;
  background: #F5F5F3;
  color: var(--text-secondary);
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.day-meal .remove-meal {
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 11px;
  padding: 0 2px;
  color: var(--text-muted);
}
.day-meal:hover .remove-meal { opacity: 0.6; }
.day-meal.empty { background: transparent; color: #D0D0D0; }
.day-add-btn {
  font-size: 10px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 2px;
}
.day-add-btn:hover { color: var(--accent); background: var(--orange-bg); }

/* Ingredient box */
.ingredient-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.ingredient-box h3 {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 12px;
}
.ingredient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
}
.ingredient-item {
  display: flex;
  justify-content: space-between;
  padding: 9px 14px;
  border-radius: 7px;
  background: #FAFAF8;
  font-size: 13px;
}
.ingredient-item .ing-name { font-weight: 500; }
.ingredient-item .ing-amount { color: var(--accent); font-weight: 600; }

/* Category management */
.cat-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.cat-row input { flex: 1; }

/* Dish picker */
.dish-picker-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 3px;
  transition: background 0.15s;
}
.dish-picker-item:hover { background: #F5F5F3; }

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.7s;
  pointer-events: none;
}
@keyframes toastIn  { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* === Login Overlay === */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  background-image: url('../images/backpic.jpg');
  background-size: cover;
  background-position: center;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.2);
  z-index: 0;
}

.login-card {
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  max-width: 360px;
  width: 100%;
  position: relative;
  z-index: 1;
  text-align: center;
}

.login-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-card h2 {
  font-weight: 700;
  font-size: 22px;
  margin-bottom: 4px;
  letter-spacing: -0.2px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.login-input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(255,255,255,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  outline: none;
  text-align: center;
  letter-spacing: 4px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.login-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,99,58,0.12);
  background: rgba(255,255,255,0.7);
}

.login-input::placeholder {
  letter-spacing: normal;
  color: var(--text-muted);
}

.login-error {
  color: var(--accent);
  font-size: 12px;
  margin-top: 8px;
  font-weight: 500;
}

.login-btn {
  margin-top: 16px;
  width: 100%;
  justify-content: center;
  padding: 11px 16px;
  font-size: 14px;
}

/* ==================== Mobile Responsive ==================== */
@media (max-width: 768px) {
  .navbar {
    padding: 0 12px;
    height: 52px;
  }
  .navbar-brand { font-size: 16px; }
  .nav-tab { padding: 6px 12px; font-size: 12px; }

  .main { padding: 16px 12px 80px; }
  .view-title { font-size: 20px; }

  /* Toolbar stack */
  .toolbar { gap: 6px; }
  .search-input { max-width: 100%; min-width: 0; }
  .toolbar .btn { padding: 8px 12px; font-size: 12px; }

  /* Dish grid 2-1 columns */
  .dish-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .dish-grid.col3 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .dish-card-image { height: 130px; }
  .dish-card-body { padding: 10px 12px 12px; }
  .dish-card-name { font-size: 14px; }
  .add-card { min-height: 200px; }

  /* Category tiles */
  .category-tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cat-tile-thumb { height: 100px; }

  /* Modal full-width */
  .modal { max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; margin-top: auto; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  /* Week planner horizontal scroll */
  .week-strip {
    grid-template-columns: repeat(7, minmax(110px, 1fr));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .day-card { min-width: 110px; min-height: auto; }

  /* Ingredient grid */
  .ingredient-grid { grid-template-columns: repeat(2, 1fr); }

  /* Form fields */
  .form-input, .form-textarea, .form-select { font-size: 16px; } /* prevent iOS zoom */
}

@media (max-width: 480px) {
  .dish-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .dish-grid.col3 { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .dish-card-image { height: 110px; font-size: 36px; }
  .dish-card-name { font-size: 13px; }
  .dish-card-desc { font-size: 11px; }
  .dish-card-tags .badge { font-size: 9px; }
  .category-tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .cat-tile-thumb { height: 85px; font-size: 32px; }
  .ingredient-grid { grid-template-columns: 1fr; }
}
