/* VARIABLES */
:root {
  --primary-color: #5c0c0c;
  --secondary-color: #400000;
  --primary-dark: #000;
  --secondary-dark: #333;
  --grey-dark: #8d8d8d;
  --primary-light: #fff;
}

/* GLOBAL RESET */
#meal-planner-app,
#meal-planner-app * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
}

/* CONTAINER */
.page-container {
  /* keep the existing flex and wrap, but add: */
  justify-content: center;
}

#meal-planner-app {
  position: relative;      /* keep this so your absolute buttons still work */
  display: flex;
  justify-content: center; /* horizontal centering */
  width: 100%;
  max-width: 1200px;
  margin: 20px auto;
  padding: 120px 30px 30px;
  background: var(--primary-light);
  border: 2px solid var(--secondary-color);
  border-radius: 8px;
  overflow-x: hidden;
}

/* CONTROLS */
#mp-generate-week,
#mp-save-week {
  position: absolute;
  top: 20px;
  padding: 10px 20px;
  background: var(--primary-color);
  color: var(--primary-light);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s;
  z-index: 10;
}

#mp-generate-week { left: 30px; }
#mp-save-week     { right: 30px; }

#mp-generate-week:hover,
#mp-save-week:hover {
  background: var(--secondary-color);
}

/* CALENDAR GRID */
.mp-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 15px;
}

/* DAY CELL */
.mp-calendar .day-cell {
  position: relative;
  background: var(--secondary-dark);
  color: var(--primary-light);
  border-radius: 4px;
  padding-bottom: 50px;       /* space for replace button */
  min-height: 150px;
  display: flex;
  flex-direction: column;
}

/* DATE HEADER INSIDE CELL */
.mp-calendar .day-cell .cell-header {
  background: var(--secondary-color);
  color: var(--primary-light);
  padding: 6px;
  border-radius: 4px 4px 0 0;
  text-align: center;
  font-weight: bold;
}

/* MEAL TITLE */
.mp-calendar .day-cell .cell-content {
  flex: 1;
  padding: 10px;
  font-size: 1rem;
  overflow-wrap: break-word;
}

.cell-content {
  flex: 1;
  padding:10px;
  border-radius:4px 4px 0 0;
}

/* HIGHLIGHT TODAY */
.mp-calendar .day-cell.today {
  box-shadow: 0 0 0 3px var(--primary-color);
}

/* REPLACE BUTTON */
.mp-calendar .day-cell button.mp-replace {
  position: absolute;
  bottom: 10px;
  right: 10px;
  padding: 4px 8px;
  font-size: 0.9rem;
  background: var(--primary-color);
  color: var(--primary-light);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s;
}

.mp-calendar .day-cell button.mp-replace:hover {
  background: var(--secondary-color);
}

/* DATE HEADER */
.cell-header {
  background: var(--secondary-color);
  color: var(--primary-light);
  padding: 8px;
  text-align: center;
  font-weight: bold;
  border-radius: 4px 4px 0 0;
  font-size: 1rem;
}

/* HIGHLIGHT TODAY’S HEADER */
.day-cell.today .cell-header {
  background: #FFD700;       /* bright gold */
  color: #000;               /* dark text for contrast */
  box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

/* OPTIONAL: give the entire today cell a subtle ring */
.day-cell.today {
  box-shadow: 0 0 0 3px #FFD700;
}

/* ===== CURRENT WEEK STYLING ===== */
#meal-planner-current {
  background: #f9f9f9;
  border: 2px solid var(--grey-dark);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 40px;
}

/* Use the same grid layout as interactive week */
#meal-planner-current .mp-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

/* Day cell */
#meal-planner-current .day-cell {
  background: var(--grey-dark);
  color: var(--primary-light);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
}

/* Header */
#meal-planner-current .cell-header {
  background: var(--secondary-dark);
  color: var(--primary-light);
  padding: 6px;
  text-align: center;
  font-weight: bold;
  border-radius: 4px 4px 0 0;
}

/* Content */
#meal-planner-current .cell-content {
  flex: 1;
  padding: 10px;
  font-size: 0.95rem;
  text-align: center;
  word-break: break-word;
}

/* Remove replace buttons entirely */
#meal-planner-current .mp-replace {
  display: none;
}

/* Highlight today in current week */
#meal-planner-current .day-cell.today {
  box-shadow: 0 0 0 3px var(--primary-color);
}

/* Current week empty state */
.mp-current-empty {
  display: none;
  margin-top: 12px;
  text-align: center;
  color: var(--secondary-dark);
  font-style: italic;
}

.mp-current-empty.is-visible {
  display: block;
}

/* ===== RESPONSIVE (current-week view) ===== */
@media (max-width: 1000px) {
  #meal-planner-current .mp-calendar {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 600px) {
  #meal-planner-current {
    padding: 15px;
  }
  #meal-planner-current .mp-calendar {
    grid-template-columns: repeat(2, 1fr);
  }
  #meal-planner-current .cell-content {
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  #meal-planner-current .mp-calendar {
    display: block;
  }
  #meal-planner-current .day-cell {
    margin-bottom: 12px;
  }
}


/* ===== RESPONSIVE (interactive planner) ===== */
/* ≤1000px: 4-column grid, tighten padding & fonts */
@media (max-width: 1000px) {
  #meal-planner-app {
    padding: 100px 20px 20px;
  }
  #meal-planner-app .mp-calendar {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }
  #meal-planner-app .day-cell {
    padding-bottom: 40px;
    min-height: 130px;
  }
  #meal-planner-app .cell-header {
    font-size: 0.9rem;
    padding: 5px;
  }
  #meal-planner-app .cell-content {
    font-size: 0.9rem;
    padding: 8px;
  }
}

/* ≤600px: 2-column grid, stack buttons above & below, smaller */
@media (max-width: 600px) {
  /* flow everything in document order */
  #meal-planner-app {
    display: block;
    padding: 80px 15px 15px;
  }

  /* 2 columns */
  #meal-planner-app .mp-calendar {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* shrink the cells */
  #meal-planner-app .day-cell {
    padding-bottom: 30px;
    min-height: 120px;
  }
  #meal-planner-app .cell-header {
    font-size: 0.85rem;
    padding: 4px;
  }
  #meal-planner-app .cell-content {
    font-size: 0.85rem;
    padding: 6px;
  }

  /* stack generate/save -->
     full-width-ish but not too wide,
     tiny padding & font for comfort */
  #mp-generate-week,
  #mp-save-week {
    position: static;
    display: block;
    width: 80%;
    max-width: 200px;
    margin: 8px auto;
    padding: 6px 0;
    font-size: 0.85rem;
  }
}

/* ≤400px: single-column days + buttons stay stacked */
@media (max-width: 400px) {
  #meal-planner-app {
    padding: 60px 10px 10px;
  }
  #meal-planner-app .mp-calendar {
    display: block;
  }
  #meal-planner-app .day-cell {
    width: 100%;
    margin-bottom: 12px;
    padding-bottom: 25px;
    min-height: auto;
  }
  #mp-generate-week,
  #mp-save-week {
    width: 90%;
    margin: 6px auto;
    padding: 4px 0;
    font-size: 0.75rem;
  }
}

/* NEXT WEEK DYNAMIC HEADER */
.meal-planner-wrapper.next-week.has-plan h3:nth-of-type(2) {
  color: #28a745; /* green */
}

.meal-planner-wrapper.next-week.no-plan h3:nth-of-type(2) {
  color: #dc3545; /* red */
}

/* DISABLED “Save Week” BUTTON */
#mp-save-week:disabled {
  background: var(--grey-dark);
  color: var(--primary-light);
  cursor: not-allowed;
  opacity: 0.6;
}

#mp-save-week:disabled:hover {
  background: var(--grey-dark);
}

/* SHOPPING LIST */
#mp-shopping-list,
.mp-access {
  max-width: 960px;
}

.mp-access {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 0 auto 12px;
  background: #fff8f0;
  border: 2px solid var(--secondary-color);
  border-radius: 8px;
}

.mp-access label {
  font-weight: bold;
  color: var(--secondary-color);
}

.mp-access input {
  flex: 1;
  min-width: 180px;
  padding: 8px;
  border: 1px solid var(--secondary-color);
  border-radius: 6px;
}

.mp-access button {
  padding: 8px 14px;
  background: var(--primary-color);
  color: var(--primary-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.3s;
}

.mp-access button:hover {
  background: var(--secondary-color);
}

.mp-access .mp-access-status {
  font-weight: bold;
  color: var(--secondary-color);
}

#mp-shopping-list {
  margin: 24px auto 0;
  padding: 18px;
  background: #fff8f0;
  border: 2px solid var(--secondary-color);
  border-radius: 8px;
  color: #2c1a1a;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

#mp-shopping-list .mp-shopping-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

#mp-shopping-list .mp-shopping-title h4 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--secondary-color);
}

#mp-shopping-list .mp-shopping-date {
  display: block;
  margin-top: 4px;
  font-weight: bold;
  color: var(--primary-color);
}

#mp-shopping-list .mp-shopping-note {
  margin: 4px 0 0;
  max-width: 520px;
  color: #5c3a3a;
  font-size: 0.95rem;
}

#mp-shopping-list .mp-shopping-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}

#mp-shopping-input {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--secondary-color);
  border-radius: 6px;
  font-size: 1rem;
}

#mp-shopping-add {
  padding: 10px 16px;
  background: var(--primary-color);
  color: var(--primary-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.3s;
}

#mp-shopping-add:hover {
  background: var(--secondary-color);
}

#mp-shopping-export {
  padding: 10px 16px;
  background: var(--secondary-color);
  color: var(--primary-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.3s;
}

#mp-shopping-export:hover {
  background: var(--primary-color);
}

#mp-shopping-list .mp-shopping-items {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

#mp-shopping-list .mp-shopping-items li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--secondary-color);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.95rem;
  min-height: 44px;
}

#mp-shopping-list .mp-item-text {
  flex: 1;
  word-break: break-word;
}

#mp-shopping-list .mp-remove-item {
  border: none;
  background: transparent;
  color: var(--secondary-color);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}

#mp-shopping-list .mp-remove-item:hover {
  background: rgba(0,0,0,0.05);
}

#mp-shopping-list .mp-empty {
  list-style: none;
  color: var(--secondary-color);
  font-style: italic;
}

#mp-shopping-list .mp-shopping-lock {
  display: none;
  margin: 0 0 8px 0;
  color: var(--secondary-color);
  font-weight: bold;
}

#mp-shopping-list.mp-locked .mp-shopping-lock {
  display: block;
}

#mp-shopping-list.mp-locked .mp-shopping-items {
  opacity: 0.6;
  pointer-events: none;
}

@media (max-width: 640px) {
  #mp-shopping-list .mp-shopping-head { flex-direction: column; }
  #mp-shopping-list .mp-shopping-controls { flex-direction: column; }
  #mp-shopping-add,
  #mp-shopping-export {
    width: 100%;
    text-align: center;
  }
}

/* ==============================
   MEAL SELECTOR + REPLACE LAYOUT
   ============================== */

/* Container structure */
.day-cell {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  position: relative;
  padding-bottom: 55px; /* ensures button doesn't overlap content */
}

/* Header styling (unchanged) */
.day-cell .cell-header {
  flex-shrink: 0;
}

/* Meal title/content area */
.day-cell .cell-content {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 0.95rem;
  overflow-wrap: break-word;
}

/* Dropdown wrapper: full width, stacked */
.mp-select-wrap {
  display: block;
  width: 90%;
  margin: 8px auto 10px auto; /* center horizontally */
  order: 3;
}

.mp-select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid var(--grey-dark);
  background: #fff;
  color: #111;
  font-size: .95rem;
  box-sizing: border-box;
}

/* Replace button — always below the dropdown */
.day-cell button.mp-replace {
  display: block;
  width: 90%;
  margin: 0 auto 10px auto;
  padding: 6px 8px;
  background: var(--primary-color);
  color: var(--primary-light);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s;
}

.day-cell button.mp-replace:hover {
  background: var(--secondary-color);
}

/* Hide selector in read-only weeks */
.day-cell.readonly .mp-select-wrap,
.day-cell.readonly .mp-select,
.day-cell.readonly button.mp-replace {
  display: none;
}

/* ===== Responsive tweaks ===== */
@media (max-width: 800px) {
  .mp-select-wrap,
  .day-cell button.mp-replace {
    width: 95%;
  }
}

@media (max-width: 600px) {
  .mp-select-wrap { margin-bottom: 16px; }
  .day-cell button.mp-replace {
    width: 100%;
    margin-bottom: 12px;
  }
}
/* ==== Meal card layout fix: stack content, select, then button ==== */
.mp-calendar .day-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding-bottom: 12px;                /* no fake space for abs button */
}

/* keep meal text flexible so the controls sit below it */
.mp-calendar .day-cell .cell-content {
  flex: 1 1 auto;
  padding: 10px;
  text-align: center;
}

/* dropdown centred, full width of card */
.mp-calendar .day-cell .mp-select-wrap {
  order: 3;
  width: 90%;
  margin: 8px auto 6px;
}

.mp-calendar .day-cell .mp-select {
  width: 100%;
  box-sizing: border-box;
}

/* REPLACE button goes *after* dropdown, not absolute */
.mp-calendar .day-cell button.mp-replace {
  order: 4;
  position: static !important;         /* override earlier absolute rule */
  bottom: auto; right: auto;           /* neutralise */
  display: block;
  width: 90%;
  margin: 0 auto 8px;                  /* centred on its own line */
  align-self: stretch;
}

/* read-only cards hide the controls */
.mp-calendar .day-cell.readonly .mp-select-wrap,
.mp-calendar .day-cell.readonly .mp-select,
.mp-calendar .day-cell.readonly button.mp-replace {
  display: none !important;
}

/* responsive tweaks */
@media (max-width: 800px) {
  .mp-calendar .day-cell .mp-select-wrap,
  .mp-calendar .day-cell button.mp-replace {
    width: 95%;
  }
}

@media (max-width: 600px) {
  .mp-calendar .day-cell .mp-select-wrap { margin-bottom: 10px; }
  .mp-calendar .day-cell button.mp-replace { width: 100%; }
}
