* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: system-ui, sans-serif; background: #f5f0eb; color: #333; min-height: 100vh; }
.hidden { display: none !important; }

/* Login */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.1); width: 90%; max-width: 360px; text-align: center; }
.login-box h1 { margin-bottom: 1.5rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.7rem; }
.login-box input { padding: 0.7rem; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; }
.login-box button { padding: 0.7rem; border: none; border-radius: 6px; font-size: 1rem; cursor: pointer; }
#login-btn { background: #e8632b; color: white; }
#register-btn { background: #eee; }
.login-error { color: #c33; font-size: 0.9rem; min-height: 1.2em; }

header { background: #e8632b; color: white; padding: 1.2rem 1.5rem 0; text-align: center; }
header h1 { margin-bottom: 0.5rem; }
.header-row { display: flex; justify-content: center; align-items: center; gap: 1.5rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.family-setting { display: flex; align-items: center; gap: 0.5rem; }
.family-setting label { font-size: 0.95rem; }
.family-setting input { width: 60px; padding: 0.3rem 0.5rem; border: none; border-radius: 6px; font-size: 1rem; text-align: center; }
.user-info { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95rem; }
.lang-switch { display: flex; gap: 0.3rem; }
.lang-btn { background: none; border: 2px solid transparent; border-radius: 4px; font-size: 1.3rem; cursor: pointer; padding: 0.1rem 0.3rem; opacity: 0.5; transition: opacity 0.2s; }
.lang-btn.active { opacity: 1; border-color: white; }
.login-box .lang-switch { justify-content: center; margin-bottom: 0.5rem; }
.login-box .lang-btn.active { border-color: #e8632b; }
#logout-btn { padding: 0.3rem 0.8rem; background: rgba(255,255,255,0.2); color: white; border: 1px solid rgba(255,255,255,0.4); border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
#export-btn, #import-btn { background: none; border: 1px solid rgba(255,255,255,0.4); border-radius: 6px; cursor: pointer; font-size: 1rem; padding: 0.2rem 0.5rem; }
nav { display: flex; gap: 0; justify-content: center; flex-wrap: wrap; }
.tab { padding: 0.6rem 1.2rem; border: none; background: rgba(255,255,255,0.2); color: white; cursor: pointer; font-size: 0.95rem; border-radius: 8px 8px 0 0; }
.tab.active { background: #f5f0eb; color: #333; }

.page { display: none; max-width: 800px; margin: 0 auto; padding: 1.5rem; }
.page.active { display: block; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }

.add-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.add-row input { flex: 1; padding: 0.6rem; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; min-width: 100px; }
.add-row input[type="date"] { flex: 0.7; }
.add-row button, #add-recipe-btn, #generate-btn, #copy-shopping-btn {
  padding: 0.6rem 1.2rem; background: #e8632b; color: white;
  border: none; border-radius: 6px; cursor: pointer; font-size: 1rem; white-space: nowrap;
}
#copy-shopping-btn { background: #555; }

.item-list { list-style: none; }
.item-list li {
  display: flex; justify-content: space-between; align-items: center;
  background: white; padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.item-list .qty { color: #888; margin-left: 0.5rem; }
.item-list .expiry { color: #888; margin-left: 0.5rem; font-size: 0.85rem; }
.item-list .expiry.expiring-soon { color: #e8632b; font-weight: 600; }
.item-list .expiry.expired { color: #c33; font-weight: 600; }
.item-list .del-btn { background: none; border: none; color: #c33; cursor: pointer; font-size: 1.2rem; }
.item-list .edit-inv-btn { background: none; border: none; cursor: pointer; font-size: 1rem; }

/* Search & filter */
.search-filter-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.search-filter-row input { flex: 1; padding: 0.6rem; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; }
.search-filter-row select { padding: 0.6rem; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; }

/* Recipe grid */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.recipe-card { position: relative; background: white; border-radius: 10px; padding: 1rem; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1); transition: transform 0.2s; }
.recipe-card:hover { transform: translateY(-3px); }
.card-img { width: 100%; height: 140px; object-fit: cover; border-radius: 8px; margin-bottom: 0.5rem; }
.card-img-missing { width: 100%; height: 140px; border-radius: 8px; margin-bottom: 0.5rem; background: #eee; display: flex; align-items: center; justify-content: center; color: #aaa; font-size: 0.9rem; }
.recipe-card h3 { margin-bottom: 0.3rem; padding-right: 2.5rem; }
.want-week { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: #555; cursor: pointer; margin-bottom: 0.3rem; }
.want-week input { width: 15px; height: 15px; cursor: pointer; }
.want-week input:checked + span, .want-week:has(input:checked) { color: #e8632b; font-weight: 600; }
.recipe-card .meta { color: #888; font-size: 0.85rem; }
.card-actions { position: absolute; top: 0.5rem; right: 0.5rem; display: flex; gap: 0.3rem; }
.card-actions .fav-btn { opacity: 1; }
.card-actions .del-recipe { opacity: 0; transition: opacity 0.2s; }
.recipe-card:hover .card-actions .del-recipe { opacity: 1; }
.card-actions button { background: none; border: none; cursor: pointer; font-size: 1.1rem; }
.del-recipe { color: #c33; }
.fav-btn { font-size: 1.2rem !important; opacity: 1 !important; }
.fav-btn.active { opacity: 1 !important; }
.match-bar { height: 6px; border-radius: 3px; background: #eee; margin-top: 0.5rem; }
.match-bar .fill { height: 100%; border-radius: 3px; background: #4caf50; }
.tag { display: inline-block; background: #fde8db; color: #e8632b; padding: 0.1rem 0.5rem; border-radius: 12px; font-size: 0.75rem; }

/* Modals */
dialog { border: none; border-radius: 12px; padding: 1.5rem; max-width: 500px; width: 90%; box-shadow: 0 4px 20px rgba(0,0,0,0.2); }
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog form { display: flex; flex-direction: column; gap: 0.7rem; }
dialog input, dialog select, dialog textarea { padding: 0.6rem; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; font-family: inherit; }
dialog textarea { min-height: 70px; resize: vertical; }
.modal-actions, .detail-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; flex-wrap: wrap; }
.modal-actions button, .detail-actions button, .cancel-btn { padding: 0.5rem 1.2rem; border: none; border-radius: 6px; cursor: pointer; font-size: 1rem; }
.modal-actions button[type="submit"] { background: #e8632b; color: white; }
.cancel-btn { background: #ddd; }
#detail-edit-btn { background: #e8632b; color: white; }
#detail-cook-btn { background: #4caf50; color: white; }

/* Planner */
.hint { color: #888; margin-bottom: 1rem; }
.week-table { width: 100%; border-collapse: collapse; background: white; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,0.1); margin-bottom: 1.5rem; }
.week-table th, .week-table td { padding: 0.6rem 0.8rem; text-align: center; border-bottom: 1px solid #eee; }
.week-table th { background: #e8632b; color: white; font-size: 0.85rem; }
.week-table td:first-child { text-align: left; font-weight: 600; }
.week-table input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
#plan-result { margin-bottom: 1.5rem; }
.day-block { margin-bottom: 1.5rem; }
.day-block h3 { margin-bottom: 0.5rem; color: #e8632b; }
.day-meals { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.meal-card { background: white; border-radius: 10px; padding: 0.8rem 1rem; box-shadow: 0 2px 6px rgba(0,0,0,0.1); flex: 1; min-width: 200px; position: relative; }
.swap-meal { position: absolute; top: 0.5rem; right: 0.5rem; background: none; border: none; cursor: pointer; font-size: 1.1rem; opacity: 0.5; }
.swap-meal:hover { opacity: 1; }
.swap-drop { position: absolute; top: 2.2rem; right: 0.5rem; background: white; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 20; width: 240px; }
.swap-search { width: 100%; padding: 0.5rem; border: none; border-bottom: 1px solid #eee; border-radius: 8px 8px 0 0; font-size: 0.9rem; box-sizing: border-box; outline: none; }
.swap-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; }
.swap-list li { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.85rem; }
.swap-list li:hover { background: #fff3e0; }
.meal-card h4 { margin-bottom: 0.2rem; }
.meal-card .meal-type { text-transform: capitalize; font-size: 0.75rem; color: #e8632b; font-weight: 600; }
.missing { color: #c33; font-size: 0.85rem; margin-top: 0.5rem; }
.have { color: #4caf50; font-size: 0.85rem; }
#shopping-list-wrap { background: white; border-radius: 10px; padding: 1.5rem; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
#shopping-list-wrap h3 { margin-bottom: 0.8rem; }
.shop-aisle { font-weight: 700; color: #e8632b; padding: 0.5rem 0 0.2rem; font-size: 0.9rem; border-bottom: 1px solid #eee; margin-top: 0.5rem; }

#detail-content h2 { margin-bottom: 0.5rem; }
#detail-content h4 { margin: 1rem 0 0.3rem; }
#detail-content ul, #detail-content ol { padding-left: 1.2rem; }
#detail-content li { margin-bottom: 0.2rem; }
.empty { text-align: center; color: #aaa; padding: 2rem; }

/* Diet profile */
.diet-group { background: white; border-radius: 10px; padding: 1rem 1.2rem; margin-bottom: 1rem; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.diet-group h3 { margin-bottom: 0.6rem; font-size: 0.95rem; color: #e8632b; }
.diet-group label { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; cursor: pointer; }
.diet-group input[type="checkbox"] { width: 16px; height: 16px; }
.diet-warning { display: inline-block; background: #fff3cd; color: #856404; padding: 0.1rem 0.5rem; border-radius: 12px; font-size: 0.7rem; margin-left: 0.3rem; }
.diet-block { display: inline-block; background: #f8d7da; color: #721c24; padding: 0.1rem 0.5rem; border-radius: 12px; font-size: 0.7rem; margin-left: 0.3rem; }

/* History */
.history-date { color: #888; font-size: 0.85rem; }
.history-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.4rem; }
.history-cal .cal-head { font-weight: 700; text-align: center; font-size: 0.8rem; color: #e8632b; padding: 0.3rem; }
.history-cal .cal-day { background: white; border-radius: 8px; padding: 0.4rem; min-height: 60px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.history-cal .cal-day .cal-date { font-size: 0.75rem; color: #888; margin-bottom: 0.2rem; }
.history-cal .cal-day .cal-meal { font-size: 0.75rem; padding: 0.1rem 0.3rem; border-radius: 4px; margin-bottom: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-cal .cal-meal.cooked { background: #e8f5e9; color: #2e7d32; }
.history-cal .cal-meal.planned { background: #fff3e0; color: #e65100; }
.history-cal .cal-day.today { border: 2px solid #e8632b; }
.cal-nav { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 0.8rem; }
.cal-nav button { background: none; border: 1px solid #ddd; border-radius: 6px; padding: 0.3rem 0.7rem; cursor: pointer; }
.cal-nav span { font-weight: 600; }
.toast { position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%); background: #333; color: white; padding: 0.8rem 1.5rem; border-radius: 8px; z-index: 999; animation: fadeout 2s 1s forwards; }
@keyframes fadeout { to { opacity: 0; } }

/* Rating */
.rating-row { margin-top: 0.5rem; display: flex; align-items: center; gap: 0.3rem; }
.stars button { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: 0; }
.recipe-card .rating { font-size: 0.8rem; color: #e8632b; }
.price-tag { color: #2e7d32 !important; font-weight: 600; }

/* Budget */
.budget-bar { background: white; border-radius: 8px; padding: 0.6rem 1rem; margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); font-size: 0.9rem; color: #555; }

/* Shared inventory */
.shared-toggle { font-size: 0.85rem; display: flex; align-items: center; gap: 0.3rem; cursor: pointer; color: #555; }
.shared-toggle input { width: 16px; height: 16px; }

/* Quick-add buttons */
.quick-add { margin-bottom: 1rem; }
.quick-cat { margin-bottom: 0.6rem; }
.quick-cat h4 { font-size: 0.85rem; color: #e8632b; margin-bottom: 0.3rem; }
.quick-btns { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.quick-btns button { padding: 0.35rem 0.7rem; border: 1px solid #ddd; border-radius: 16px; background: white; cursor: pointer; font-size: 0.85rem; transition: background 0.15s; }
.quick-btns button:hover { background: #fde8db; }
.quick-btns button.added { background: #4caf50; color: white; border-color: #4caf50; }

/* Double batch */
#detail-double-btn { background: #ff9800; color: white; }
.portions-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }
.portion-btn { width: 32px; height: 32px; border: 1px solid #ccc; border-radius: 50%; background: white; font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.portion-btn:hover { background: #fde8db; }
#browse-library-btn { padding: 0.6rem 1.2rem; background: #555; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 1rem; }
#library-modal { max-width: 600px; }
.del-shop { background: none; border: none; color: #c33; cursor: pointer; font-size: 0.9rem; margin-left: 0.5rem; }
.add-shop-row { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.add-shop-row input { flex: 1; padding: 0.4rem; border: 1px solid #ccc; border-radius: 6px; }
.add-shop-row button { padding: 0.4rem 0.8rem; border: none; border-radius: 6px; background: #4caf50; color: white; cursor: pointer; font-size: 1rem; }

/* Meal prep indicator */
.prep-badge { display: inline-block; background: #e3f2fd; color: #1565c0; padding: 0.1rem 0.5rem; border-radius: 12px; font-size: 0.7rem; margin-left: 0.3rem; }

/* Thumbs */
.thumb-row { margin-top: 0.3rem; }
.thumb-row button { background: none; border: none; font-size: 1rem; cursor: pointer; opacity: 0.4; }
.thumb-row button.active { opacity: 1; }

/* Leftovers */
.leftover-badge { display: inline-block; background: #fff3e0; color: #e65100; padding: 0.1rem 0.5rem; border-radius: 12px; font-size: 0.7rem; }

/* Mobile responsive */
@media (max-width: 600px) {
  header { padding: 0.8rem 1rem 0; }
  header h1 { font-size: 1.3rem; }
  .header-row { gap: 0.8rem; }
  .tab { padding: 0.5rem 0.7rem; font-size: 0.8rem; }
  .page { padding: 1rem; }
  .section-header { flex-direction: column; align-items: flex-start; }
  .add-row { flex-direction: column; }
  .add-row input { min-width: 0; }
  .recipe-grid { grid-template-columns: 1fr; }
  .recipe-card .card-actions .del-recipe { opacity: 1; }
  .week-table { font-size: 0.75rem; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .week-table th, .week-table td { padding: 0.4rem; white-space: nowrap; }
  .day-meals { flex-direction: column; }
  .meal-card { min-width: 0; }
  .detail-actions { flex-direction: column; }
  .detail-actions button { width: 100%; }
  .search-filter-row { flex-direction: column; }
  .diet-group { padding: 0.8rem; }
  .history-cal { grid-template-columns: repeat(7, 1fr); font-size: 0.7rem; }
  .history-cal .cal-day { min-height: 45px; padding: 0.3rem; }
}
