/* FoodShop! styles */

/* ---- Colors (exact values from the spec) ---- */
:root {
  --deep-blue: #001E5E;
  --cyan: #1FC4F4;
  --red: #E11921;
  --orange: #F37D1E;
  --yellow: #FABF11;
  --white: #FFFFFF;
  --green: #238A47;
  --line: #C9D1E3;        /* light divider lines */
  --soft-text: #3D4B73;   /* secondary text; still strong contrast on white */
  /* Multicolor stripe used under the header and on the Misc. category */
  --rainbow: linear-gradient(90deg,
    var(--cyan) 0 20%, var(--green) 20% 40%, var(--yellow) 40% 60%,
    var(--orange) 60% 80%, var(--red) 80% 100%);
}

/* ---- Basics ---- */
* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--cyan);   /* Deep Blue text on Cyan = 7.6:1, fine */
  color: var(--deep-blue);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.4;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Big, clear keyboard focus outline */
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---- Header ---- */
.app-header {
  background: var(--deep-blue);
  color: var(--white);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 8px solid;
  border-image: var(--rainbow) 1;
}
.app-header h1 { margin: 0; font-size: 1.6rem; }

.sync-status { margin: 0; font-size: 0.9rem; display: flex; align-items: center; gap: 6px; }
.sync-status::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: var(--cyan);
}
.sync-status.offline::before { background: var(--orange); }

/* ---- Layout ---- */
.screen {
  max-width: 640px;
  margin: 0 auto;
  /* extra space at the bottom so the tab bar and Undo bar never cover content */
  padding: 16px 16px calc(180px + env(safe-area-inset-bottom));
}

.card {
  background: var(--white);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  border: 3px solid var(--deep-blue);
}
.card h2 { margin: 0 0 12px; font-size: 1.3rem; }

/* ---- Messages ---- */
.message {
  margin: 0;
  padding: 12px 16px;
  background: var(--orange);
  color: var(--deep-blue);
  font-weight: 600;
  text-align: center;
}
.login-error { color: var(--red); font-weight: 600; margin: 4px 0 12px; }

/* ---- Form fields ---- */
label { display: block; font-weight: 600; margin: 8px 0 4px; }

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  font: inherit;            /* 18px, which also stops iPhones from zooming in */
  color: var(--deep-blue);
  background: var(--white);
  border: 2px solid var(--deep-blue);
  border-radius: 10px;
}
#login-form input { margin-bottom: 8px; }

/* ---- Buttons ---- */
.btn {
  min-height: 52px;
  padding: 10px 20px;
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--green); color: var(--white); }
#login-form .btn-primary { width: 100%; margin-top: 8px; }

.btn-quiet {
  display: block;
  margin: 24px auto 0;
  background: var(--white);
  color: var(--deep-blue);
  border-color: var(--deep-blue);
}

/* ---- Add form ---- */
.category-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
/* Each category button wears its category's color */
.category-choice {
  min-height: 48px;
  padding: 6px 4px;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border: 2px solid var(--deep-blue);
  border-radius: 10px;
  cursor: pointer;
}
/* The chosen category: a checkmark plus a thick ring around it */
.category-choice[aria-pressed="true"] {
  box-shadow: 0 0 0 3px var(--white), 0 0 0 6px var(--deep-blue);
}
.category-choice[aria-pressed="true"]::before { content: "✓ "; }

.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }

/* ---- The list ---- */
.category {
  background: var(--white);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
  border: 3px solid var(--deep-blue);
}
.category h2 {
  margin: 0;
  padding: 12px 16px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border-bottom: 3px solid var(--deep-blue);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.category .count { font-size: 1rem; font-weight: 700; color: var(--on-accent); }

/* Each category's color (--accent) and the text color that's readable on it (--on-accent).
   White text only on Green, Red, and Deep Blue, always bold. Yellow is saved for "Get elsewhere". */
[data-category="produce"] { --accent: var(--green);     --on-accent: var(--white); }
[data-category="meat"]    { --accent: var(--red);       --on-accent: var(--white); }
[data-category="frozen"]  { --accent: var(--cyan);      --on-accent: var(--deep-blue); }
[data-category="aisles"]  { --accent: var(--orange);    --on-accent: var(--deep-blue); }
[data-category="misc"]    { --accent: var(--white);     --on-accent: var(--deep-blue); }
[data-category="dairy"]   { --accent: var(--deep-blue); --on-accent: var(--white); }

/* Misc. = a mix of everything: white with a multicolor stripe along the bottom */
.category[data-category="misc"] h2,
.category-choice[data-category="misc"] {
  background: var(--rainbow) bottom / 100% 8px no-repeat, var(--white);
}
.category[data-category="misc"] h2 { padding-bottom: 20px; }
.category-choice[data-category="misc"] { padding-bottom: 12px; }

.items { list-style: none; margin: 0; padding: 0; }
.empty { margin: 0; padding: 12px 16px; color: var(--soft-text); font-style: italic; }

.item {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 60px;
  padding: 4px 8px 4px 4px;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: none; }

/* "Get elsewhere": yellow highlighter background, Deep Blue text */
.item.elsewhere { background: var(--yellow); }

/* Tap the item (checkbox + name) to cross it off */
.item-toggle {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  font: inherit;
  font-size: 1.15rem;       /* about 21px: easy to scan */
  font-weight: 600;
  color: var(--deep-blue);
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
}
.item-name { overflow-wrap: anywhere; }

.box {
  flex: none;
  width: 28px;
  height: 28px;
  border: 2px solid var(--deep-blue);
  border-radius: 6px;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 1.1rem;
  font-weight: 700;
}

/* Bought: checked box, crossed out, stays in place */
.item.bought .box { background: var(--deep-blue); }
.item.bought .box::after { content: "✓"; }
.item.bought .item-name {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  font-weight: 400;
}

/* "Other store" button */
.elsewhere-btn {
  flex: none;
  min-height: 44px;
  padding: 4px 10px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--deep-blue);
  background: var(--white);
  border: 2px solid var(--orange);
  border-radius: 8px;
  cursor: pointer;
}
.elsewhere-btn[aria-pressed="true"] {
  background: var(--deep-blue);
  color: var(--white);
  border-color: var(--deep-blue);
}

/* Delete button */
.delete-btn {
  flex: none;
  width: 44px;
  height: 44px;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--deep-blue);
  background: transparent;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

/* ---- Undo bar ---- */
.undo-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(84px + env(safe-area-inset-bottom));   /* just above the tab bar */
  max-width: 616px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  background: var(--deep-blue);
  color: var(--white);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
#undo-text { overflow-wrap: anywhere; }
.btn-undo { background: var(--yellow); color: var(--deep-blue); flex: none; }

/* ======================================================
   Phase 2: weeks, Finish panel, meals, history, tab bar
   ====================================================== */

/* "This week: Sat, Nov 7 – Sat, Nov 14" (Deep Blue on the Cyan page) */
.week-title { margin: 0 0 12px; font-size: 1.2rem; font-weight: 700; }

/* History items aren't buttons, so no pointer cursor */
span.item-toggle { cursor: default; }

/* ---- Buttons ---- */
.btn-wide { display: block; width: 100%; margin-top: 16px; }
.btn-finish {
  display: block;
  width: 100%;
  margin-top: 8px;
  background: var(--orange);          /* Deep Blue on Orange = 5.8:1 */
  color: var(--deep-blue);
  border-color: var(--deep-blue);
  border-width: 3px;
}
.btn-secondary {
  background: var(--white);
  color: var(--deep-blue);
  border-color: var(--deep-blue);
}
.btn-back { margin: 0 0 16px; }

/* ---- Finish panel ---- */
.finish-new-week { font-weight: 700; }
.leftover-list { list-style: none; margin: 12px 0 0; padding: 0; }
.leftover { border-bottom: 1px solid var(--line); }
.leftover.elsewhere { background: var(--yellow); }
.leftover label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin: 0;
  padding: 6px 8px;
  cursor: pointer;
}
.leftover input[type="checkbox"] {
  flex: none;
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--deep-blue);
}
.leftover-name { flex: 1; font-size: 1.1rem; overflow-wrap: anywhere; }
.leftover-category { font-size: 0.9rem; font-weight: 600; color: var(--soft-text); }

/* ---- Meal plan ---- */
.meal-day { padding: 12px 16px; }
.meal-day.today { border-width: 5px; }
.meal-label { margin: 0 0 6px; font-size: 1.1rem; font-weight: 700; }
.today-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--green);           /* white bold text on Green */
  color: var(--white);
  font-size: 0.9rem;
  font-weight: 700;
}
.meal-hint { margin: -2px 0 8px; font-size: 0.95rem; color: var(--soft-text); }
textarea {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  font: inherit;                      /* 18px: no zooming on iPhones */
  color: var(--deep-blue);
  background: var(--white);
  border: 2px solid var(--deep-blue);
  border-radius: 10px;
  resize: vertical;
}
.meal-status { margin: 4px 0 0; min-height: 1.4em; font-size: 0.95rem; color: var(--soft-text); }

/* ---- History ---- */
.history-weeks { list-style: none; margin: 0; padding: 0; }
.history-weeks li { margin-bottom: 10px; }
.history-week {
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  text-align: left;
  color: var(--deep-blue);
  background: var(--white);
  border: 3px solid var(--deep-blue);
  border-radius: 12px;
  cursor: pointer;
}
.history-week::after { content: " ›"; float: right; }
.history-meals { margin: 0; }
.history-meals dt { font-weight: 700; margin-top: 10px; }
.history-meals dt:first-child { margin-top: 0; }
.history-meals dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- Tab bar ---- */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--deep-blue);
  border-top: 6px solid;
  border-image: var(--rainbow) 1;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar button {
  flex: 1;
  min-height: 64px;
  font: inherit;
  font-weight: 700;
  color: var(--white);
  background: transparent;
  border: none;
  cursor: pointer;
}
.tab-bar button[aria-current="page"] {
  background: var(--cyan);            /* Deep Blue on Cyan = 7.6:1 */
  color: var(--deep-blue);
}
