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

:root {
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-text: #2c2420;
  --color-text-light: #6b5e54;
  --color-primary: #c0623a;
  --color-primary-hover: #a8522e;
  --color-accent: #e8d5c4;
  --color-border: #e0d6cc;
  --color-danger: #b5382a;
  --color-star: #d4a017;
  --color-tag-bg: #f0e6da;
  --color-tag-text: #7a5c3e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(44, 36, 32, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 960px; margin: 0 auto; padding: 0 1rem; width: 100%; }

/* === Navbar === */
.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: .75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; }
.nav-brand { font-size: 1.25rem; font-weight: 700; color: var(--color-primary); }
.nav-brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 1.25rem; }
.nav-links a { color: var(--color-text-light); font-weight: 500; }
.nav-links a:hover { color: var(--color-primary); text-decoration: none; }

/* === Footer === */
.site-footer {
  margin-top: auto;
  padding: 1.5rem 0;
  text-align: center;
  font-size: .85rem;
  color: var(--color-text-light);
  border-top: 1px solid var(--color-border);
}
.footer-subtle { opacity: .6; margin-top: .25rem; }

/* === Buttons === */
.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  line-height: 1.4;
  transition: background .15s;
  font-family: var(--font);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-accent); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-border); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #952018; }
.btn-small { padding: .3rem .6rem; font-size: .8rem; }
.btn-large { padding: .65rem 1.5rem; font-size: 1rem; min-height: 44px; }

/* === Forms & Inputs === */
.input {
  display: block;
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--color-surface);
  color: var(--color-text);
  min-height: 44px;
}
.input:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }
textarea.input { resize: vertical; }
select.input { cursor: pointer; }

.form-group { margin-bottom: 1rem; }
.form-group label, .form-group legend {
  display: block;
  font-weight: 600;
  margin-bottom: .3rem;
  font-size: .9rem;
}
.required { color: var(--color-danger); }
.hint { font-weight: 400; color: var(--color-text-light); font-size: .85rem; }

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }

.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }

.recipe-form fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; }
.nutrition-row { margin-bottom: .5rem; }

/* === Page Header === */
.page-header { padding: 1.5rem 0 1rem; }
.page-header h1 { margin-bottom: .75rem; }

/* === Import bar === */
.import-bar { display: flex; gap: .5rem; }
.import-input { flex: 1; }
.import-section { margin-bottom: 1.5rem; }
.import-section h2 { font-size: 1rem; margin-bottom: .5rem; }
.import-section hr { border: none; border-top: 1px solid var(--color-border); margin-top: 1rem; }

/* === Search / Filter === */
.search-filter-row { margin-bottom: 1.5rem; }
.search-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.search-input { flex: 2; min-width: 180px; }
.select-input { flex: 1; min-width: 120px; }

/* === Recipe Grid (card list) === */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.recipe-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  color: var(--color-text);
  transition: box-shadow .15s;
}
.recipe-card:hover { box-shadow: 0 3px 8px rgba(44,36,32,.14); text-decoration: none; }

.card-image { height: 140px; background-size: cover; background-position: center; background-color: var(--color-accent); }
.card-image-placeholder { background: linear-gradient(135deg, var(--color-accent), var(--color-border)); }

.card-body { padding: .85rem 1rem 1rem; flex: 1; display: flex; flex-direction: column; }
.card-title { font-size: 1.05rem; margin-bottom: .3rem; }
.card-desc { font-size: .85rem; color: var(--color-text-light); margin-bottom: .5rem; flex: 1; }
.card-meta { display: flex; flex-wrap: wrap; gap: .5rem; font-size: .8rem; color: var(--color-text-light); margin-bottom: .5rem; }
.card-rating { color: var(--color-star); }
.card-tags { display: flex; flex-wrap: wrap; gap: .35rem; }

/* === Tags / Pills === */
.tag {
  display: inline-block;
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  padding: .15rem .55rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 500;
}

/* === Pagination === */
.pagination { display: flex; justify-content: center; gap: .75rem; margin-bottom: 2rem; }

/* === Empty state === */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-text-light); }
.empty-state h2 { margin-bottom: .5rem; color: var(--color-text); }

/* === Recipe Detail === */
.recipe-detail { padding: 1.5rem 0 2rem; }
.detail-header { margin-bottom: 1.25rem; }
.detail-title-row { display: flex; align-items: baseline; gap: .75rem; }
.detail-title-row h1 { font-size: 1.75rem; }
.favorite-toggle {
  font-size: 1.5rem; color: var(--color-danger); cursor: pointer;
  background: none; border: none; padding: 0; line-height: 1; font-family: inherit;
}
.favorite-toggle:hover { opacity: 0.7; }
.detail-actions { display: flex; gap: .5rem; margin-top: .75rem; }
.inline-form { display: inline; }

.detail-image { margin-bottom: 1.25rem; border-radius: var(--radius); overflow: hidden; }
.detail-image img { width: 100%; max-height: 400px; object-fit: cover; display: block; }

.detail-description { font-size: 1.05rem; color: var(--color-text-light); margin-bottom: 1.25rem; line-height: 1.7; }

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
  padding: .85rem 1rem;
  background: var(--color-accent);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}
.meta-item { display: flex; flex-direction: column; }
.meta-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-light); }
.meta-value { font-weight: 600; font-size: .95rem; }
.rating-stars { color: var(--color-star); }

.detail-section { margin-bottom: 1.5rem; }
.detail-section h2 { font-size: 1.2rem; margin-bottom: .6rem; border-bottom: 1px solid var(--color-border); padding-bottom: .3rem; }

.ingredient-list { padding-left: 1.5rem; }
.ingredient-list li { padding: .25rem 0; font-size: 1rem; }

.directions p, .recipe-notes p { margin-bottom: .75rem; line-height: 1.7; }

.nutrition-list { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; }
.nutrition-item { display: flex; gap: .4rem; }
.nutrition-item dt { font-weight: 600; }
.nutrition-item dt::after { content: ":"; }

.detail-tags { margin-bottom: 1rem; display: flex; flex-wrap: wrap; gap: .4rem; }

.detail-source { font-size: .85rem; color: var(--color-text-light); margin-top: 1rem; word-break: break-all; }

/* === Form page === */
.form-page { padding: 1.5rem 0 2rem; }
.form-page h1 { margin-bottom: 1rem; }

/* === Print === */
@media print {
  .navbar, .site-footer, .detail-actions, .btn, .search-filter-row, .import-bar, .pagination { display: none !important; }
  body { background: #fff; }
  .container { max-width: 100%; }
  .detail-meta { border: 1px solid #ccc; }
}

/* === htmx indicators === */
.htmx-indicator { opacity: 0; transition: opacity 32ms ease-out; font-style: italic; color: var(--text-muted, #888); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; transition: opacity 0ms 200ms; }

/* === Cooking mode === */
.cooking-mode .ingredient-item { cursor: pointer; padding: 4px 0; transition: all 0.15s; }
.cooking-mode .ingredient-item:hover { background: rgba(0,0,0,0.04); }
.ingredient-item.strikethrough { text-decoration: line-through; opacity: 0.5; }

/* === Scaling controls === */
.scaling-controls { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.scale-buttons { display: flex; gap: 0.25rem; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.85rem; }
.scale-btn { background: var(--bg-subtle, #f0f0f0); border: 1px solid var(--border, #ddd); border-radius: 4px; cursor: pointer; }
.scale-btn.active { background: var(--accent, #e07c24); color: white; border-color: var(--accent, #e07c24); }
.servings-prompt { margin-top: 0.5rem; font-size: 0.9rem; }
.input-sm { padding: 0.25rem 0.5rem; font-size: 0.9rem; }

/* === Meal Plans, Grocery Lists, Pantry === */
.inline-create-form { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.plans-list { display: flex; flex-direction: column; gap: 0.75rem; }
.plan-card { display: flex; align-items: center; justify-content: space-between; padding: 1rem; background: white; border-radius: 8px; border: 1px solid var(--border, #ddd); }
.plan-card h2 { margin: 0; font-size: 1.1rem; }
.plan-meta { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--text-muted, #888); }
.plan-link { text-decoration: none; color: inherit; flex: 1; }
.plan-link:hover h2 { color: var(--accent, #e07c24); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border, #ddd); }
.data-table th { font-weight: 600; font-size: 0.85rem; color: var(--text-muted, #888); }
.generate-grocery, .add-entry-section, .add-item-section, .create-form-section { margin-bottom: 1.5rem; }
.grocery-items, .pantry-items { list-style: none; padding: 0; margin: 0; }
.grocery-item, .pantry-item { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border, #eee); }
.grocery-item.checked { opacity: 0.5; }
.grocery-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; flex: 1; }
.grocery-text { flex: 1; }
.pantry-item-info { display: flex; align-items: center; gap: 0.75rem; flex: 1; flex-wrap: wrap; }
.pantry-add-form { display: flex; flex-direction: column; gap: 0.5rem; }
.pantry-add-form .form-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.pantry-qty { font-size: 0.85rem; color: var(--text-muted, #888); }
.pantry-expiry { font-size: 0.8rem; color: #c0392b; }
.pantry-expiry.expired { font-weight: 700; background: #fde8e8; padding: 0.1rem 0.4rem; border-radius: 4px; }
.pantry-expiry.expiring-soon { color: #d4a017; font-weight: 600; }
.match-badge { display: inline-block; background: var(--accent, #e07c24); color: white; padding: 0.2rem 0.5rem; border-radius: 4px; font-weight: bold; font-size: 0.9rem; margin-bottom: 0.5rem; }
.match-card .card-body { padding: 1rem; }
.missing-list { margin-top: 0.5rem; }
.tag-missing { background: #fde8e8; color: #c0392b; border-color: #f5c6cb; }
.filter-row { margin-bottom: 1rem; }
.inline-form { display: inline; }

/* === Interactive rating stars === */
.rating-stars-interactive {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 0.1em;
}
.rating-star-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.25rem; color: var(--color-border);
  padding: 0.25rem; min-width: 44px; min-height: 44px;
  line-height: 1; text-align: center; font-family: inherit;
  transition: color 0.1s;
}
.rating-star-btn.filled { color: var(--color-star); }
.rating-star-btn:disabled { cursor: wait; opacity: 0.5; }
/* Hover preview: hovered star + all siblings after it (visually before due to row-reverse) */
.rating-star-btn:hover,
.rating-star-btn:hover ~ .rating-star-btn { color: var(--color-star); }

/* === Direction step highlighting === */
.direction-step { cursor: pointer; padding: 4px 0; border-radius: 4px; transition: background 0.15s; }
.cooking-mode .direction-step:hover { background: rgba(0,0,0,0.04); }
.direction-step.active-step { background: rgba(224, 124, 36, 0.1); border-left: 3px solid var(--accent, #e07c24); padding-left: 8px; }

/* === Calendar Meal Plan === */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.5rem;
}
.calendar-nav-title { font-weight: 600; font-size: 1.1rem; }

.calendar-grid {
  display: grid;
  grid-template-columns: 80px repeat(7, 1fr);
  gap: 1px;
  background: var(--color-border);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.calendar-header {
  background: var(--color-accent);
  padding: 0.5rem 0.25rem;
  text-align: center;
  font-size: 0.85rem;
}
.calendar-header.today { background: var(--color-primary); color: #fff; }
.calendar-day-name { display: block; font-weight: 600; }
.calendar-day-num { display: block; font-size: 0.8rem; opacity: 0.8; }

.calendar-slot-label {
  background: var(--color-surface);
  padding: 0.5rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.calendar-cell {
  background: var(--color-surface);
  padding: 0.3rem;
  min-height: 70px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow-y: auto;
  max-height: 120px;
  position: relative;
}
.calendar-cell.today { background: #fef9f4; }

.calendar-entry {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.25rem;
  background: var(--color-tag-bg);
  border-radius: 4px;
  font-size: 0.78rem;
}
.calendar-entry-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
  font-weight: 500;
}
.calendar-entry-title:hover { color: var(--color-primary); text-decoration: none; }

.calendar-remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-light);
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  flex-shrink: 0;
}
.calendar-remove-btn:hover { color: var(--color-danger); }

.calendar-add-btn {
  background: none;
  border: 1px dashed var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-text-light);
  font-size: 0.85rem;
  padding: 0.15rem;
  margin-top: auto;
  transition: all 0.15s;
}
.calendar-add-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(192, 98, 58, 0.05);
}

/* Mobile calendar (hidden on desktop) */
.calendar-mobile { display: none; }
.calendar-mobile-day {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}
.calendar-mobile-day.today { border-color: var(--color-primary); }
.calendar-mobile-day-header { font-size: 0.95rem; margin-bottom: 0.5rem; }
.calendar-mobile-slot { margin-bottom: 0.4rem; }
.calendar-mobile-slot-name {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--color-text-light);
  font-weight: 600;
  letter-spacing: 0.03em;
}
.calendar-add-btn-mobile {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.4rem;
  font-size: 0.85rem;
}

/* === Aisle-grouped grocery list === */
.aisle-section { margin-bottom: 0.25rem; }
.aisle-header {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--color-text-light);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-accent);
  border-radius: var(--radius) var(--radius) 0 0;
  user-select: none;
}
.aisle-count {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  font-weight: 600;
}
.grocery-recipe-badge {
  font-size: 0.7rem;
  color: var(--color-text-light);
  background: var(--color-tag-bg);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}
.grocery-item {
  padding: 0.75rem 1rem;
  min-height: 48px;
}
.grocery-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  position: sticky;
  top: 52px;
  z-index: 99;
  font-size: 0.85rem;
}
.grocery-filter-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-weight: 500;
}
.grocery-remaining { color: var(--color-text-light); font-size: 0.8rem; }

/* Hide checked items when filter active */
.grocery-hide-checked .grocery-item.checked { display: none; }
.grocery-hide-checked .aisle-section.aisle-empty { display: none; }

/* Checked item flash animation */
@keyframes check-flash {
  0% { background: rgba(76, 175, 80, 0.15); }
  100% { background: transparent; }
}
.grocery-item.just-checked { animation: check-flash 150ms ease-out; }

/* === Completed step styling === */
.direction-step {
  transition: opacity 200ms ease, background 200ms ease;
  scroll-margin-top: 60px;
}
.direction-step.completed-step {
  opacity: 0.5;
  border-left: 3px solid var(--color-border);
  padding-left: 8px;
  cursor: pointer;
}
.direction-step.completed-step:hover { opacity: 0.75; }

/* === Timer panel === */
.timer-panel {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  right: 1rem;
  z-index: 200;
  max-height: 60svh;
  min-width: 280px;
  max-width: 360px;
}
.timer-panel-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 99px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(44, 36, 32, 0.15);
  font-family: var(--font);
  margin-left: auto;
}
.timer-panel-toggle:hover { background: var(--color-primary-hover); }
.timer-list {
  display: none;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(44, 36, 32, 0.15);
  margin-top: 0.5rem;
  overflow-y: auto;
  max-height: calc(60svh - 50px);
}
.timer-panel.expanded .timer-list { display: block; }
.timer-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
}
.timer-entry:last-child { border-bottom: none; }
.timer-entry-info { display: flex; flex-direction: column; }
.timer-entry-label {
  font-size: 0.8rem;
  color: var(--color-text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.timer-entry-time {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.timer-entry-time.expired {
  color: var(--color-danger);
  animation: pulse-timer 1s ease-in-out infinite;
}
@keyframes pulse-timer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.timer-dismiss-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-light);
  font-size: 1.2rem;
  padding: 0.25rem;
  line-height: 1;
}
.timer-dismiss-btn:hover { color: var(--color-danger); }

/* Timer trigger buttons in recipe directions */
.timer-trigger-btn {
  display: inline;
  background: var(--color-accent);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.85em;
  cursor: pointer;
  color: var(--color-primary);
  font-weight: 600;
  font-family: var(--font);
}
.timer-trigger-btn:hover {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* === Responsive === */
@media (max-width: 600px) {
  .calendar-grid { display: none; }
  .calendar-mobile { display: block; }
  .recipe-grid { grid-template-columns: 1fr; }
  .search-form { flex-direction: column; }
  .form-row { flex-direction: column; gap: 0; }
  .detail-title-row h1 { font-size: 1.35rem; }
  .scaling-controls { flex-direction: column; align-items: flex-start; }
  .timer-panel { left: 0.5rem; right: 0.5rem; min-width: 0; max-width: none; }
}
